diff --git a/td/mtproto/HandshakeActor.h b/td/mtproto/HandshakeActor.h index 251f4d2d..4ec17240 100644 --- a/td/mtproto/HandshakeActor.h +++ b/td/mtproto/HandshakeActor.h @@ -6,6 +6,10 @@ // #pragma once +#include "td/mtproto/Handshake.h" +#include "td/mtproto/HandshakeConnection.h" +#include "td/mtproto/RawConnection.h" + #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" @@ -14,11 +18,6 @@ namespace td { namespace mtproto { -class AuthKeyHandshake; -class AuthKeyHandshakeContext; -class RawConnection; -class HandshakeConnection; - // Has Raw connection. Generates new auth key. And returns it and raw_connection. Or error... class HandshakeActor : public Actor { public: @@ -59,5 +58,6 @@ class HandshakeActor : public Actor { void return_connection(Status status); void return_handshake(); }; + } // namespace mtproto } // namespace td diff --git a/td/mtproto/HandshakeConnection.h b/td/mtproto/HandshakeConnection.h index 2d512370..ada294d5 100644 --- a/td/mtproto/HandshakeConnection.h +++ b/td/mtproto/HandshakeConnection.h @@ -9,6 +9,7 @@ #include "td/mtproto/AuthKey.h" #include "td/mtproto/Handshake.h" #include "td/mtproto/NoCryptoStorer.h" +#include "td/mtproto/PacketStorer.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/Transport.h" #include "td/mtproto/utils.h" @@ -22,6 +23,7 @@ namespace td { namespace mtproto { + class HandshakeConnection : private RawConnection::Callback , private AuthKeyHandshake::Callback { @@ -78,5 +80,6 @@ class HandshakeConnection return Status::OK(); } }; + } // namespace mtproto } // namespace td diff --git a/td/mtproto/IStreamTransport.h b/td/mtproto/IStreamTransport.h index 182d1eaf..1e7be807 100644 --- a/td/mtproto/IStreamTransport.h +++ b/td/mtproto/IStreamTransport.h @@ -12,6 +12,7 @@ namespace td { namespace mtproto { + struct TransportType { enum Type { Tcp, ObfuscatedTcp, Http } type; int16 dc_id; @@ -22,6 +23,7 @@ struct TransportType { TransportType(Type type, int16 dc_id, string secret) : type(type), dc_id(dc_id), secret(std::move(secret)) { } }; + class IStreamTransport { public: IStreamTransport() = default; @@ -40,5 +42,6 @@ class IStreamTransport { }; unique_ptr create_transport(TransportType type); + } // namespace mtproto } // namespace td diff --git a/td/mtproto/NoCryptoStorer.h b/td/mtproto/NoCryptoStorer.h index 7f774087..90cc5930 100644 --- a/td/mtproto/NoCryptoStorer.h +++ b/td/mtproto/NoCryptoStorer.h @@ -6,9 +6,8 @@ // #pragma once -#include "td/mtproto/PacketStorer.h" - #include "td/utils/Random.h" +#include "td/utils/StorerBase.h" namespace td { namespace mtproto { @@ -23,6 +22,7 @@ class NoCryptoImpl { Random::secure_bytes(pad_); } } + template void do_store(T &storer) const { storer.store_binary(message_id_); diff --git a/td/mtproto/PingConnection.h b/td/mtproto/PingConnection.h index b690263b..045ae284 100644 --- a/td/mtproto/PingConnection.h +++ b/td/mtproto/PingConnection.h @@ -8,9 +8,12 @@ #include "td/mtproto/AuthKey.h" #include "td/mtproto/NoCryptoStorer.h" +#include "td/mtproto/PacketStorer.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/utils.h" +#include "td/mtproto/mtproto_api.h" + #include "td/utils/buffer.h" #include "td/utils/port/detail/PollableFd.h" #include "td/utils/Random.h" @@ -18,8 +21,6 @@ #include "td/utils/Time.h" #include "td/utils/UInt.h" -#include "td/mtproto/mtproto_api.h" - namespace td { namespace mtproto { diff --git a/td/mtproto/RawConnection.cpp b/td/mtproto/RawConnection.cpp index a6f57ceb..add181d7 100644 --- a/td/mtproto/RawConnection.cpp +++ b/td/mtproto/RawConnection.cpp @@ -13,6 +13,7 @@ #include "td/utils/logging.h" #include "td/utils/misc.h" #include "td/utils/Status.h" +#include "td/utils/StorerBase.h" #include @@ -21,15 +22,15 @@ namespace mtproto { void RawConnection::send_crypto(const Storer &storer, int64 session_id, int64 salt, const AuthKey &auth_key, uint64 quick_ack_token) { - mtproto::PacketInfo info; + PacketInfo info; info.version = 2; info.no_crypto_flag = false; info.salt = salt; info.session_id = session_id; - auto packet = BufferWriter{mtproto::Transport::write(storer, auth_key, &info), transport_->max_prepend_size(), + auto packet = BufferWriter{Transport::write(storer, auth_key, &info), transport_->max_prepend_size(), transport_->max_append_size()}; - mtproto::Transport::write(storer, auth_key, &info, packet.as_slice()); + Transport::write(storer, auth_key, &info, packet.as_slice()); bool use_quick_ack = false; if (quick_ack_token != 0 && transport_->support_quick_ack()) { @@ -45,12 +46,12 @@ void RawConnection::send_crypto(const Storer &storer, int64 session_id, int64 sa } uint64 RawConnection::send_no_crypto(const Storer &storer) { - mtproto::PacketInfo info; + PacketInfo info; info.no_crypto_flag = true; - auto packet = BufferWriter{mtproto::Transport::write(storer, mtproto::AuthKey(), &info), - transport_->max_prepend_size(), transport_->max_append_size()}; - mtproto::Transport::write(storer, mtproto::AuthKey(), &info, packet.as_slice()); + auto packet = BufferWriter{Transport::write(storer, AuthKey(), &info), transport_->max_prepend_size(), + transport_->max_append_size()}; + Transport::write(storer, AuthKey(), &info, packet.as_slice()); LOG(INFO) << "Send handshake packet: " << format::as_hex_dump<4>(packet.as_slice()); transport_->write(std::move(packet), false); return info.message_id; @@ -91,17 +92,17 @@ Status RawConnection::flush_read(const AuthKey &auth_key, Callback &callback) { PacketInfo info; info.version = 2; - TRY_RESULT(read_result, mtproto::Transport::read(packet.as_slice(), auth_key, &info)); + TRY_RESULT(read_result, Transport::read(packet.as_slice(), auth_key, &info)); switch (read_result.type()) { - case mtproto::Transport::ReadResult::Quickack: { + case Transport::ReadResult::Quickack: { TRY_STATUS(on_quick_ack(read_result.quick_ack(), callback)); break; } - case mtproto::Transport::ReadResult::Error: { + case Transport::ReadResult::Error: { TRY_STATUS(on_read_mtproto_error(read_result.error())); break; } - case mtproto::Transport::ReadResult::Packet: { + case Transport::ReadResult::Packet: { // If a packet was successfully decrypted, then it is ok to assume that the connection is alive if (!auth_key.empty()) { if (stats_callback_) { @@ -112,7 +113,7 @@ Status RawConnection::flush_read(const AuthKey &auth_key, Callback &callback) { TRY_STATUS(callback.on_raw_packet(info, packet.from_slice(read_result.packet()))); break; } - case mtproto::Transport::ReadResult::Nop: + case Transport::ReadResult::Nop: break; default: UNREACHABLE(); diff --git a/td/mtproto/RawConnection.h b/td/mtproto/RawConnection.h index ddea988d..f8e26160 100644 --- a/td/mtproto/RawConnection.h +++ b/td/mtproto/RawConnection.h @@ -29,6 +29,7 @@ struct PacketInfo; namespace td { namespace mtproto { + class RawConnection { public: class StatsCallback { diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index 9ddc54fd..f099129c 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -7,13 +7,8 @@ #include "td/mtproto/SessionConnection.h" #include "td/mtproto/AuthData.h" -#include "td/mtproto/AuthKey.h" #include "td/mtproto/CryptoStorer.h" -#include "td/mtproto/Handshake.h" -#include "td/mtproto/NoCryptoStorer.h" - -#include "td/mtproto/HttpTransport.h" -#include "td/mtproto/TcpTransport.h" +#include "td/mtproto/PacketStorer.h" #include "td/mtproto/Transport.h" #include "td/utils/as.h" @@ -650,7 +645,7 @@ Status SessionConnection::before_write() { return Status::OK(); } -Status SessionConnection::on_raw_packet(const td::mtproto::PacketInfo &info, BufferSlice packet) { +Status SessionConnection::on_raw_packet(const PacketInfo &info, BufferSlice packet) { auto old_main_message_id = main_message_id_; main_message_id_ = info.message_id; SCOPE_EXIT { @@ -799,14 +794,14 @@ std::pair SessionConnection::encrypted_bind(int64 perm_key, Query query{auth_data_->next_message_id(Time::now_cached()), 0, object_packet.as_buffer_slice(), false, 0, false}; PacketStorer query_storer(query, Slice()); - mtproto::PacketInfo info; + PacketInfo info; info.version = 1; info.no_crypto_flag = false; info.salt = Random::secure_int64(); info.session_id = Random::secure_int64(); - auto packet = BufferWriter{mtproto::Transport::write(query_storer, auth_data_->get_main_auth_key(), &info), 0, 0}; - mtproto::Transport::write(query_storer, auth_data_->get_main_auth_key(), &info, packet.as_slice()); + auto packet = BufferWriter{Transport::write(query_storer, auth_data_->get_main_auth_key(), &info), 0, 0}; + Transport::write(query_storer, auth_data_->get_main_auth_key(), &info, packet.as_slice()); return std::make_pair(query.message_id, packet.as_buffer_slice()); } @@ -1028,5 +1023,6 @@ void SessionConnection::force_close(SessionConnection::Callback *callback) { callback_ = callback; do_close(Status::OK()); } + } // namespace mtproto } // namespace td diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index 7258d09e..d6b3246c 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -6,7 +6,6 @@ // #pragma once -#include "td/mtproto/crypto.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/utils.h" @@ -258,7 +257,7 @@ class SessionConnection Status do_flush() TD_WARN_UNUSED_RESULT; Status before_write() override TD_WARN_UNUSED_RESULT; - Status on_raw_packet(const td::mtproto::PacketInfo &info, BufferSlice packet) override; + Status on_raw_packet(const PacketInfo &info, BufferSlice packet) override; Status on_quick_ack(uint64 quick_ack_token) override; void on_read(size_t size) override; }; diff --git a/td/mtproto/Transport.h b/td/mtproto/Transport.h index 8b9ec8c3..bfeae13b 100644 --- a/td/mtproto/Transport.h +++ b/td/mtproto/Transport.h @@ -18,6 +18,7 @@ namespace td { namespace mtproto { + class AuthKey; #pragma pack(push, 4) diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index 5a4d082b..9f34a12f 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -19,6 +19,12 @@ #include "td/telegram/net/Session.h" #include "td/telegram/StateManager.h" #include "td/telegram/TdDb.h" +#include "td/telegram/telegram_api.h" + +#include "td/mtproto/AuthData.h" +#include "td/mtproto/AuthKey.h" +#include "td/mtproto/crypto.h" +#include "td/mtproto/RawConnection.h" #if !TD_EMSCRIPTEN //FIXME #include "td/net/HttpQuery.h" @@ -28,8 +34,6 @@ #include "td/actor/actor.h" -#include "td/telegram/telegram_api.h" - #include "td/utils/base64.h" #include "td/utils/buffer.h" #include "td/utils/common.h" diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index a18b2f23..aca8ca18 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -49,7 +49,6 @@ #include "td/utils/tl_helpers.h" #include -#include #include #include #include diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 92dcf3ee..3c4bf131 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -33,6 +33,7 @@ #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" +#include #include #include #include diff --git a/td/telegram/DeviceTokenManager.cpp b/td/telegram/DeviceTokenManager.cpp index 76d93f00..2f6afd8d 100644 --- a/td/telegram/DeviceTokenManager.cpp +++ b/td/telegram/DeviceTokenManager.cpp @@ -17,10 +17,8 @@ #include "td/mtproto/crypto.h" -#include "td/utils/as.h" #include "td/utils/base64.h" #include "td/utils/buffer.h" -#include "td/utils/crypto.h" #include "td/utils/format.h" #include "td/utils/JsonBuilder.h" #include "td/utils/logging.h" diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 9e2ec4bb..2d99bfd3 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -47,6 +47,7 @@ #include "td/utils/Heap.h" #include "td/utils/Hints.h" #include "td/utils/logging.h" +#include "td/utils/Slice.h" #include "td/utils/Status.h" #include "td/utils/StringBuilder.h" #include "td/utils/tl_storers.h" diff --git a/td/telegram/SecretChatActor.cpp b/td/telegram/SecretChatActor.cpp index 4227cbf2..b542769c 100644 --- a/td/telegram/SecretChatActor.cpp +++ b/td/telegram/SecretChatActor.cpp @@ -6,8 +6,6 @@ // #include "td/telegram/SecretChatActor.h" -#include "td/mtproto/PacketStorer.h" - #include "td/telegram/net/NetQueryCreator.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/UniqueId.h" @@ -15,6 +13,10 @@ #include "td/telegram/secret_api.hpp" #include "td/telegram/telegram_api.hpp" +#include "td/mtproto/PacketStorer.h" +#include "td/mtproto/Transport.h" +#include "td/mtproto/utils.h" + #include "td/db/binlog/BinlogHelper.h" #include "td/db/binlog/BinlogInterface.h" diff --git a/td/telegram/SecretChatActor.h b/td/telegram/SecretChatActor.h index ccec3d9e..d57c28d2 100644 --- a/td/telegram/SecretChatActor.h +++ b/td/telegram/SecretChatActor.h @@ -14,7 +14,6 @@ #include "td/mtproto/AuthKey.h" #include "td/mtproto/crypto.h" -#include "td/mtproto/Transport.h" #include "td/telegram/DhConfig.h" #include "td/telegram/logevent/SecretChatEvent.h" diff --git a/td/telegram/SecretChatsManager.cpp b/td/telegram/SecretChatsManager.cpp index c40b0822..967ac59a 100644 --- a/td/telegram/SecretChatsManager.cpp +++ b/td/telegram/SecretChatsManager.cpp @@ -22,6 +22,8 @@ #include "td/telegram/secret_api.h" #include "td/telegram/telegram_api.hpp" +#include "td/mtproto/crypto.h" + #include "td/actor/PromiseFuture.h" #include "td/db/binlog/BinlogEvent.h" diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 2f703ac0..a57779aa 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -26,6 +26,7 @@ #include "td/telegram/files/FileGcParameters.h" #include "td/telegram/files/FileId.h" #include "td/telegram/files/FileManager.h" +#include "td/telegram/files/FileSourceId.h" #include "td/telegram/files/FileType.h" #include "td/telegram/Global.h" #include "td/telegram/HashtagHints.h" diff --git a/td/telegram/files/FileData.h b/td/telegram/files/FileData.h index 96fc4bd9..2fe84702 100644 --- a/td/telegram/files/FileData.h +++ b/td/telegram/files/FileData.h @@ -7,16 +7,17 @@ #pragma once #include "td/telegram/DialogId.h" -#include "td/telegram/Global.h" #include "td/telegram/FileReferenceManager.h" #include "td/telegram/FileReferenceManager.hpp" #include "td/telegram/files/FileEncryptionKey.h" #include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileSourceId.h" +#include "td/telegram/Global.h" #include "td/telegram/Td.h" #include "td/utils/common.h" #include "td/utils/format.h" +#include "td/utils/misc.h" #include "td/utils/StringBuilder.h" #include "td/utils/tl_helpers.h" diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 965a57c8..51beb26c 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -41,11 +41,11 @@ class FileReferenceView { LOG(ERROR) << "File reference is too big " << base64_encode(second); second = invalid_file_reference(); } - char second_length = static_cast(narrow_cast(second.size())); + char second_length = static_cast(static_cast(second.size())); return PSTRING() << second_length << first << second; } - FileReferenceView(Slice data) { + explicit FileReferenceView(Slice data) { if (data.empty()) { return; } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 9be1cb89..9c83366c 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -9,6 +9,7 @@ #include "td/telegram/telegram_api.h" #include "td/telegram/ConfigShared.h" +#include "td/telegram/FileReferenceManager.h" #include "td/telegram/files/FileData.h" #include "td/telegram/files/FileDb.h" #include "td/telegram/files/FileLoaderUtils.h" diff --git a/td/telegram/net/PublicRsaKeyWatchdog.cpp b/td/telegram/net/PublicRsaKeyWatchdog.cpp index 957fed24..25fab0a9 100644 --- a/td/telegram/net/PublicRsaKeyWatchdog.cpp +++ b/td/telegram/net/PublicRsaKeyWatchdog.cpp @@ -12,6 +12,8 @@ #include "td/telegram/telegram_api.h" +#include "td/mtproto/crypto.h" + #include "td/utils/logging.h" #include "td/utils/Time.h" diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index a20c3c11..25c115b2 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -17,8 +17,10 @@ #include "td/telegram/StateManager.h" #include "td/telegram/UniqueId.h" +#include "td/mtproto/crypto.h" #include "td/mtproto/Handshake.h" #include "td/mtproto/HandshakeActor.h" +#include "td/mtproto/IStreamTransport.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/SessionConnection.h" diff --git a/td/telegram/net/Session.h b/td/telegram/net/Session.h index 7305f22a..97bb8dbd 100644 --- a/td/telegram/net/Session.h +++ b/td/telegram/net/Session.h @@ -6,18 +6,19 @@ // #pragma once +#include "td/telegram/net/AuthDataShared.h" +#include "td/telegram/net/NetQuery.h" +#include "td/telegram/net/TempAuthKeyWatchdog.h" +#include "td/telegram/StateManager.h" + #include "td/mtproto/AuthData.h" +#include "td/mtproto/AuthKey.h" #include "td/mtproto/Handshake.h" #include "td/mtproto/SessionConnection.h" #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" -#include "td/telegram/net/AuthDataShared.h" -#include "td/telegram/net/NetQuery.h" -#include "td/telegram/net/TempAuthKeyWatchdog.h" -#include "td/telegram/StateManager.h" - #include "td/utils/buffer.h" #include "td/utils/common.h" #include "td/utils/List.h" diff --git a/td/telegram/net/SessionProxy.h b/td/telegram/net/SessionProxy.h index 40d788c9..d9512cdc 100644 --- a/td/telegram/net/SessionProxy.h +++ b/td/telegram/net/SessionProxy.h @@ -9,6 +9,9 @@ #include "td/telegram/net/AuthDataShared.h" #include "td/telegram/net/NetQuery.h" +#include "td/mtproto/AuthData.h" +#include "td/mtproto/AuthKey.h" + #include "td/actor/actor.h" #include diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 7d1e7452..bd8ad897 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -12,7 +12,7 @@ #include "td/mtproto/crypto.h" #include "td/mtproto/Handshake.h" #include "td/mtproto/HandshakeActor.h" -#include "td/mtproto/HandshakeConnection.h" +#include "td/mtproto/IStreamTransport.h" #include "td/mtproto/PingConnection.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/Transport.h" @@ -26,7 +26,6 @@ #include "td/telegram/net/PublicRsaKeyShared.h" #include "td/telegram/NotificationManager.h" -#include "td/utils/as.h" #include "td/utils/base64.h" #include "td/utils/logging.h" #include "td/utils/port/IPAddress.h"