From 9592aac404d137400c7f9c1b52734222769dcecf Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 13 Aug 2020 16:57:28 +0300 Subject: [PATCH] Minor improvements. GitOrigin-RevId: 09fbcc25ade8d77c13dc580f13b206c07ba53f9f --- td/telegram/net/Session.cpp | 5 +++++ tdnet/td/net/HttpChunkedByteFlow.cpp | 2 +- test/data.cpp | 4 ++++ test/db.cpp | 6 +++--- test/http.cpp | 5 ++--- test/main.cpp | 3 +-- test/mtproto.cpp | 17 ++++++++--------- test/secure_storage.cpp | 4 ++-- test/tdclient.cpp | 7 +++---- 9 files changed, 29 insertions(+), 24 deletions(-) diff --git a/td/telegram/net/Session.cpp b/td/telegram/net/Session.cpp index 51912ccb5..bce60fd5b 100644 --- a/td/telegram/net/Session.cpp +++ b/td/telegram/net/Session.cpp @@ -596,6 +596,7 @@ void Session::on_container_sent(uint64 container_id, vector msg_ids) { void Session::on_message_ack(uint64 id) { on_message_ack_impl(id, 1); } + void Session::on_message_ack_impl(uint64 id, int32 type) { auto cit = sent_containers_.find(id); if (cit != sent_containers_.end()) { @@ -643,6 +644,7 @@ void Session::dec_container(uint64 message_id, Query *query) { sent_containers_.erase(it); } } + void Session::cleanup_container(uint64 message_id, Query *query) { if (query->container_id == message_id) { // message was sent without any container @@ -879,6 +881,7 @@ void Session::on_message_info(uint64 id, int32 state, uint64 answer_id, int32 an current_info_->connection->resend_answer(answer_id); } } + Status Session::on_destroy_auth_key() { auth_data_.drop_main_auth_key(); on_auth_key_updated(); @@ -1106,6 +1109,7 @@ void Session::connection_close(ConnectionInfo *info) { info->connection->force_close(static_cast(this)); CHECK(info->state == ConnectionInfo::State::Empty); } + bool Session::need_send_check_main_key() const { return need_check_main_key_ && auth_data_.get_main_auth_key().id() != being_checked_main_auth_key_id_; } @@ -1135,6 +1139,7 @@ bool Session::need_send_bind_key() const { return auth_data_.use_pfs() && !auth_data_.get_bind_flag() && auth_data_.get_tmp_auth_key().id() != being_binded_tmp_auth_key_id_; } + bool Session::need_send_query() const { return !close_flag_ && !need_check_main_key_ && (!auth_data_.use_pfs() || auth_data_.get_bind_flag()) && !pending_queries_.empty() && !can_destroy_auth_key(); diff --git a/tdnet/td/net/HttpChunkedByteFlow.cpp b/tdnet/td/net/HttpChunkedByteFlow.cpp index d0d462138..9f83f61a3 100644 --- a/tdnet/td/net/HttpChunkedByteFlow.cpp +++ b/tdnet/td/net/HttpChunkedByteFlow.cpp @@ -74,7 +74,7 @@ bool HttpChunkedByteFlow::loop() { state_ = State::ReadChunkLength; len_ = 0; } - } while (0); + } while (false); if (!is_input_active_ && !result) { finish(Status::Error("Unexpected end of stream")); } diff --git a/test/data.cpp b/test/data.cpp index 0df469262..ee3cb0c3f 100644 --- a/test/data.cpp +++ b/test/data.cpp @@ -5,7 +5,9 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "data.h" + namespace td { + static const char thumbnail_arr[] = "_9j_4AAQSkZJRgABAQEASABIAAD_2wBDAAICAgICAQICAgIDAgIDAwYEAwMDAwcFBQQGCAcJCAgHCAgJCg0LCQoMCggICw8LDA0ODg8OCQsQERAOEQ" "0ODg7_2wBDAQIDAwMDAwcEBAcOCQgJDg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg4ODg7_wAARCAAyADIDASIA" @@ -152,6 +154,8 @@ static const char sqlite_sample_db_arr[] = "Wk6mXCxM++OZxA8K3MGlQuG7Gmodcz6FHh9mqoIZZh6OrObpBUrJfdoZeWXR+" "GVt8zi3m0oPlAhNUyi3a6zeZcvqfwI3M7zoXxGU2q0ETZgfCE26H9E+PNxes7mw4SwEl78lclmnNhUlZ5C4Y8v2YJnmFn8+a6WdrgjTU2awQ/" "osSJFtKuNgOw9n72uyhPOkEB4qcVZ1A="; + const char *sqlite_sample_db = sqlite_sample_db_arr; const size_t sqlite_sample_db_size = sizeof(sqlite_sample_db_arr) - 1; + } // namespace td diff --git a/test/db.cpp b/test/db.cpp index b5064072d..7535f8f83 100644 --- a/test/db.cpp +++ b/test/db.cpp @@ -4,6 +4,8 @@ // 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) // +#include "data.h" + #include "td/db/binlog/BinlogHelper.h" #include "td/db/binlog/ConcurrentBinlog.h" #include "td/db/BinlogKeyValue.h" @@ -28,8 +30,6 @@ #include "td/utils/Status.h" #include "td/utils/tests.h" -#include "data.h" - #include #include #include @@ -200,7 +200,7 @@ TEST(DB, sqlite_encryption_migrate) { SqliteDb::destroy(path).ignore(); auto cucumber = DbKey::password("cucumber"); auto empty = DbKey::empty(); - if (0) { + if (false) { // sqlite_sample_db was generated by the following code { SqliteDb::change_key(path, cucumber, empty).ensure(); diff --git a/test/http.cpp b/test/http.cpp index ab55708bf..a087dd72e 100644 --- a/test/http.cpp +++ b/test/http.cpp @@ -4,7 +4,7 @@ // 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) // -#include "td/utils/tests.h" +#include "data.h" #include "td/net/HttpChunkedByteFlow.h" #include "td/net/HttpHeaderCreator.h" @@ -31,10 +31,9 @@ #include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" +#include "td/utils/tests.h" #include "td/utils/UInt.h" -#include "data.h" - #include #include diff --git a/test/main.cpp b/test/main.cpp index 6999a0dcc..e45ca5234 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -4,13 +4,12 @@ // 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) // -#include "td/utils/tests.h" - #include "td/utils/common.h" #include "td/utils/crypto.h" #include "td/utils/logging.h" #include "td/utils/OptionParser.h" #include "td/utils/Slice.h" +#include "td/utils/tests.h" #if TD_EMSCRIPTEN #include diff --git a/test/mtproto.cpp b/test/mtproto.cpp index c6b11de20..9651b2c67 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -4,10 +4,11 @@ // 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) // -#include "td/utils/tests.h" - -#include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" +#include "td/telegram/ConfigManager.h" +#include "td/telegram/net/DcId.h" +#include "td/telegram/net/PublicRsaKeyShared.h" +#include "td/telegram/net/Session.h" +#include "td/telegram/NotificationManager.h" #include "td/mtproto/AuthData.h" #include "td/mtproto/DhHandshake.h" @@ -25,11 +26,8 @@ #include "td/net/Socks5.h" #include "td/net/TransparentProxy.h" -#include "td/telegram/ConfigManager.h" -#include "td/telegram/net/DcId.h" -#include "td/telegram/net/PublicRsaKeyShared.h" -#include "td/telegram/net/Session.h" -#include "td/telegram/NotificationManager.h" +#include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" #include "td/utils/base64.h" #include "td/utils/common.h" @@ -39,6 +37,7 @@ #include "td/utils/port/SocketFd.h" #include "td/utils/Random.h" #include "td/utils/Status.h" +#include "td/utils/tests.h" #include "td/utils/Time.h" REGISTER_TESTS(mtproto); diff --git a/test/secure_storage.cpp b/test/secure_storage.cpp index 178947fe6..3e00fa8c9 100644 --- a/test/secure_storage.cpp +++ b/test/secure_storage.cpp @@ -4,14 +4,14 @@ // 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) // +#include "td/telegram/SecureStorage.h" + #include "td/utils/buffer.h" #include "td/utils/filesystem.h" #include "td/utils/logging.h" #include "td/utils/port/path.h" #include "td/utils/tests.h" -#include "td/telegram/SecureStorage.h" - using namespace td; TEST(SecureStorage, secret) { diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 8709ebf3c..7b421231b 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -6,15 +6,14 @@ // #include "data.h" -#include "td/actor/actor.h" -#include "td/actor/PromiseFuture.h" - #include "td/telegram/Client.h" #include "td/telegram/ClientActor.h" #include "td/telegram/files/PartsManager.h" - #include "td/telegram/td_api.h" +#include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" + #include "td/utils/base64.h" #include "td/utils/BufferedFd.h" #include "td/utils/common.h"