Reduce ping timeout in primary non-main-DC connections.

This commit is contained in:
levlam 2023-01-15 00:25:22 +03:00
parent 973df16c88
commit fb935a8de2
8 changed files with 40 additions and 29 deletions

View File

@ -521,8 +521,8 @@ static ActorOwn<> get_full_config(DcOption option, Promise<tl_object_ptr<telegra
int_dc_id += 10000;
}
session_ = create_actor<Session>("ConfigSession", std::move(session_callback), std::move(auth_data), raw_dc_id,
int_dc_id, false /*is_main*/, true /*use_pfs*/, false /*is_cdn*/,
false /*need_destroy_auth_key*/, mtproto::AuthKey(),
int_dc_id, false /*is_primary*/, false /*is_main*/, true /*use_pfs*/,
false /*is_cdn*/, false /*need_destroy_auth_key*/, mtproto::AuthKey(),
std::vector<mtproto::ServerSalt>());
auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), DcId::empty());
query->total_timeout_limit_ = 60 * 60 * 24;

View File

@ -172,17 +172,17 @@ Status NetQueryDispatcher::wait_dc_init(DcId dc_id, bool force) {
int32 download_session_count = is_premium ? 8 : 2;
int32 download_small_session_count = is_premium ? 8 : 2;
dc.main_session_ = create_actor<SessionMultiProxy>(PSLICE() << "SessionMultiProxy:" << raw_dc_id << ":main",
session_count, auth_data, raw_dc_id == main_dc_id_, use_pfs,
false, false, is_cdn, need_destroy_key);
session_count, auth_data, true, raw_dc_id == main_dc_id_,
use_pfs, false, false, is_cdn, need_destroy_key);
dc.upload_session_ = create_actor_on_scheduler<SessionMultiProxy>(
PSLICE() << "SessionMultiProxy:" << raw_dc_id << ":upload", slow_net_scheduler_id, upload_session_count,
auth_data, false, use_pfs, false, true, is_cdn, need_destroy_key);
auth_data, false, false, use_pfs, false, true, is_cdn, need_destroy_key);
dc.download_session_ = create_actor_on_scheduler<SessionMultiProxy>(
PSLICE() << "SessionMultiProxy:" << raw_dc_id << ":download", slow_net_scheduler_id, download_session_count,
auth_data, false, use_pfs, true, true, is_cdn, need_destroy_key);
auth_data, false, false, use_pfs, true, true, is_cdn, need_destroy_key);
dc.download_small_session_ = create_actor_on_scheduler<SessionMultiProxy>(
PSLICE() << "SessionMultiProxy:" << raw_dc_id << ":download_small", slow_net_scheduler_id,
download_small_session_count, auth_data, false, use_pfs, true, true, is_cdn, need_destroy_key);
download_small_session_count, auth_data, false, false, use_pfs, true, true, is_cdn, need_destroy_key);
dc.is_inited_ = true;
if (dc_id.is_internal()) {
send_closure_later(dc_auth_manager_, &DcAuthManager::add_dc, std::move(auth_data));

View File

@ -232,9 +232,14 @@ bool Session::PriorityQueue::empty() const {
}
Session::Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 raw_dc_id,
int32 dc_id, bool is_main, bool use_pfs, bool is_cdn, bool need_destroy,
int32 dc_id, bool is_primary, bool is_main, bool use_pfs, bool is_cdn, bool need_destroy,
const mtproto::AuthKey &tmp_auth_key, const vector<mtproto::ServerSalt> &server_salts)
: raw_dc_id_(raw_dc_id), dc_id_(dc_id), is_main_(is_main), is_cdn_(is_cdn), need_destroy_(need_destroy) {
: raw_dc_id_(raw_dc_id)
, dc_id_(dc_id)
, is_primary_(is_primary)
, is_main_(is_main)
, is_cdn_(is_cdn)
, need_destroy_(need_destroy) {
VLOG(dc) << "Start connection " << tag("need_destroy", need_destroy_);
if (need_destroy_) {
use_pfs = false;
@ -347,18 +352,19 @@ void Session::on_logging_out(bool logging_out_flag) {
}
void Session::connection_online_update(bool force) {
bool new_connection_online_flag = (online_flag_ || logging_out_flag_) &&
(has_queries() || last_activity_timestamp_ + 10 > Time::now_cached() || is_main_);
bool new_connection_online_flag =
(online_flag_ || logging_out_flag_) &&
(has_queries() || last_activity_timestamp_ + 10 > Time::now_cached() || is_primary_);
if (connection_online_flag_ == new_connection_online_flag && !force) {
return;
}
connection_online_flag_ = new_connection_online_flag;
VLOG(dc) << "Set connection_online " << connection_online_flag_;
if (main_connection_.connection_) {
main_connection_.connection_->set_online(connection_online_flag_, is_main_);
main_connection_.connection_->set_online(connection_online_flag_, is_primary_);
}
if (long_poll_connection_.connection_) {
long_poll_connection_.connection_->set_online(connection_online_flag_, is_main_);
long_poll_connection_.connection_->set_online(connection_online_flag_, is_primary_);
}
}
@ -1287,7 +1293,7 @@ void Session::connection_open_finish(ConnectionInfo *info,
if (can_destroy_auth_key()) {
info->connection_->destroy_key();
}
info->connection_->set_online(connection_online_flag_, is_main_);
info->connection_->set_online(connection_online_flag_, is_primary_);
info->connection_->set_name(name);
Scheduler::subscribe(info->connection_->get_poll_info().extract_pollable_fd(this));
info->mode_ = mode_;

View File

@ -67,8 +67,8 @@ class Session final
};
Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 raw_dc_id, int32 dc_id,
bool is_main, bool use_pfs, bool is_cdn, bool need_destroy, const mtproto::AuthKey &tmp_auth_key,
const vector<mtproto::ServerSalt> &server_salts);
bool is_primary, bool is_main, bool use_pfs, bool is_cdn, bool need_destroy,
const mtproto::AuthKey &tmp_auth_key, const vector<mtproto::ServerSalt> &server_salts);
void send(NetQueryPtr &&query);
@ -106,6 +106,7 @@ class Session final
const int32 raw_dc_id_; // numerical datacenter ID, i.e. 2
const int32 dc_id_; // unique datacenter ID, i.e. -10002
const bool is_primary_; // true for primary Sessions to all DCs
const bool is_main_; // true only for the primary Session(s) to the main DC
const bool is_cdn_;
const bool need_destroy_;

View File

@ -18,14 +18,14 @@
namespace td {
SessionMultiProxy::SessionMultiProxy() = default;
SessionMultiProxy::~SessionMultiProxy() = default;
SessionMultiProxy::SessionMultiProxy(int32 session_count, std::shared_ptr<AuthDataShared> shared_auth_data,
bool is_main, bool use_pfs, bool allow_media_only, bool is_media, bool is_cdn,
bool need_destroy_auth_key)
bool is_primary, bool is_main, bool use_pfs, bool allow_media_only, bool is_media,
bool is_cdn, bool need_destroy_auth_key)
: session_count_(session_count)
, auth_data_(std::move(shared_auth_data))
, is_primary_(is_primary)
, is_main_(is_main)
, use_pfs_(use_pfs)
, allow_media_only_(allow_media_only)
@ -142,8 +142,8 @@ void SessionMultiProxy::init() {
int32 session_id_;
};
info.proxy = create_actor<SessionProxy>(name, make_unique<Callback>(actor_id(this), sessions_generation_, i),
auth_data_, is_main_, allow_media_only_, is_media_, get_pfs_flag(), is_cdn_,
need_destroy_auth_key_ && i == 0);
auth_data_, is_primary_, is_main_, allow_media_only_, is_media_,
get_pfs_flag(), is_cdn_, need_destroy_auth_key_ && i == 0);
sessions_.push_back(std::move(info));
}
}

