Reduce refresh margin for persistent temp auth keys to speed up recover when the old key reregisters after auth.dropTempAuthKeys.

This commit is contained in:
levlam 2023-07-17 19:21:18 +03:00
parent 9aed145fa1
commit 723d09ddee
5 changed files with 15 additions and 12 deletions

View File

@ -89,14 +89,14 @@ class AuthData {
bool was_tmp_auth_key() const { bool was_tmp_auth_key() const {
return use_pfs() && !tmp_auth_key_.empty(); return use_pfs() && !tmp_auth_key_.empty();
} }
bool need_tmp_auth_key(double now) const { bool need_tmp_auth_key(double now, double refresh_margin) const {
if (!use_pfs()) { if (!use_pfs()) {
return false; return false;
} }
if (tmp_auth_key_.empty()) { if (tmp_auth_key_.empty()) {
return true; return true;
} }
if (now > tmp_auth_key_.expires_at() - 60 * 60 * 2 /*2 hours*/) { if (now > tmp_auth_key_.expires_at() - refresh_margin) {
return true; return true;
} }
return false; return false;

View File

@ -523,10 +523,10 @@ static ActorOwn<> get_full_config(DcOption option, Promise<tl_object_ptr<telegra
if (G()->is_test_dc()) { if (G()->is_test_dc()) {
int_dc_id += 10000; int_dc_id += 10000;
} }
session_ = create_actor<Session>("ConfigSession", std::move(session_callback), std::move(auth_data), raw_dc_id, session_ = create_actor<Session>(
int_dc_id, false /*is_primary*/, false /*is_main*/, true /*use_pfs*/, "ConfigSession", std::move(session_callback), std::move(auth_data), raw_dc_id, int_dc_id,
false /*is_cdn*/, false /*need_destroy_auth_key*/, mtproto::AuthKey(), false /*is_primary*/, false /*is_main*/, true /*use_pfs*/, false /*persist_tmp_auth_key*/, false /*is_cdn*/,
std::vector<mtproto::ServerSalt>()); 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()); auto query = G()->net_query_creator().create_unauth(telegram_api::help_getConfig(), DcId::empty());
query->total_timeout_limit_ = 60 * 60 * 24; query->total_timeout_limit_ = 60 * 60 * 24;
query->set_callback(actor_shared(this)); query->set_callback(actor_shared(this));

View File

@ -232,12 +232,14 @@ bool Session::PriorityQueue::empty() const {
} }
Session::Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 raw_dc_id, Session::Session(unique_ptr<Callback> callback, std::shared_ptr<AuthDataShared> shared_auth_data, int32 raw_dc_id,
int32 dc_id, bool is_primary, 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 persist_tmp_auth_key, bool is_cdn,
const mtproto::AuthKey &tmp_auth_key, const vector<mtproto::ServerSalt> &server_salts) bool need_destroy, const mtproto::AuthKey &tmp_auth_key,
const vector<mtproto::ServerSalt> &server_salts)
: raw_dc_id_(raw_dc_id) : raw_dc_id_(raw_dc_id)
, dc_id_(dc_id) , dc_id_(dc_id)
, is_primary_(is_primary) , is_primary_(is_primary)
, is_main_(is_main) , is_main_(is_main)
, persist_tmp_auth_key_(use_pfs && persist_tmp_auth_key)
, is_cdn_(is_cdn) , is_cdn_(is_cdn)
, need_destroy_(need_destroy) { , need_destroy_(need_destroy) {
VLOG(dc) << "Start connection " << tag("need_destroy", need_destroy_); VLOG(dc) << "Start connection " << tag("need_destroy", need_destroy_);
@ -1504,7 +1506,7 @@ void Session::auth_loop(double now) {
if (auth_data_.need_main_auth_key()) { if (auth_data_.need_main_auth_key()) {
create_gen_auth_key_actor(MainAuthKeyHandshake); create_gen_auth_key_actor(MainAuthKeyHandshake);
} }
if (auth_data_.need_tmp_auth_key(now)) { if (auth_data_.need_tmp_auth_key(now, persist_tmp_auth_key_ ? 2 * 60 : 60 * 60)) {
create_gen_auth_key_actor(TmpAuthKeyHandshake); create_gen_auth_key_actor(TmpAuthKeyHandshake);
} }
} }

View File

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

View File

@ -236,8 +236,8 @@ void SessionProxy::open_session(bool force) {
session_ = create_actor<Session>( session_ = create_actor<Session>(
name, name,
make_unique<SessionCallback>(actor_shared(this, session_generation_), dc_id, allow_media_only_, is_media_, hash), 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_primary_, is_main_, use_pfs_, is_cdn_, need_destroy_, tmp_auth_key_, auth_data_, raw_dc_id, int_dc_id, is_primary_, is_main_, use_pfs_, persist_tmp_auth_key_, is_cdn_, need_destroy_,
server_salts_); tmp_auth_key_, server_salts_);
} }
void SessionProxy::update_auth_key_state() { void SessionProxy::update_auth_key_state() {