diff --git a/td/telegram/AuthManager.cpp b/td/telegram/AuthManager.cpp index 5a8206a77..24702f2f6 100644 --- a/td/telegram/AuthManager.cpp +++ b/td/telegram/AuthManager.cpp @@ -59,6 +59,7 @@ AuthManager::AuthManager(int32 api_id, const string &api_hash, ActorShared<> par ContactsManager::send_get_me_query( td_, PromiseCreator::lambda([this](Result result) { update_state(State::Ok); })); } + G()->net_query_dispatcher().check_authorization_is_ok(); } else if (auth_str == "logout") { LOG(WARNING) << "Continue to log out"; update_state(State::LoggingOut); diff --git a/td/telegram/net/DcAuthManager.cpp b/td/telegram/net/DcAuthManager.cpp index deae91ca1..a61bd5b62 100644 --- a/td/telegram/net/DcAuthManager.cpp +++ b/td/telegram/net/DcAuthManager.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/net/DcAuthManager.h" +#include "td/telegram/ConfigShared.h" #include "td/telegram/Global.h" #include "td/telegram/net/AuthDataShared.h" #include "td/telegram/net/NetQuery.h" @@ -240,4 +241,11 @@ void DcAuthManager::loop() { } } +void DcAuthManager::check_authorization_is_ok() { + auto main_dc = find_dc(main_dc_id_.get_raw_id()); + if (!main_dc || main_dc->auth_key_state != AuthKeyState::OK) { + G()->shared_config().set_option_string("auth", "Authorization check failed in DcAuthManager"); + } +} + } // namespace td diff --git a/td/telegram/net/DcAuthManager.h b/td/telegram/net/DcAuthManager.h index 96473428e..ecefeb694 100644 --- a/td/telegram/net/DcAuthManager.h +++ b/td/telegram/net/DcAuthManager.h @@ -31,6 +31,8 @@ class DcAuthManager final : public NetQueryCallback { void update_main_dc(DcId new_main_dc_id); void destroy(Promise<> promise); + void check_authorization_is_ok(); + private: struct DcInfo { DcId dc_id; diff --git a/td/telegram/net/NetQueryDispatcher.cpp b/td/telegram/net/NetQueryDispatcher.cpp index e9be4cd50..686dbee01 100644 --- a/td/telegram/net/NetQueryDispatcher.cpp +++ b/td/telegram/net/NetQueryDispatcher.cpp @@ -352,4 +352,8 @@ void NetQueryDispatcher::set_main_dc_id(int32 new_main_dc_id) { G()->td_db()->get_binlog_pmc()->set("main_dc_id", to_string(main_dc_id_.load(std::memory_order_relaxed))); } +void NetQueryDispatcher::check_authorization_is_ok() { + send_closure(dc_auth_manager_, &DcAuthManager::check_authorization_is_ok); +} + } // namespace td diff --git a/td/telegram/net/NetQueryDispatcher.h b/td/telegram/net/NetQueryDispatcher.h index d771009fc..5b1eacc59 100644 --- a/td/telegram/net/NetQueryDispatcher.h +++ b/td/telegram/net/NetQueryDispatcher.h @@ -58,6 +58,7 @@ class NetQueryDispatcher { } void set_main_dc_id(int32 new_main_dc_id); + void check_authorization_is_ok(); private: std::atomic stop_flag_{false};