Minor fixes.

GitOrigin-RevId: a5d8a4b0b9b9c4e858d7a9a7403bef0de7e009e0
This commit is contained in:
levlam 2019-05-22 21:17:24 +03:00
parent a1bc213f90
commit 34fcde6827
17 changed files with 134 additions and 99 deletions

View File

@ -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<mtproto::RawConnection> raw_connection,
unique_ptr<mtproto::AuthData> auth_data,
Promise<unique_ptr<mtproto::RawConnection>> promise, ActorShared<> parent) {
ActorOwn<> create_ping_actor(std::string debug, unique_ptr<RawConnection> raw_connection,
unique_ptr<AuthData> auth_data, Promise<unique_ptr<RawConnection>> promise,
ActorShared<> parent) {
class PingActor : public Actor {
public:
PingActor(unique_ptr<mtproto::RawConnection> raw_connection, unique_ptr<mtproto::AuthData> auth_data,
Promise<unique_ptr<mtproto::RawConnection>> promise, ActorShared<> parent)
PingActor(unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data,
Promise<unique_ptr<RawConnection>> 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<mtproto::PingConnection> ping_connection_;
Promise<unique_ptr<mtproto::RawConnection>> promise_;
unique_ptr<PingConnection> ping_connection_;
Promise<unique_ptr<RawConnection>> promise_;
ActorShared<> parent_;
void start_up() override {
@ -97,5 +103,6 @@ ActorOwn<> create_ping_actor(std::string debug, unique_ptr<mtproto::RawConnectio
return ActorOwn<>(create_actor<PingActor>(PSLICE() << "PingActor<" << debug << ">", std::move(raw_connection),
std::move(auth_data), std::move(promise), std::move(parent)));
}
} // namespace mtproto
} // namespace td

View File

@ -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<mtproto::RawConnection> raw_connection,
unique_ptr<mtproto::AuthData> auth_data,
Promise<unique_ptr<mtproto::RawConnection>> promise, ActorShared<> parent);
ActorOwn<> create_ping_actor(string debug, unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data,
Promise<unique_ptr<RawConnection>> promise, ActorShared<> parent);
}
} // namespace td

View File

@ -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<mtproto::RawConnection> raw_connection, unique_ptr<mtproto::AuthData> auth_data)
PingConnectionPingPong(unique_ptr<RawConnection> raw_connection, unique_ptr<AuthData> auth_data)
: auth_data_(std::move(auth_data)) {
auth_data_->set_header("");
connection_ =
@ -80,8 +98,8 @@ class PingConnectionPingPong
}
private:
unique_ptr<mtproto::AuthData> auth_data_;
unique_ptr<mtproto::SessionConnection> connection_;
unique_ptr<AuthData> auth_data_;
unique_ptr<SessionConnection> connection_;
int pong_cnt_{0};
double rtt_;
bool is_closed_{false};
@ -165,12 +183,15 @@ class PingConnectionPingPong
};
} // namespace detail
unique_ptr<PingConnection> PingConnection::create_req_pq(unique_ptr<RawConnection> raw_connection, size_t ping_count) {
return make_unique<detail::PingConnectionReqPQ>(std::move(raw_connection), ping_count);
}
unique_ptr<PingConnection> PingConnection::create_ping_pong(unique_ptr<RawConnection> raw_connection,
unique_ptr<AuthData> auth_data) {
return make_unique<detail::PingConnectionPingPong>(std::move(raw_connection), std::move(auth_data));
}
} // namespace mtproto
} // namespace td

View File

@ -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 {

View File

@ -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"

View File

@ -2022,7 +2022,6 @@ class CliClient final : public Actor {
} else if (op == "storage") {
auto chat_limit = to_integer<int32>(args);
send_request(td_api::make_object<td_api::getStorageStatistics>(chat_limit));
//quit();
} else if (op == "storage_fast") {
send_request(td_api::make_object<td_api::getStorageStatisticsFast>());
} else if (op == "database") {

View File

@ -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 <algorithm>

View File

@ -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,7 +107,8 @@ 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) {
td::walk_path(files_dir,
[&](CSlice path, WalkPath::Type type) {
if (token) {
return WalkPath::Action::Abort;
}
@ -132,7 +134,8 @@ void scan_fs(CancellationToken &token, CallbackT &&callback) {
info.mtime_nsec = stat.mtime_nsec_;
callback(info);
return WalkPath::Action::Continue;
}).ignore();
})
.ignore();
}
}
} // namespace

View File

@ -36,6 +36,7 @@
#include <map>
#include <memory>
#include <set>
#include <unordered_map>
#include <utility>

View File

@ -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"

View File

@ -15,8 +15,6 @@
#include "td/utils/ScopeGuard.h"
#include "td/utils/Status.h"
#include <atomic>
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>

View File

@ -7,7 +7,10 @@
#pragma once
#include <atomic>
#include <memory>
namespace td {
namespace detail {
struct RawCancellationToken {
std::atomic<bool> is_cancelled_{false};
@ -21,11 +24,6 @@ class CancellationToken {
}
explicit CancellationToken(std::shared_ptr<detail::RawCancellationToken> 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<detail::RawCancellationToken> 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<detail::RawCancellationToken> token_;
};
} // namespace td

View File

@ -12,6 +12,7 @@
#include "td/utils/Status.h"
#include <functional>
#include <type_traits>
#include <utility>
namespace td {

View File

@ -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,28 +35,33 @@ 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) {
walk_path(main_dir,
[&](CSlice name, WalkPath::Type type) {
if (type == WalkPath::Type::NotDir) {
ASSERT_TRUE(name == fd_path || name == fd2_path);
}
cnt++;
}).ensure();
})
.ensure();
}
ASSERT_EQ((5 * 2 + 2) * ITER_COUNT, cnt);
bool was_abort = false;
walk_path(main_dir, [&](CSlice name, WalkPath::Type type) {
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();
})
.ensure();
CHECK(was_abort);
cnt = 0;
bool is_first_dir = true;
walk_path(main_dir, [&](CSlice name, WalkPath::Type type) {
walk_path(main_dir,
[&](CSlice name, WalkPath::Type type) {
cnt++;
if (type == WalkPath::Type::EnterDir) {
if (is_first_dir) {
@ -66,7 +71,8 @@ TEST(Port, files) {
}
}
return WalkPath::Action::Continue;
}).ensure();
})
.ensure();
ASSERT_EQ(6, cnt);
ASSERT_EQ(0u, fd.get_size());

View File

@ -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);

View File

@ -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"