Remove authorization loss logic from DcAuthManager, because we can be logged before entering password and before authorization.

This commit is contained in:
levlam 2021-02-01 14:51:38 +03:00
parent ad0c5e6783
commit 90b34e7d0c
3 changed files with 6 additions and 17 deletions

View File

@ -8,7 +8,6 @@
#include "td/actor/actor.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/AuthDataShared.h"
#include "td/telegram/net/NetQuery.h"
@ -66,9 +65,7 @@ void DcAuthManager::add_dc(std::shared_ptr<AuthDataShared> auth_data) {
info.shared_auth_data = std::move(auth_data);
auto state_was_auth = info.shared_auth_data->get_auth_key_state();
info.auth_key_state = state_was_auth.first;
VLOG(dc) << "Add " << info.dc_id << " with auth key state " << info.auth_key_state
<< " and was_auth = " << state_was_auth.second;
was_auth_ |= state_was_auth.second;
VLOG(dc) << "Add " << info.dc_id << " with auth key state " << info.auth_key_state;
if (!main_dc_id_.is_exact()) {
main_dc_id_ = info.dc_id;
VLOG(dc) << "Set main DcId to " << main_dc_id_;
@ -101,10 +98,8 @@ void DcAuthManager::update_auth_key_state() {
int32 dc_id = narrow_cast<int32>(get_link_token());
auto &dc = get_dc(dc_id);
auto state_was_auth = dc.shared_auth_data->get_auth_key_state();
VLOG(dc) << "Update " << dc_id << " auth key state from " << dc.auth_key_state << " to " << state_was_auth.first
<< " with was_auth = " << state_was_auth.second;
VLOG(dc) << "Update " << dc_id << " auth key state from " << dc.auth_key_state << " to " << state_was_auth.first;
dc.auth_key_state = state_was_auth.first;
was_auth_ |= state_was_auth.second;
loop();
}
@ -239,15 +234,8 @@ void DcAuthManager::loop() {
}
auto main_dc = find_dc(main_dc_id_.get_raw_id());
if (!main_dc || main_dc->auth_key_state != AuthKeyState::OK) {
VLOG(dc) << "Main is " << main_dc_id_ << ", main auth key state is "
<< (main_dc ? main_dc->auth_key_state : AuthKeyState::Empty) << ", was_auth = " << was_auth_;
if (was_auth_) {
G()->shared_config().set_option_boolean("auth", false);
destroy_loop();
}
VLOG(dc) << "Skip loop because auth state of main DcId " << main_dc_id_.get_raw_id() << " is "
<< (main_dc != nullptr ? (PSTRING() << main_dc->auth_key_state) : "unknown");
VLOG(dc) << "Skip loop, because main DC is " << main_dc_id_ << ", main auth key state is "
<< (main_dc != nullptr ? main_dc->auth_key_state : AuthKeyState::Empty);
return;
}
for (auto &dc : dcs_) {

View File

@ -47,7 +47,6 @@ class DcAuthManager : public NetQueryCallback {
ActorShared<> parent_;
std::vector<DcInfo> dcs_;
bool was_auth_{false};
DcId main_dc_id_;
bool close_flag_{false};
Promise<> destroy_promise_;

View File

@ -8,6 +8,7 @@
#include "td/telegram/telegram_api.h"
#include "td/telegram/ConfigShared.h"
#include "td/telegram/DhCache.h"
#include "td/telegram/Global.h"
#include "td/telegram/net/DcAuthManager.h"
@ -778,6 +779,7 @@ void Session::on_message_result_error(uint64 id, int error_code, BufferSlice mes
LOG(WARNING) << "Lost authorization due to " << tag("msg", message.as_slice());
}
auth_data_.set_auth_flag(false);
G()->shared_config().set_option_boolean("auth", false);
shared_auth_data_->set_auth_key(auth_data_.get_main_auth_key());
on_session_failed(Status::OK());
}