View File

@ -19,12 +19,12 @@ class SessionProxy;
class SessionMultiProxy final : public Actor {
public:
SessionMultiProxy();
SessionMultiProxy(int32 session_count, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_primary,
bool is_main, bool use_pfs, bool allow_media_only, bool is_media, bool is_cdn,
bool need_destroy_auth_key);
SessionMultiProxy(const SessionMultiProxy &other) = delete;
SessionMultiProxy &operator=(const SessionMultiProxy &other) = delete;
~SessionMultiProxy() final;
SessionMultiProxy(int32 session_count, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_main, bool use_pfs,
bool allow_media_only, bool is_media, bool is_cdn, bool need_destroy_auth_key);
void send(NetQueryPtr query);
void update_main_flag(bool is_main);
@ -39,6 +39,7 @@ class SessionMultiProxy final : public Actor {
private:
int32 session_count_ = 0;
std::shared_ptr<AuthDataShared> auth_data_;
const bool is_primary_;
bool is_main_ = false;
bool use_pfs_ = false;
bool allow_media_only_ = false;

View File

@ -78,10 +78,11 @@ class SessionCallback final : public Session::Callback {
};
SessionProxy::SessionProxy(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data,
bool is_main, bool allow_media_only, bool is_media, bool use_pfs, bool is_cdn,
bool need_destroy)
bool is_primary, bool is_main, bool allow_media_only, bool is_media, bool use_pfs,
bool is_cdn, bool need_destroy)
: callback_(std::move(callback))
, auth_data_(std::move(shared_auth_data))
, is_primary_(is_primary)
, is_main_(is_main)
, allow_media_only_(allow_media_only)
, is_media_(is_media)
@ -212,7 +213,8 @@ void SessionProxy::open_session(bool force) {
session_ = create_actor<Session>(
name,
make_unique<SessionCallback>(actor_shared(this, session_generation_), dc_id, allow_media_only_, is_media_, hash),
auth_data_, raw_dc_id, int_dc_id, is_main_, use_pfs_, is_cdn_, need_destroy_, tmp_auth_key_, server_salts_);
auth_data_, raw_dc_id, int_dc_id, is_primary_, is_main_, use_pfs_, is_cdn_, need_destroy_, tmp_auth_key_,
server_salts_);
}
void SessionProxy::update_auth_key_state() {

View File

@ -29,8 +29,8 @@ class SessionProxy final : public Actor {
virtual void on_query_finished() = 0;
};
SessionProxy(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_main,
bool allow_media_only, bool is_media, bool use_pfs, bool is_cdn, bool need_destroy);
SessionProxy(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, bool is_primary,
bool is_main, bool allow_media_only, bool is_media, bool use_pfs, bool is_cdn, bool need_destroy);
void send(NetQueryPtr query);
void update_main_flag(bool is_main);
@ -41,6 +41,7 @@ class SessionProxy final : public Actor {
unique_ptr<Callback> callback_;
std::shared_ptr<AuthDataShared> auth_data_;
AuthKeyState auth_key_state_ = AuthKeyState::Empty;
const bool is_primary_;
bool is_main_;
bool allow_media_only_;
bool is_media_;