mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-03 21:54:05 +02:00
Fix complicated crash in async base::Timer destroying.
This commit is contained in:
parent
4eaf03b922
commit
a300a25419
3 changed files with 46 additions and 33 deletions
|
@ -2691,14 +2691,6 @@ bool GroupCall::tryCreateController() {
|
|||
}
|
||||
});
|
||||
};
|
||||
auto e2eEncryptDecrypt = Fn<std::vector<uint8_t>(
|
||||
const std::vector<uint8_t>&,
|
||||
bool)>();
|
||||
if (_e2e) {
|
||||
e2eEncryptDecrypt = [e2e = _e2e](const std::vector<uint8_t> &data, bool encrypt) {
|
||||
return encrypt ? e2e->encrypt(data) : e2e->decrypt(data);
|
||||
};
|
||||
}
|
||||
|
||||
tgcalls::GroupInstanceDescriptor descriptor = {
|
||||
.threads = tgcalls::StaticThreads::getThreads(),
|
||||
|
@ -2785,7 +2777,7 @@ bool GroupCall::tryCreateController() {
|
|||
});
|
||||
return result;
|
||||
},
|
||||
.e2eEncryptDecrypt = e2eEncryptDecrypt,
|
||||
.e2eEncryptDecrypt = _e2e ? _e2e->callbackEncryptDecrypt() : nullptr,
|
||||
};
|
||||
if (Logs::DebugEnabled()) {
|
||||
auto callLogFolder = cWorkingDir() + u"DebugLogs"_q;
|
||||
|
|
|
@ -222,7 +222,7 @@ void Call::apply(int subchain, const Block &last) {
|
|||
LOG_AND_FAIL(id.error(), CallFailure::Unknown);
|
||||
return;
|
||||
}
|
||||
_id = CallId{ uint64(id.value()) };
|
||||
setId({ uint64(id.value()) });
|
||||
|
||||
for (auto i = 0; i != kSubChainsCount; ++i) {
|
||||
auto &entry = _subchains[i];
|
||||
|
@ -245,6 +245,16 @@ void Call::apply(int subchain, const Block &last) {
|
|||
_participantsSet = ParseParticipantsSet(state.value());
|
||||
}
|
||||
|
||||
void Call::setId(CallId id) {
|
||||
Expects(!_id);
|
||||
|
||||
_id = id;
|
||||
if (const auto raw = _guardedId.get()) {
|
||||
raw->value = id;
|
||||
raw->exists = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Call::checkForOutboundMessages() {
|
||||
Expects(_id);
|
||||
|
||||
|
@ -408,26 +418,32 @@ rpl::producer<QByteArray> Call::emojiHashValue() const {
|
|||
return _emojiHash.value();
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Call::encrypt(const std::vector<uint8_t> &data) const {
|
||||
const auto result = tde2e_api::call_encrypt(libId(), Slice(data));
|
||||
if (!result.is_ok()) {
|
||||
return {};
|
||||
auto Call::callbackEncryptDecrypt()
|
||||
-> Fn<std::vector<uint8_t>(const std::vector<uint8_t>&, bool)> {
|
||||
if (!_guardedId) {
|
||||
_guardedId = std::make_shared<GuardedCallId>();
|
||||
if (const auto raw = _id ? _guardedId.get() : nullptr) {
|
||||
raw->value = _id;
|
||||
raw->exists = true;
|
||||
}
|
||||
}
|
||||
const auto &value = result.value();
|
||||
const auto start = reinterpret_cast<const uint8_t*>(value.data());
|
||||
const auto end = start + value.size();
|
||||
return std::vector<uint8_t>{ start, end };
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Call::decrypt(const std::vector<uint8_t> &data) const {
|
||||
const auto result = tde2e_api::call_decrypt(libId(), Slice(data));
|
||||
if (!result.is_ok()) {
|
||||
return {};
|
||||
}
|
||||
const auto &value = result.value();
|
||||
const auto start = reinterpret_cast<const uint8_t*>(value.data());
|
||||
const auto end = start + value.size();
|
||||
return std::vector<uint8_t>{ start, end };
|
||||
return [v = _guardedId](const std::vector<uint8_t> &data, bool encrypt) {
|
||||
if (!v->exists) {
|
||||
return std::vector<uint8_t>();
|
||||
}
|
||||
const auto libId = std::int64_t(v->value.v);
|
||||
const auto slice = Slice(data);
|
||||
const auto result = encrypt
|
||||
? tde2e_api::call_encrypt(libId, slice)
|
||||
: tde2e_api::call_decrypt(libId, slice);
|
||||
if (!result.is_ok()) {
|
||||
return std::vector<uint8_t>();
|
||||
}
|
||||
const auto &value = result.value();
|
||||
const auto start = reinterpret_cast<const uint8_t*>(value.data());
|
||||
const auto end = start + value.size();
|
||||
return std::vector<uint8_t>{ start, end };
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace TdE2E
|
||||
|
|
|
@ -101,14 +101,17 @@ public:
|
|||
|
||||
[[nodiscard]] rpl::producer<ParticipantsSet> participantsSetValue() const;
|
||||
|
||||
[[nodiscard]] std::vector<uint8_t> encrypt(
|
||||
const std::vector<uint8_t> &data) const;
|
||||
[[nodiscard]] std::vector<uint8_t> decrypt(
|
||||
const std::vector<uint8_t> &data) const;
|
||||
[[nodiscard]] auto callbackEncryptDecrypt()
|
||||
-> Fn<std::vector<uint8_t>(const std::vector<uint8_t>&, bool)>;
|
||||
|
||||
private:
|
||||
static constexpr int kSubChainsCount = 2;
|
||||
|
||||
struct GuardedCallId {
|
||||
CallId value;
|
||||
std::atomic<bool> exists;
|
||||
};
|
||||
|
||||
struct SubChainState {
|
||||
base::Timer shortPollTimer;
|
||||
base::Timer waitingTimer;
|
||||
|
@ -118,6 +121,7 @@ private:
|
|||
int height = 0;
|
||||
};
|
||||
|
||||
void setId(CallId id);
|
||||
void apply(int subchain, const Block &last);
|
||||
void fail(CallFailure reason);
|
||||
|
||||
|
@ -133,6 +137,7 @@ private:
|
|||
PublicKey _myKey;
|
||||
std::optional<CallFailure> _failure;
|
||||
rpl::event_stream<CallFailure> _failures;
|
||||
std::shared_ptr<GuardedCallId> _guardedId;
|
||||
|
||||
SubChainState _subchains[kSubChainsCount];
|
||||
rpl::event_stream<SubchainRequest> _subchainRequests;
|
||||
|
|
Loading…
Add table
Reference in a new issue