From 5e2a71d8fb8ef19e5a3be9305c59d562d168c223 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 31 Jan 2019 05:37:59 +0300 Subject: [PATCH] Add Query.h. GitOrigin-RevId: f795d804e9d3feb4f72517dc84bd13bfe7955bc4 --- CMakeLists.txt | 1 + td/mtproto/CryptoStorer.h | 11 ++++++----- td/mtproto/Query.h | 25 +++++++++++++++++++++++++ td/mtproto/SessionConnection.cpp | 9 +++++---- td/mtproto/SessionConnection.h | 4 ++-- td/mtproto/utils.h | 11 ----------- 6 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 td/mtproto/Query.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2abd374ab..fbd7f4212 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -450,6 +450,7 @@ set(TDLIB_SOURCE td/mtproto/PacketInfo.h td/mtproto/PacketStorer.h td/mtproto/PingConnection.h + td/mtproto/Query.h td/mtproto/RawConnection.h td/mtproto/SessionConnection.h td/mtproto/TcpTransport.h diff --git a/td/mtproto/CryptoStorer.h b/td/mtproto/CryptoStorer.h index 64b2a39b2..355fc7ca9 100644 --- a/td/mtproto/CryptoStorer.h +++ b/td/mtproto/CryptoStorer.h @@ -8,6 +8,7 @@ #include "td/mtproto/AuthData.h" #include "td/mtproto/PacketStorer.h" +#include "td/mtproto/Query.h" #include "td/mtproto/utils.h" #include "td/mtproto/mtproto_api.h" @@ -102,7 +103,7 @@ class CancelVectorImpl { class QueryImpl { public: - QueryImpl(const Query &query, Slice header) : query_(query), header_(header) { + QueryImpl(const MtprotoQuery &query, Slice header) : query_(query), header_(header) { } template @@ -144,13 +145,13 @@ class QueryImpl { } private: - const Query &query_; + const MtprotoQuery &query_; Slice header_; }; class QueryVectorImpl { public: - QueryVectorImpl(const vector &to_send, Slice header) : to_send_(to_send), header_(header) { + QueryVectorImpl(const vector &to_send, Slice header) : to_send_(to_send), header_(header) { } template @@ -164,7 +165,7 @@ class QueryVectorImpl { } private: - const vector &to_send_; + const vector &to_send_; Slice header_; }; @@ -187,7 +188,7 @@ class ContainerImpl { class CryptoImpl { public: - CryptoImpl(const vector &to_send, Slice header, vector &&to_ack, int64 ping_id, int ping_timeout, + CryptoImpl(const vector &to_send, Slice header, vector &&to_ack, int64 ping_id, int ping_timeout, int max_delay, int max_after, int max_wait, int future_salt_n, vector get_info, vector resend, vector cancel, bool destroy_key, AuthData *auth_data, uint64 *container_id, uint64 *get_info_id, uint64 *resend_id, uint64 *ping_message_id, uint64 *parent_message_id) diff --git a/td/mtproto/Query.h b/td/mtproto/Query.h new file mode 100644 index 000000000..9b4887c14 --- /dev/null +++ b/td/mtproto/Query.h @@ -0,0 +1,25 @@ +// +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2019 +// +// 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) +// +#pragma once + +#include "td/utils/buffer.h" +#include "td/utils/common.h" + +namespace td { +namespace mtproto { + +struct MtprotoQuery { + int64 message_id; + int32 seq_no; + BufferSlice packet; + bool gzip_flag; + uint64 invoke_after_id; + bool use_quick_ack; +}; + +} // namespace mtproto +} // namespace td diff --git a/td/mtproto/SessionConnection.cpp b/td/mtproto/SessionConnection.cpp index f099129cd..db0fb6be1 100644 --- a/td/mtproto/SessionConnection.cpp +++ b/td/mtproto/SessionConnection.cpp @@ -749,7 +749,7 @@ Result SessionConnection::send_query(BufferSlice buffer, bool gzip_flag, if (to_send_.empty()) { send_before(Time::now_cached() + QUERY_DELAY); } - to_send_.push_back(Query{message_id, seq_no, std::move(buffer), gzip_flag, invoke_after_id, use_quick_ack}); + to_send_.push_back(MtprotoQuery{message_id, seq_no, std::move(buffer), gzip_flag, invoke_after_id, use_quick_ack}); VLOG(mtproto) << "Invoke query " << message_id << " of size " << to_send_.back().packet.size() << " with seq_no " << seq_no << " after " << invoke_after_id << (use_quick_ack ? " with quick ack" : ""); @@ -791,7 +791,8 @@ std::pair SessionConnection::encrypted_bind(int64 perm_key, auto real_size = object_storer.store(object_packet.as_slice().ubegin()); CHECK(size == real_size); - Query query{auth_data_->next_message_id(Time::now_cached()), 0, object_packet.as_buffer_slice(), false, 0, false}; + MtprotoQuery query{ + auth_data_->next_message_id(Time::now_cached()), 0, object_packet.as_buffer_slice(), false, 0, false}; PacketStorer query_storer(query, Slice()); PacketInfo info; @@ -871,7 +872,7 @@ void SessionConnection::flush_packet() { send_till++; } } - std::vector queries; + std::vector queries; if (send_till == to_send_.size()) { queries = std::move(to_send_); } else if (send_till != 0) { @@ -943,7 +944,7 @@ void SessionConnection::flush_packet() { } if (container_id != 0) { - vector ids = transform(queries, [](const Query &x) { return static_cast(x.message_id); }); + vector ids = transform(queries, [](const MtprotoQuery &x) { return static_cast(x.message_id); }); // some acks may be lost here. Nobody will resend them if something goes wrong with query. // It is mostly problem for server. We will just drop this answers in next connection diff --git a/td/mtproto/SessionConnection.h b/td/mtproto/SessionConnection.h index f7c75c81d..5a3173523 100644 --- a/td/mtproto/SessionConnection.h +++ b/td/mtproto/SessionConnection.h @@ -8,7 +8,7 @@ #include "td/mtproto/RawConnection.h" #include "td/mtproto/PacketInfo.h" -#include "td/mtproto/utils.h" +#include "td/mtproto/Query.h" #include "td/utils/buffer.h" #include "td/utils/format.h" @@ -152,7 +152,7 @@ class SessionConnection static constexpr int HTTP_MAX_DELAY = 30; // 0.03s static constexpr int TEMP_KEY_TIMEOUT = 60 * 60 * 24; // one day - vector to_send_; + vector to_send_; vector to_ack_; double force_send_at_ = 0; diff --git a/td/mtproto/utils.h b/td/mtproto/utils.h index 0ca769adc..a315f63ac 100644 --- a/td/mtproto/utils.h +++ b/td/mtproto/utils.h @@ -19,17 +19,6 @@ namespace td { -namespace mtproto { -struct Query { - int64 message_id; - int32 seq_no; - BufferSlice packet; - bool gzip_flag; - uint64 invoke_after_id; - bool use_quick_ack; -}; -} // namespace mtproto - template Result fetch_result(Slice message, bool check_end = true) { TlParser parser(message);