diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index eb95f4972..a67d8c09b 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -226,7 +226,8 @@ void NetQueryDispatcher::update_session_count() { bool use_pfs = get_use_pfs(); for (size_t i = 1; i < MAX_DC_COUNT; i++) { if (is_dc_inited(narrow_cast(i))) { - send_closure_later(dcs_[i - 1].main_session_, &SessionMultiProxy::update_options, session_count, use_pfs); + send_closure_later(dcs_[i - 1].main_session_, &SessionMultiProxy::update_options, session_count, use_pfs, + need_destroy_auth_key_); send_closure_later(dcs_[i - 1].upload_session_, &SessionMultiProxy::update_use_pfs, use_pfs); send_closure_later(dcs_[i - 1].download_session_, &SessionMultiProxy::update_use_pfs, use_pfs); send_closure_later(dcs_[i - 1].download_small_session_, &SessionMultiProxy::update_use_pfs, use_pfs); diff --git a/td/telegram/net/SessionMultiProxy.cpp b/td/telegram/net/SessionMultiProxy.cpp index 6fd9a9f75..854884aea 100644 --- a/td/telegram/net/SessionMultiProxy.cpp +++ b/td/telegram/net/SessionMultiProxy.cpp @@ -61,19 +61,23 @@ void SessionMultiProxy::update_main_flag(bool is_main) { } void SessionMultiProxy::destroy_auth_key() { - need_destroy_auth_key_ = true; - send_closure(sessions_[0].proxy, &SessionProxy::destroy_auth_key); + update_options(1, false, true); } void SessionMultiProxy::update_session_count(int32 session_count) { - update_options(session_count, use_pfs_); + update_options(session_count, use_pfs_, need_destroy_auth_key_); } void SessionMultiProxy::update_use_pfs(bool use_pfs) { - update_options(session_count_, use_pfs); + update_options(session_count_, use_pfs, need_destroy_auth_key_); } -void SessionMultiProxy::update_options(int32 session_count, bool use_pfs) { +void SessionMultiProxy::update_options(int32 session_count, bool use_pfs, bool need_destroy_auth_key) { + if (need_destroy_auth_key_) { + LOG(INFO) << "Ignore session option changes while destroying auth key"; + return; + } + bool changed = false; if (session_count != session_count_) { @@ -96,6 +100,12 @@ void SessionMultiProxy::update_options(int32 session_count, bool use_pfs) { changed = true; } } + + if (need_destroy_auth_key) { + need_destroy_auth_key_ = need_destroy_auth_key; + LOG(WARNING) << "Destroy auth key in " << get_name(); + } + if (changed) { init(); } diff --git a/td/telegram/net/SessionMultiProxy.h b/td/telegram/net/SessionMultiProxy.h index 254681c07..8dcf29035 100644 --- a/td/telegram/net/SessionMultiProxy.h +++ b/td/telegram/net/SessionMultiProxy.h @@ -30,7 +30,7 @@ class SessionMultiProxy final : public Actor { void update_session_count(int32 session_count); void update_use_pfs(bool use_pfs); - void update_options(int32 session_count, bool use_pfs); + void update_options(int32 session_count, bool use_pfs, bool need_destroy_auth_key); void update_mtproto_header(); void destroy_auth_key(); diff --git a/td/telegram/net/SessionProxy.cpp b/td/telegram/net/SessionProxy.cpp index 1580360d6..1a7889710 100644 --- a/td/telegram/net/SessionProxy.cpp +++ b/td/telegram/net/SessionProxy.cpp @@ -172,16 +172,6 @@ void SessionProxy::update_main_flag(bool is_main) { open_session(); } -void SessionProxy::destroy_auth_key() { - if (need_destroy_auth_key_) { - LOG(INFO) << "Ignore reduntant destroy_auth_key"; - return; - } - need_destroy_auth_key_ = true; - close_session(); - open_session(); -} - void SessionProxy::on_failed() { if (session_generation_ != get_link_token()) { return; diff --git a/td/telegram/net/SessionProxy.h b/td/telegram/net/SessionProxy.h index e15d93bc0..a30b4ff99 100644 --- a/td/telegram/net/SessionProxy.h +++ b/td/telegram/net/SessionProxy.h @@ -42,8 +42,6 @@ class SessionProxy final : public Actor { void update_mtproto_header(); - void destroy_auth_key(); - private: unique_ptr callback_; std::shared_ptr auth_data_;