diff --git a/td/mtproto/AuthKey.h b/td/mtproto/AuthKey.h index 5c3959605..20eb414e2 100644 --- a/td/mtproto/AuthKey.h +++ b/td/mtproto/AuthKey.h @@ -34,11 +34,7 @@ class AuthKey { bool auth_flag() const { return auth_flag_; } - bool was_auth_flag() const { - return was_auth_flag_; - } void set_auth_flag(bool new_auth_flag) { - was_auth_flag_ |= new_auth_flag; auth_flag_ = new_auth_flag; } @@ -67,15 +63,13 @@ class AuthKey { } static constexpr int32 AUTH_FLAG = 1; - static constexpr int32 WAS_AUTH_FLAG = 2; static constexpr int32 HAS_CREATED_AT = 4; template void store(StorerT &storer) const { storer.store_binary(auth_key_id_); bool has_created_at = created_at_ != 0; - storer.store_binary(static_cast((auth_flag_ ? AUTH_FLAG : 0) | (was_auth_flag_ ? WAS_AUTH_FLAG : 0) | - (has_created_at ? HAS_CREATED_AT : 0))); + storer.store_binary(static_cast((auth_flag_ ? AUTH_FLAG : 0) | (has_created_at ? HAS_CREATED_AT : 0))); storer.store_string(auth_key_); if (has_created_at) { storer.store_binary(created_at_); @@ -87,7 +81,6 @@ class AuthKey { auth_key_id_ = parser.fetch_long(); auto flags = parser.fetch_int(); auth_flag_ = (flags & AUTH_FLAG) != 0; - was_auth_flag_ = (flags & WAS_AUTH_FLAG) != 0 || auth_flag_; auth_key_ = parser.template fetch_string(); if ((flags & HAS_CREATED_AT) != 0) { created_at_ = parser.fetch_double(); @@ -100,7 +93,6 @@ class AuthKey { uint64 auth_key_id_{0}; string auth_key_; bool auth_flag_{false}; - bool was_auth_flag_{false}; bool need_header_{true}; double expires_at_{0}; double created_at_{0}; diff --git a/td/telegram/ConfigManager.cpp b/td/telegram/ConfigManager.cpp index c5be27e4c..6dcc93712 100644 --- a/td/telegram/ConfigManager.cpp +++ b/td/telegram/ConfigManager.cpp @@ -434,10 +434,8 @@ ActorOwn<> get_full_config(DcOption option, Promise promise, ActorSh } return res; } - std::pair get_auth_key_state() override { - auto auth_key = get_auth_key(); - AuthKeyState state = AuthDataShared::get_auth_key_state(auth_key); - return std::make_pair(state, auth_key.was_auth_flag()); + AuthKeyState get_auth_key_state() override { + return AuthDataShared::get_auth_key_state(get_auth_key()); } void set_auth_key(const mtproto::AuthKey &auth_key) override { G()->td_db()->get_binlog_pmc()->set(auth_key_key(), serialize(auth_key)); diff --git a/td/telegram/net/AuthDataShared.cpp b/td/telegram/net/AuthDataShared.cpp index 35f545ed2..aaf628cae 100644 --- a/td/telegram/net/AuthDataShared.cpp +++ b/td/telegram/net/AuthDataShared.cpp @@ -41,12 +41,9 @@ class AuthDataSharedImpl : public AuthDataShared { } return res; } - using AuthDataShared::get_auth_key_state; - std::pair get_auth_key_state() override { - // TODO (perf): - auto auth_key = get_auth_key(); - AuthKeyState state = get_auth_key_state(auth_key); - return std::make_pair(state, auth_key.was_auth_flag()); + + AuthKeyState get_auth_key_state() override { + return AuthDataShared::get_auth_key_state(get_auth_key()); } void set_auth_key(const mtproto::AuthKey &auth_key) override { @@ -106,7 +103,8 @@ class AuthDataSharedImpl : public AuthDataShared { } void log_auth_key(const mtproto::AuthKey &auth_key) { - LOG(WARNING) << dc_id_ << " " << tag("auth_key_id", auth_key.id()) << tag("state", get_auth_key_state(auth_key)) + LOG(WARNING) << dc_id_ << " " << tag("auth_key_id", auth_key.id()) + << tag("state", AuthDataShared::get_auth_key_state(auth_key)) << tag("created_at", auth_key.created_at()); } }; diff --git a/td/telegram/net/AuthDataShared.h b/td/telegram/net/AuthDataShared.h index 9266f4ead..1fdb2d42e 100644 --- a/td/telegram/net/AuthDataShared.h +++ b/td/telegram/net/AuthDataShared.h @@ -51,7 +51,7 @@ class AuthDataShared { virtual DcId dc_id() const = 0; virtual const std::shared_ptr &public_rsa_key() = 0; virtual mtproto::AuthKey get_auth_key() = 0; - virtual std::pair get_auth_key_state() = 0; + virtual AuthKeyState get_auth_key_state() = 0; virtual void set_auth_key(const mtproto::AuthKey &auth_key) = 0; virtual void update_server_time_difference(double diff) = 0; virtual double get_server_time_difference() = 0; diff --git a/td/telegram/net/DcAuthManager.cpp b/td/telegram/net/DcAuthManager.cpp index 41e3f3291..4cdb0d9ac 100644 --- a/td/telegram/net/DcAuthManager.cpp +++ b/td/telegram/net/DcAuthManager.cpp @@ -63,8 +63,7 @@ void DcAuthManager::add_dc(std::shared_ptr auth_data) { info.dc_id = auth_data->dc_id(); CHECK(info.dc_id.is_exact()); 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; + info.auth_key_state = info.shared_auth_data->get_auth_key_state(); 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; @@ -97,9 +96,8 @@ DcAuthManager::DcInfo *DcAuthManager::find_dc(int32 dc_id) { void DcAuthManager::update_auth_key_state() { int32 dc_id = narrow_cast(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; - dc.auth_key_state = state_was_auth.first; + dc.auth_key_state = dc.shared_auth_data->get_auth_key_state(); + VLOG(dc) << "Update " << dc_id << " auth key state from " << dc.auth_key_state << " to " << dc.auth_key_state; loop(); } diff --git a/td/telegram/net/SessionProxy.cpp b/td/telegram/net/SessionProxy.cpp index 2be3e9e46..44baab333 100644 --- a/td/telegram/net/SessionProxy.cpp +++ b/td/telegram/net/SessionProxy.cpp @@ -102,7 +102,7 @@ void SessionProxy::start_up() { private: ActorShared session_proxy_; }; - auth_key_state_ = auth_data_->get_auth_key_state().first; + auth_key_state_ = auth_data_->get_auth_key_state(); auth_data_->add_auth_key_listener(make_unique(actor_shared(this))); open_session(); } @@ -212,7 +212,7 @@ void SessionProxy::open_session(bool force) { void SessionProxy::update_auth_key_state() { auto old_auth_key_state = auth_key_state_; - auth_key_state_ = auth_data_->get_auth_key_state().first; + auth_key_state_ = auth_data_->get_auth_key_state(); if (auth_key_state_ != old_auth_key_state && old_auth_key_state == AuthKeyState::OK) { close_session(); }