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