Remove was_auth flag.

This commit is contained in:
levlam 2021-02-01 15:07:10 +03:00
parent 90b34e7d0c
commit e3cb608293
6 changed files with 14 additions and 28 deletions

View File

@ -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 <class StorerT>
void store(StorerT &storer) const {
storer.store_binary(auth_key_id_);
bool has_created_at = created_at_ != 0;
storer.store_binary(static_cast<int32>((auth_flag_ ? AUTH_FLAG : 0) | (was_auth_flag_ ? WAS_AUTH_FLAG : 0) |
(has_created_at ? HAS_CREATED_AT : 0)));
storer.store_binary(static_cast<int32>((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<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};

View File

@ -434,10 +434,8 @@ ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorSh
}
return res;
}
std::pair<AuthKeyState, bool> 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));

View File

@ -41,12 +41,9 @@ class AuthDataSharedImpl : public AuthDataShared {
}
return res;
}
using AuthDataShared::get_auth_key_state;
std::pair<AuthKeyState, bool> 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());
}
};

View File

@ -51,7 +51,7 @@ class AuthDataShared {
virtual DcId dc_id() const = 0;
virtual const std::shared_ptr<PublicRsaKeyShared> &public_rsa_key() = 0;
virtual mtproto::AuthKey get_auth_key() = 0;
virtual std::pair<AuthKeyState, bool> 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;

View File

@ -63,8 +63,7 @@ void DcAuthManager::add_dc(std::shared_ptr<AuthDataShared> 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<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;
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();
}

View File

@ -102,7 +102,7 @@ void SessionProxy::start_up() {
private:
ActorShared<SessionProxy> 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<Listener>(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();
}