summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h')
-rw-r--r--protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h36
1 files changed, 20 insertions, 16 deletions
diff --git a/protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h b/protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h
index 5c9341ddc9..b81df49a4f 100644
--- a/protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h
+++ b/protocols/Telegram/tdlib/td/td/mtproto/HandshakeConnection.h
@@ -1,5 +1,5 @@
//
-// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018
+// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@@ -9,34 +9,36 @@
#include "td/mtproto/AuthKey.h"
#include "td/mtproto/Handshake.h"
#include "td/mtproto/NoCryptoStorer.h"
+#include "td/mtproto/PacketInfo.h"
+#include "td/mtproto/PacketStorer.h"
#include "td/mtproto/RawConnection.h"
-#include "td/mtproto/Transport.h"
-#include "td/mtproto/utils.h"
#include "td/utils/buffer.h"
#include "td/utils/common.h"
#include "td/utils/format.h"
#include "td/utils/logging.h"
-#include "td/utils/port/Fd.h"
+#include "td/utils/port/detail/PollableFd.h"
#include "td/utils/Status.h"
+#include "td/utils/StorerBase.h"
namespace td {
namespace mtproto {
-class HandshakeConnection
+
+class HandshakeConnection final
: private RawConnection::Callback
, private AuthKeyHandshake::Callback {
public:
- HandshakeConnection(std::unique_ptr<RawConnection> raw_connection, AuthKeyHandshake *handshake,
- std::unique_ptr<AuthKeyHandshakeContext> context)
+ HandshakeConnection(unique_ptr<RawConnection> raw_connection, AuthKeyHandshake *handshake,
+ unique_ptr<AuthKeyHandshakeContext> context)
: raw_connection_(std::move(raw_connection)), handshake_(handshake), context_(std::move(context)) {
handshake_->resume(this);
}
- Fd &get_pollable() {
- return raw_connection_->get_pollable();
+ PollableFdInfo &get_poll_info() {
+ return raw_connection_->get_poll_info();
}
- std::unique_ptr<RawConnection> move_as_raw_connection() {
+ unique_ptr<RawConnection> move_as_raw_connection() {
return std::move(raw_connection_);
}
@@ -54,16 +56,16 @@ class HandshakeConnection
}
private:
- std::unique_ptr<RawConnection> raw_connection_;
+ unique_ptr<RawConnection> raw_connection_;
AuthKeyHandshake *handshake_;
- std::unique_ptr<AuthKeyHandshakeContext> context_;
+ unique_ptr<AuthKeyHandshakeContext> context_;
- void send_no_crypto(const Storer &storer) override {
+ void send_no_crypto(const Storer &storer) final {
raw_connection_->send_no_crypto(PacketStorer<NoCryptoImpl>(0, storer));
}
- Status on_raw_packet(const PacketInfo &packet_info, BufferSlice packet) override {
- if (packet_info.no_crypto_flag == false) {
+ Status on_raw_packet(const PacketInfo &packet_info, BufferSlice packet) final {
+ if (!packet_info.no_crypto_flag) {
return Status::Error("Expected not encrypted packet");
}
@@ -73,9 +75,11 @@ class HandshakeConnection
}
packet.confirm_read(12);
- TRY_STATUS(handshake_->on_message(packet.as_slice(), this, context_.get()));
+ auto fixed_packet_size = packet.size() & ~3; // remove some padded data
+ TRY_STATUS(handshake_->on_message(packet.as_slice().truncate(fixed_packet_size), this, context_.get()));
return Status::OK();
}
};
+
} // namespace mtproto
} // namespace td