From 6528567746c8a5f350ab1694140f6048a9e3ab6b Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 1 Apr 2025 22:48:44 +0500 Subject: [PATCH] Log applying blocks and fix sub_chain_id:1. --- .../calls/group/calls_group_call.cpp | 5 ++++ Telegram/SourceFiles/tde2e/tde2e_api.cpp | 29 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/calls/group/calls_group_call.cpp b/Telegram/SourceFiles/calls/group/calls_group_call.cpp index 832b5e8fad..dbb7298671 100644 --- a/Telegram/SourceFiles/calls/group/calls_group_call.cpp +++ b/Telegram/SourceFiles/calls/group/calls_group_call.cpp @@ -729,6 +729,11 @@ void GroupCall::setupConferenceCall() { } _conferenceCall->setParticipantsWithAccess(std::move(users)); }, _lifetime); + + _e2e->failures() | rpl::start_with_next([=] { + LOG(("TdE2E: Got failure!")); + hangup(); + }, _lifetime); } void GroupCall::removeConferenceParticipants( diff --git a/Telegram/SourceFiles/tde2e/tde2e_api.cpp b/Telegram/SourceFiles/tde2e/tde2e_api.cpp index ee25452805..a70ba8d6f5 100644 --- a/Telegram/SourceFiles/tde2e/tde2e_api.cpp +++ b/Telegram/SourceFiles/tde2e/tde2e_api.cpp @@ -19,6 +19,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL LOG_ERROR(error); \ fail(reason) +#define LOG_APPLY(subchain, slice) \ + DEBUG_LOG(("TdE2E Apply[%1]: %2").arg(subchain).arg(WrapForLog(slice))) + namespace TdE2E { namespace { @@ -52,6 +55,23 @@ constexpr auto kShortPollChainBlocksWaitFor = crl::time(1000); return result; } +[[nodiscard]] QString WrapForLog(std::string_view v) { + auto result = QString(); + const auto count = std::min(int(v.size()), 16); + result.reserve(count * 3 + 2); + for (auto i = 0; i != count; ++i) { + const auto byte = uint8(v[i]); + result += QString::number(byte, 16).rightJustified(2, '0'); + if (i + 1 != count) { + result += ' '; + } + } + if (v.size() > count) { + result += "..."; + } + return result.toUpper(); +} + } // namespace Call::Call(UserId myUserId) @@ -195,6 +215,7 @@ void Call::apply(int subchain, const Block &last) { }); if (subchain) { + LOG_APPLY(1, Slice(last.data)); auto result = tde2e_api::call_receive_inbound_message( libId(), Slice(last.data)); @@ -205,6 +226,7 @@ void Call::apply(int subchain, const Block &last) { } return; } else if (_id) { + LOG_APPLY(0, Slice(last.data)); const auto result = tde2e_api::call_apply_block( libId(), Slice(last.data)); @@ -215,6 +237,7 @@ void Call::apply(int subchain, const Block &last) { } return; } + LOG_APPLY(-1, Slice(last.data)); const auto id = tde2e_api::call_create( std::int64_t(_myKeyId.v), Slice(last.data)); @@ -296,7 +319,9 @@ void Call::apply( if (failed()) { return; - } else if (!_id || entry.height == index) { + } else if (!_id + || (subchain && !entry.height && fromShortPoll) + || (entry.height == index)) { apply(subchain, block); } entry.height = std::max(entry.height, index + 1); @@ -331,6 +356,7 @@ void Call::checkWaitingBlocks(int subchain, bool waited) { } else if (index == entry.height) { const auto slice = Slice(waiting.begin()->second.data); if (subchain) { + LOG_APPLY(1, slice); auto result = tde2e_api::call_receive_inbound_message( libId(), slice); @@ -343,6 +369,7 @@ void Call::checkWaitingBlocks(int subchain, bool waited) { : QByteArray(); checkForOutboundMessages(); } else { + LOG_APPLY(0, slice); const auto result = tde2e_api::call_apply_block( libId(), slice);