diff --git a/benchmark/bench_misc.cpp b/benchmark/bench_misc.cpp index 227cb109..52b5b19d 100644 --- a/benchmark/bench_misc.cpp +++ b/benchmark/bench_misc.cpp @@ -248,9 +248,9 @@ class WalkPathBench : public Benchmark { int cnt = 0; td::walk_path("A/", [&](CSlice path, auto type) { - if (type == td::WalkPath::Type::EnterDir) { - return; - } + if (type == td::WalkPath::Type::EnterDir) { + return; + } stat(path).ok(); cnt++; }) diff --git a/td/mtproto/Ping.cpp b/td/mtproto/Ping.cpp index 1fbaf21a..f7748e0c 100644 --- a/td/mtproto/Ping.cpp +++ b/td/mtproto/Ping.cpp @@ -8,29 +8,35 @@ #include "td/mtproto/AuthData.h" #include "td/mtproto/PingConnection.h" +#include "td/mtproto/RawConnection.h" + +#include "td/actor/actor.h" +#include "td/actor/PromiseFuture.h" + +#include "td/utils/logging.h" +#include "td/utils/Status.h" -#include "td/utils/crypto.h" -#include "td/utils/Random.h" namespace td { namespace mtproto { -ActorOwn<> create_ping_actor(std::string debug, unique_ptr raw_connection, - unique_ptr auth_data, - Promise> promise, ActorShared<> parent) { + +ActorOwn<> create_ping_actor(std::string debug, unique_ptr raw_connection, + unique_ptr auth_data, Promise> promise, + ActorShared<> parent) { class PingActor : public Actor { public: - PingActor(unique_ptr raw_connection, unique_ptr auth_data, - Promise> promise, ActorShared<> parent) + PingActor(unique_ptr raw_connection, unique_ptr auth_data, + Promise> promise, ActorShared<> parent) : promise_(std::move(promise)), parent_(std::move(parent)) { if (auth_data) { - ping_connection_ = mtproto::PingConnection::create_ping_pong(std::move(raw_connection), std::move(auth_data)); + ping_connection_ = PingConnection::create_ping_pong(std::move(raw_connection), std::move(auth_data)); } else { - ping_connection_ = mtproto::PingConnection::create_req_pq(std::move(raw_connection), 2); + ping_connection_ = PingConnection::create_req_pq(std::move(raw_connection), 2); } } private: - unique_ptr ping_connection_; - Promise> promise_; + unique_ptr ping_connection_; + Promise> promise_; ActorShared<> parent_; void start_up() override { @@ -97,5 +103,6 @@ ActorOwn<> create_ping_actor(std::string debug, unique_ptr(create_actor(PSLICE() << "PingActor<" << debug << ">", std::move(raw_connection), std::move(auth_data), std::move(promise), std::move(parent))); } + } // namespace mtproto } // namespace td diff --git a/td/mtproto/Ping.h b/td/mtproto/Ping.h index 7343edd3..699d6748 100644 --- a/td/mtproto/Ping.h +++ b/td/mtproto/Ping.h @@ -5,16 +5,20 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #pragma once + +#include "td/mtproto/AuthData.h" #include "td/mtproto/RawConnection.h" -#include "td/mtproto/SessionConnection.h" -#include "td/mtproto/Handshake.h" #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" + +#include "td/utils/common.h" + namespace td { namespace mtproto { -ActorOwn<> create_ping_actor(std::string debug, unique_ptr raw_connection, - unique_ptr auth_data, - Promise> promise, ActorShared<> parent); + +ActorOwn<> create_ping_actor(string debug, unique_ptr raw_connection, unique_ptr auth_data, + Promise> promise, ActorShared<> parent); + } } // namespace td diff --git a/td/mtproto/PingConnection.cpp b/td/mtproto/PingConnection.cpp index f9face7e..407b162f 100644 --- a/td/mtproto/PingConnection.cpp +++ b/td/mtproto/PingConnection.cpp @@ -5,10 +5,28 @@ // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // #include "td/mtproto/PingConnection.h" + +#include "td/mtproto/AuthKey.h" +#include "td/mtproto/AuthData.h" +#include "td/mtproto/mtproto_api.h" +#include "td/mtproto/NoCryptoStorer.h" +#include "td/mtproto/PacketInfo.h" +#include "td/mtproto/PacketStorer.h" +#include "td/mtproto/PingConnection.h" +#include "td/mtproto/RawConnection.h" #include "td/mtproto/SessionConnection.h" +#include "td/mtproto/utils.h" + +#include "td/utils/buffer.h" +#include "td/utils/logging.h" +#include "td/utils/Random.h" +#include "td/utils/Time.h" +#include "td/utils/UInt.h" + namespace td { namespace mtproto { namespace detail { + class PingConnectionReqPQ : public PingConnection , private RawConnection::Callback { @@ -72,7 +90,7 @@ class PingConnectionPingPong : public PingConnection , private SessionConnection::Callback { public: - PingConnectionPingPong(unique_ptr raw_connection, unique_ptr auth_data) + PingConnectionPingPong(unique_ptr raw_connection, unique_ptr auth_data) : auth_data_(std::move(auth_data)) { auth_data_->set_header(""); connection_ = @@ -80,8 +98,8 @@ class PingConnectionPingPong } private: - unique_ptr auth_data_; - unique_ptr connection_; + unique_ptr auth_data_; + unique_ptr connection_; int pong_cnt_{0}; double rtt_; bool is_closed_{false}; @@ -165,12 +183,15 @@ class PingConnectionPingPong }; } // namespace detail + unique_ptr PingConnection::create_req_pq(unique_ptr raw_connection, size_t ping_count) { return make_unique(std::move(raw_connection), ping_count); } + unique_ptr PingConnection::create_ping_pong(unique_ptr raw_connection, unique_ptr auth_data) { return make_unique(std::move(raw_connection), std::move(auth_data)); } + } // namespace mtproto } // namespace td diff --git a/td/mtproto/PingConnection.h b/td/mtproto/PingConnection.h index eddf32df..a026679c 100644 --- a/td/mtproto/PingConnection.h +++ b/td/mtproto/PingConnection.h @@ -6,22 +6,12 @@ // #pragma once -#include "td/mtproto/AuthKey.h" #include "td/mtproto/AuthData.h" -#include "td/mtproto/NoCryptoStorer.h" -#include "td/mtproto/PacketInfo.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/common.h" #include "td/utils/port/detail/PollableFd.h" -#include "td/utils/Random.h" #include "td/utils/Status.h" -#include "td/utils/Time.h" -#include "td/utils/UInt.h" namespace td { namespace mtproto { diff --git a/td/telegram/StorageManager.h b/td/telegram/StorageManager.h index ad9dd03d..e6d211f4 100644 --- a/td/telegram/StorageManager.h +++ b/td/telegram/StorageManager.h @@ -14,8 +14,8 @@ #include "td/telegram/files/FileStatsWorker.h" #include "td/telegram/td_api.h" -#include "td/utils/common.h" #include "td/utils/CancellationToken.h" +#include "td/utils/common.h" #include "td/utils/Slice.h" #include "td/utils/Status.h" diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index b48f807c..c7b81e4a 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -2022,7 +2022,6 @@ class CliClient final : public Actor { } else if (op == "storage") { auto chat_limit = to_integer(args); send_request(td_api::make_object(chat_limit)); - //quit(); } else if (op == "storage_fast") { send_request(td_api::make_object()); } else if (op == "database") { diff --git a/td/telegram/files/FileGcWorker.cpp b/td/telegram/files/FileGcWorker.cpp index 6eb5ef4d..41613cab 100644 --- a/td/telegram/files/FileGcWorker.cpp +++ b/td/telegram/files/FileGcWorker.cpp @@ -16,6 +16,7 @@ #include "td/utils/misc.h" #include "td/utils/port/Clocks.h" #include "td/utils/port/path.h" +#include "td/utils/Status.h" #include "td/utils/Time.h" #include diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index 5729c82f..7fb6203a 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -24,6 +24,7 @@ #include "td/utils/port/path.h" #include "td/utils/port/Stat.h" #include "td/utils/Slice.h" +#include "td/utils/Status.h" #include "td/utils/Time.h" #include "td/utils/tl_parsers.h" @@ -106,33 +107,35 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) { continue; } auto files_dir = get_files_dir(file_type); - td::walk_path(files_dir, [&](CSlice path, WalkPath::Type type) { - if (token) { - return WalkPath::Action::Abort; - } - if (type != WalkPath::Type::NotDir) { - return WalkPath::Action::Continue; - } - auto r_stat = stat(path); - if (r_stat.is_error()) { - LOG(WARNING) << "Stat in files gc failed: " << r_stat.error(); - return WalkPath::Action::Continue; - } - auto stat = r_stat.move_as_ok(); - if (ends_with(path, "/.nomedia") && stat.size_ == 0) { - // skip .nomedia file - return WalkPath::Action::Continue; - } + td::walk_path(files_dir, + [&](CSlice path, WalkPath::Type type) { + if (token) { + return WalkPath::Action::Abort; + } + if (type != WalkPath::Type::NotDir) { + return WalkPath::Action::Continue; + } + auto r_stat = stat(path); + if (r_stat.is_error()) { + LOG(WARNING) << "Stat in files gc failed: " << r_stat.error(); + return WalkPath::Action::Continue; + } + auto stat = r_stat.move_as_ok(); + if (ends_with(path, "/.nomedia") && stat.size_ == 0) { + // skip .nomedia file + return WalkPath::Action::Continue; + } - FsFileInfo info; - info.path = path.str(); - info.size = stat.size_; - info.file_type = file_type; - info.atime_nsec = stat.atime_nsec_; - info.mtime_nsec = stat.mtime_nsec_; - callback(info); - return WalkPath::Action::Continue; - }).ignore(); + FsFileInfo info; + info.path = path.str(); + info.size = stat.size_; + info.file_type = file_type; + info.atime_nsec = stat.atime_nsec_; + info.mtime_nsec = stat.mtime_nsec_; + callback(info); + return WalkPath::Action::Continue; + }) + .ignore(); } } } // namespace diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h index 5b807d03..b82e08c0 100644 --- a/td/telegram/net/ConnectionCreator.h +++ b/td/telegram/net/ConnectionCreator.h @@ -36,6 +36,7 @@ #include #include +#include #include #include diff --git a/td/telegram/net/Session.h b/td/telegram/net/Session.h index fd255205..b1edbbce 100644 --- a/td/telegram/net/Session.h +++ b/td/telegram/net/Session.h @@ -20,6 +20,7 @@ #include "td/actor/PromiseFuture.h" #include "td/utils/buffer.h" +#include "td/utils/CancellationToken.h" #include "td/utils/common.h" #include "td/utils/List.h" #include "td/utils/Status.h" diff --git a/tdactor/td/actor/PromiseFuture.h b/tdactor/td/actor/PromiseFuture.h index 0d1c2c5e..fcf86db0 100644 --- a/tdactor/td/actor/PromiseFuture.h +++ b/tdactor/td/actor/PromiseFuture.h @@ -15,8 +15,6 @@ #include "td/utils/ScopeGuard.h" #include "td/utils/Status.h" -#include -#include #include #include #include diff --git a/tdutils/td/utils/CancellationToken.h b/tdutils/td/utils/CancellationToken.h index f2a7ff84..cabb7768 100644 --- a/tdutils/td/utils/CancellationToken.h +++ b/tdutils/td/utils/CancellationToken.h @@ -7,7 +7,10 @@ #pragma once #include +#include + namespace td { + namespace detail { struct RawCancellationToken { std::atomic is_cancelled_{false}; @@ -21,11 +24,6 @@ class CancellationToken { } explicit CancellationToken(std::shared_ptr token) : token_(std::move(token)) { } - CancellationToken(CancellationToken &&other) = default; - CancellationToken(const CancellationToken &other) = default; - CancellationToken &operator=(CancellationToken &&other) = default; - CancellationToken &operator=(const CancellationToken &other) = default; - ~CancellationToken() = default; private: std::shared_ptr token_; @@ -41,11 +39,11 @@ class CancellationTokenSource { token_ = std::move(other.token_); return *this; } + CancellationTokenSource(const CancellationTokenSource &other) = delete; + CancellationTokenSource &operator=(const CancellationTokenSource &other) = delete; ~CancellationTokenSource() { cancel(); } - CancellationTokenSource(const CancellationTokenSource &other) = delete; - CancellationTokenSource &operator=(const CancellationTokenSource &other) = delete; CancellationToken get_cancellation_token() { if (!token_) { @@ -64,4 +62,5 @@ class CancellationTokenSource { private: std::shared_ptr token_; }; + } // namespace td diff --git a/tdutils/td/utils/port/path.h b/tdutils/td/utils/port/path.h index 404b662b..efe2e047 100644 --- a/tdutils/td/utils/port/path.h +++ b/tdutils/td/utils/port/path.h @@ -12,6 +12,7 @@ #include "td/utils/Status.h" #include +#include #include namespace td { @@ -50,7 +51,7 @@ class WalkPath { return do_run(path, func); } template ()("", Type::ExitDir))> - static TD_WARN_UNUSED_RESULT std::enable_if_t::value, Status> run(CSlice path, F &&func) { + static TD_WARN_UNUSED_RESULT std::enable_if_t::value, Status> run(CSlice path, F &&func) { return do_run(path, [&](CSlice name, Type type) { func(name, type); return Action::Continue; diff --git a/tdutils/test/port.cpp b/tdutils/test/port.cpp index 231f539b..5c71914b 100644 --- a/tdutils/test/port.cpp +++ b/tdutils/test/port.cpp @@ -6,11 +6,11 @@ // #include "td/utils/common.h" #include "td/utils/logging.h" +#include "td/utils/misc.h" #include "td/utils/port/FileFd.h" #include "td/utils/port/path.h" #include "td/utils/Slice.h" #include "td/utils/tests.h" -#include "td/utils/misc.h" using namespace td; @@ -35,38 +35,44 @@ TEST(Port, files) { int cnt = 0; const int ITER_COUNT = 1000; for (int i = 0; i < ITER_COUNT; i++) { - walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { - if (type == WalkPath::Type::NotDir) { - ASSERT_TRUE(name == fd_path || name == fd2_path); - } - cnt++; - }).ensure(); + walk_path(main_dir, + [&](CSlice name, WalkPath::Type type) { + if (type == WalkPath::Type::NotDir) { + ASSERT_TRUE(name == fd_path || name == fd2_path); + } + cnt++; + }) + .ensure(); } ASSERT_EQ((5 * 2 + 2) * ITER_COUNT, cnt); bool was_abort = false; - walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { - CHECK(!was_abort); - if (type == WalkPath::Type::EnterDir && ends_with(name, PSLICE() << TD_DIR_SLASH << "B")) { - was_abort = true; - return WalkPath::Action::Abort; - } - return WalkPath::Action::Continue; - }).ensure(); + walk_path(main_dir, + [&](CSlice name, WalkPath::Type type) { + CHECK(!was_abort); + if (type == WalkPath::Type::EnterDir && ends_with(name, PSLICE() << TD_DIR_SLASH << "B")) { + was_abort = true; + return WalkPath::Action::Abort; + } + return WalkPath::Action::Continue; + }) + .ensure(); CHECK(was_abort); cnt = 0; bool is_first_dir = true; - walk_path(main_dir, [&](CSlice name, WalkPath::Type type) { - cnt++; - if (type == WalkPath::Type::EnterDir) { - if (is_first_dir) { - is_first_dir = false; - } else { - return WalkPath::Action::SkipDir; - } - } - return WalkPath::Action::Continue; - }).ensure(); + walk_path(main_dir, + [&](CSlice name, WalkPath::Type type) { + cnt++; + if (type == WalkPath::Type::EnterDir) { + if (is_first_dir) { + is_first_dir = false; + } else { + return WalkPath::Action::SkipDir; + } + } + return WalkPath::Action::Continue; + }) + .ensure(); ASSERT_EQ(6, cnt); ASSERT_EQ(0u, fd.get_size()); diff --git a/test/mtproto.cpp b/test/mtproto.cpp index 4e4970e7..2ce9226a 100644 --- a/test/mtproto.cpp +++ b/test/mtproto.cpp @@ -9,12 +9,13 @@ #include "td/actor/actor.h" #include "td/actor/PromiseFuture.h" +#include "td/mtproto/AuthData.h" #include "td/mtproto/crypto.h" #include "td/mtproto/DhHandshake.h" #include "td/mtproto/Handshake.h" #include "td/mtproto/HandshakeActor.h" -#include "td/mtproto/PingConnection.h" #include "td/mtproto/Ping.h" +#include "td/mtproto/PingConnection.h" #include "td/mtproto/RawConnection.h" #include "td/mtproto/TransportType.h" @@ -23,9 +24,9 @@ #include "td/net/TransparentProxy.h" #include "td/telegram/ConfigManager.h" -#include "td/telegram/net/Session.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/utils/base64.h" @@ -33,7 +34,9 @@ #include "td/utils/logging.h" #include "td/utils/port/IPAddress.h" #include "td/utils/port/SocketFd.h" +#include "td/utils/Random.h" #include "td/utils/Status.h" +#include "td/utils/Time.h" REGISTER_TESTS(mtproto); diff --git a/test/tdclient.cpp b/test/tdclient.cpp index 9a841b71..922bbe5a 100644 --- a/test/tdclient.cpp +++ b/test/tdclient.cpp @@ -23,6 +23,7 @@ #include "td/utils/misc.h" #include "td/utils/port/FileFd.h" #include "td/utils/port/path.h" +#include "td/utils/port/thread.h" #include "td/utils/Random.h" #include "td/utils/Slice.h" #include "td/utils/Status.h"