Use Ping with mtproto_api::ping if possible
GitOrigin-RevId: fa80dc2a2c44e416bcb50b76ba2bc64de91f8de8
This commit is contained in:
parent
be006f6cb4
commit
ef4f719563
@ -49,7 +49,7 @@ class MessageIdDuplicateChecker {
|
||||
class AuthData {
|
||||
public:
|
||||
AuthData();
|
||||
AuthData(const AuthData &) = delete;
|
||||
AuthData(const AuthData &) = default;
|
||||
AuthData &operator=(const AuthData &) = delete;
|
||||
AuthData(AuthData &&) = delete;
|
||||
AuthData &operator=(AuthData &&) = delete;
|
||||
|
@ -74,6 +74,8 @@ class PingConnectionPingPong
|
||||
public:
|
||||
PingConnectionPingPong(unique_ptr<mtproto::RawConnection> raw_connection, unique_ptr<mtproto::AuthData> auth_data)
|
||||
: auth_data_(std::move(auth_data)) {
|
||||
auth_data_->set_header("");
|
||||
auth_data_->set_session_id(static_cast<uint64>(Random::secure_int64()));
|
||||
connection_ =
|
||||
make_unique<SessionConnection>(SessionConnection::Mode::Tcp, std::move(raw_connection), auth_data_.get());
|
||||
}
|
||||
|
@ -207,7 +207,8 @@ ActorOwn<> get_full_config(DcId dc_id, IPAddress ip_address, Promise<FullConfig>
|
||||
}
|
||||
void on_closed() final {
|
||||
}
|
||||
void request_raw_connection(Promise<unique_ptr<mtproto::RawConnection>> promise) final {
|
||||
void request_raw_connection(unique_ptr<mtproto::AuthData> auth_data,
|
||||
Promise<unique_ptr<mtproto::RawConnection>> promise) final {
|
||||
request_raw_connection_cnt_++;
|
||||
VLOG(config_recoverer) << "Request full config from " << address_ << ", try = " << request_raw_connection_cnt_;
|
||||
if (request_raw_connection_cnt_ <= 2) {
|
||||
|
@ -739,13 +739,13 @@ void ConnectionCreator::request_raw_connection(DcId dc_id, bool allow_media_only
|
||||
client.dc_id = dc_id;
|
||||
client.allow_media_only = allow_media_only;
|
||||
client.is_media = is_media;
|
||||
client.auth_data = std::move(auth_data);
|
||||
} else {
|
||||
CHECK(client.hash == hash);
|
||||
CHECK(client.dc_id == dc_id);
|
||||
CHECK(client.allow_media_only == allow_media_only);
|
||||
CHECK(client.is_media == is_media);
|
||||
}
|
||||
client.auth_data = std::move(auth_data);
|
||||
VLOG(connections) << "Request connection for " << tag("client", format::as_hex(client.hash)) << " to " << dc_id << " "
|
||||
<< tag("allow_media_only", allow_media_only);
|
||||
client.queries.push_back(std::move(promise));
|
||||
@ -1014,6 +1014,8 @@ void ConnectionCreator::client_create_raw_connection(Result<ConnectionData> r_co
|
||||
auto promise = PromiseCreator::lambda([actor_id = actor_id(this), hash, check_mode,
|
||||
debug_str](Result<unique_ptr<mtproto::RawConnection>> result) mutable {
|
||||
if (result.is_ok()) {
|
||||
//FIXME
|
||||
LOG(ERROR) << "RTT: " << result.ok()->rtt_;
|
||||
VLOG(connections) << "Ready connection (" << (check_mode ? "" : "un") << "checked) " << result.ok().get() << ' '
|
||||
<< debug_str;
|
||||
} else {
|
||||
@ -1038,8 +1040,26 @@ void ConnectionCreator::client_create_raw_connection(Result<ConnectionData> r_co
|
||||
if (check_mode) {
|
||||
VLOG(connections) << "Start check: " << debug_str;
|
||||
auto token = next_token();
|
||||
children_[token] = {true, create_ping_actor(debug_str, std::move(raw_connection), nullptr, std::move(promise),
|
||||
create_reference(token))};
|
||||
auto it = clients_.find(hash);
|
||||
CHECK(it != clients_.end());
|
||||
const auto &auth_data_ptr = it->second.auth_data;
|
||||
unique_ptr<mtproto::AuthData> auth_data;
|
||||
if (auth_data_ptr && auth_data_ptr->use_pfs() && auth_data_ptr->has_auth_key(Time::now_cached())) {
|
||||
auth_data = make_unique<mtproto::AuthData>(*auth_data_ptr);
|
||||
// FIXME
|
||||
LOG(ERROR) << "use auth_data";
|
||||
} else {
|
||||
if (auth_data_ptr) {
|
||||
// FIXME
|
||||
LOG(ERROR) << "do not use auth data " << !!auth_data_ptr << " " << auth_data_ptr->use_pfs() << " "
|
||||
<< auth_data_ptr->has_auth_key(Time::now_cached());
|
||||
} else {
|
||||
// FIXME
|
||||
LOG(ERROR) << "do not use auth data";
|
||||
}
|
||||
}
|
||||
children_[token] = {true, create_ping_actor(debug_str, std::move(raw_connection), std::move(auth_data),
|
||||
std::move(promise), create_reference(token))};
|
||||
} else {
|
||||
promise.set_value(std::move(raw_connection));
|
||||
}
|
||||
|
@ -79,11 +79,12 @@ class GenAuthKeyActor : public Actor {
|
||||
// Bug in Android clang and MSVC
|
||||
// std::tuple<Result<int>> b(std::forward_as_tuple(Result<int>()));
|
||||
|
||||
callback_->request_raw_connection(PromiseCreator::cancellable_lambda(
|
||||
cancellation_token_source_.get_cancellation_token(),
|
||||
[actor_id = actor_id(this)](Result<unique_ptr<mtproto::RawConnection>> r_raw_connection) {
|
||||
send_closure(actor_id, &GenAuthKeyActor::on_connection, std::move(r_raw_connection), false);
|
||||
}));
|
||||
callback_->request_raw_connection(
|
||||
nullptr, PromiseCreator::cancellable_lambda(
|
||||
cancellation_token_source_.get_cancellation_token(),
|
||||
[actor_id = actor_id(this)](Result<unique_ptr<mtproto::RawConnection>> r_raw_connection) {
|
||||
send_closure(actor_id, &GenAuthKeyActor::on_connection, std::move(r_raw_connection), false);
|
||||
}));
|
||||
}
|
||||
|
||||
void hangup() override {
|
||||
@ -892,7 +893,11 @@ void Session::connection_open(ConnectionInfo *info, bool ask_info) {
|
||||
promise.set_value(std::move(cached_connection_));
|
||||
} else {
|
||||
VLOG(dc) << "Request new connection";
|
||||
callback_->request_raw_connection(std::move(promise));
|
||||
unique_ptr<mtproto::AuthData> auth_data;
|
||||
if (auth_data_.use_pfs() && auth_data_.has_auth_key(Time::now())) {
|
||||
auth_data = make_unique<mtproto::AuthData>(auth_data_);
|
||||
}
|
||||
callback_->request_raw_connection(std::move(auth_data), std::move(promise));
|
||||
}
|
||||
|
||||
info->wakeup_at = Time::now_cached() + 1000;
|
||||
|
@ -55,7 +55,8 @@ class Session final
|
||||
virtual ~Callback() = default;
|
||||
virtual void on_failed() = 0;
|
||||
virtual void on_closed() = 0;
|
||||
virtual void request_raw_connection(Promise<unique_ptr<mtproto::RawConnection>>) = 0;
|
||||
virtual void request_raw_connection(unique_ptr<mtproto::AuthData> auth_data,
|
||||
Promise<unique_ptr<mtproto::RawConnection>>) = 0;
|
||||
virtual void on_tmp_auth_key_updated(mtproto::AuthKey auth_key) = 0;
|
||||
virtual void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts) {
|
||||
}
|
||||
|
@ -43,9 +43,10 @@ class SessionCallback : public Session::Callback {
|
||||
void on_closed() override {
|
||||
send_closure(parent_, &SessionProxy::on_closed);
|
||||
}
|
||||
void request_raw_connection(Promise<unique_ptr<mtproto::RawConnection>> promise) override {
|
||||
void request_raw_connection(unique_ptr<mtproto::AuthData> auth_data,
|
||||
Promise<unique_ptr<mtproto::RawConnection>> promise) override {
|
||||
send_closure(G()->connection_creator(), &ConnectionCreator::request_raw_connection, dc_id_, allow_media_only_,
|
||||
is_media_, std::move(promise), hash_, nullptr);
|
||||
is_media_, std::move(promise), hash_, std::move(auth_data));
|
||||
}
|
||||
|
||||
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key) override {
|
||||
|
Loading…
Reference in New Issue
Block a user