Rename AuthState to AuthKeyState.
GitOrigin-RevId: 7211994ddf6e267342ba29010328387093549e5c
This commit is contained in:
parent
98b8929932
commit
2b7511d07f
@ -9,6 +9,7 @@
|
|||||||
#include "td/telegram/ConfigShared.h"
|
#include "td/telegram/ConfigShared.h"
|
||||||
#include "td/telegram/Global.h"
|
#include "td/telegram/Global.h"
|
||||||
#include "td/telegram/logevent/LogEvent.h"
|
#include "td/telegram/logevent/LogEvent.h"
|
||||||
|
#include "td/telegram/net/AuthDataShared.h"
|
||||||
#include "td/telegram/net/ConnectionCreator.h"
|
#include "td/telegram/net/ConnectionCreator.h"
|
||||||
#include "td/telegram/net/DcId.h"
|
#include "td/telegram/net/DcId.h"
|
||||||
#include "td/telegram/net/DcOptions.h"
|
#include "td/telegram/net/DcOptions.h"
|
||||||
@ -344,9 +345,9 @@ ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise) {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
std::pair<AuthState, bool> get_auth_state() override {
|
std::pair<AuthKeyState, bool> get_auth_key_state() override {
|
||||||
auto auth_key = get_auth_key();
|
auto auth_key = get_auth_key();
|
||||||
AuthState state = AuthDataShared::get_auth_state(auth_key);
|
AuthKeyState state = AuthDataShared::get_auth_key_state(auth_key);
|
||||||
return std::make_pair(state, auth_key.was_auth_flag());
|
return std::make_pair(state, auth_key.was_auth_flag());
|
||||||
}
|
}
|
||||||
void set_auth_key(const mtproto::AuthKey &auth_key) override {
|
void set_auth_key(const mtproto::AuthKey &auth_key) override {
|
||||||
|
@ -42,11 +42,11 @@ class AuthDataSharedImpl : public AuthDataShared {
|
|||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
using AuthDataShared::get_auth_state;
|
using AuthDataShared::get_auth_key_state;
|
||||||
std::pair<AuthState, bool> get_auth_state() override {
|
std::pair<AuthKeyState, bool> get_auth_key_state() override {
|
||||||
// TODO (perf):
|
// TODO (perf):
|
||||||
auto auth_key = get_auth_key();
|
auto auth_key = get_auth_key();
|
||||||
AuthState state = get_auth_state(auth_key);
|
AuthKeyState state = get_auth_key_state(auth_key);
|
||||||
return std::make_pair(state, auth_key.was_auth_flag());
|
return std::make_pair(state, auth_key.was_auth_flag());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ class AuthDataSharedImpl : public AuthDataShared {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void log_auth_key(const mtproto::AuthKey &auth_key) {
|
void log_auth_key(const mtproto::AuthKey &auth_key) {
|
||||||
LOG(WARNING) << dc_id_ << " " << tag("auth_key_id", auth_key.id()) << tag("state", get_auth_state(auth_key));
|
LOG(WARNING) << dc_id_ << " " << tag("auth_key_id", auth_key.id()) << tag("state", get_auth_key_state(auth_key));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -21,18 +21,18 @@
|
|||||||
|
|
||||||
namespace td {
|
namespace td {
|
||||||
|
|
||||||
enum class AuthState : int32 { Empty, KeyNoAuth, OK };
|
enum class AuthKeyState : int32 { Empty, NoAuth, OK };
|
||||||
|
|
||||||
inline StringBuilder &operator<<(StringBuilder &sb, AuthState state) {
|
inline StringBuilder &operator<<(StringBuilder &sb, AuthKeyState state) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case AuthState::Empty:
|
case AuthKeyState::Empty:
|
||||||
return sb << "Empty";
|
return sb << "Empty";
|
||||||
case AuthState::KeyNoAuth:
|
case AuthKeyState::NoAuth:
|
||||||
return sb << "KeyNoAuth";
|
return sb << "NoAuth";
|
||||||
case AuthState::OK:
|
case AuthKeyState::OK:
|
||||||
return sb << "OK";
|
return sb << "OK";
|
||||||
default:
|
default:
|
||||||
return sb << "Unknown AuthState";
|
return sb << "Unknown AuthKeyState";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class AuthDataShared {
|
|||||||
virtual DcId dc_id() const = 0;
|
virtual DcId dc_id() const = 0;
|
||||||
virtual const std::shared_ptr<PublicRsaKeyShared> &public_rsa_key() = 0;
|
virtual const std::shared_ptr<PublicRsaKeyShared> &public_rsa_key() = 0;
|
||||||
virtual mtproto::AuthKey get_auth_key() = 0;
|
virtual mtproto::AuthKey get_auth_key() = 0;
|
||||||
virtual std::pair<AuthState, bool> get_auth_state() = 0;
|
virtual std::pair<AuthKeyState, bool> get_auth_key_state() = 0;
|
||||||
virtual void set_auth_key(const mtproto::AuthKey &auth_key) = 0;
|
virtual void set_auth_key(const mtproto::AuthKey &auth_key) = 0;
|
||||||
virtual void update_server_time_difference(double diff) = 0;
|
virtual void update_server_time_difference(double diff) = 0;
|
||||||
virtual double get_server_time_difference() = 0;
|
virtual double get_server_time_difference() = 0;
|
||||||
@ -60,16 +60,14 @@ class AuthDataShared {
|
|||||||
virtual void set_future_salts(const std::vector<mtproto::ServerSalt> &future_salts) = 0;
|
virtual void set_future_salts(const std::vector<mtproto::ServerSalt> &future_salts) = 0;
|
||||||
virtual std::vector<mtproto::ServerSalt> get_future_salts() = 0;
|
virtual std::vector<mtproto::ServerSalt> get_future_salts() = 0;
|
||||||
|
|
||||||
static AuthState get_auth_state(const mtproto::AuthKey &auth_key) {
|
static AuthKeyState get_auth_key_state(const mtproto::AuthKey &auth_key) {
|
||||||
AuthState state;
|
|
||||||
if (auth_key.empty()) {
|
if (auth_key.empty()) {
|
||||||
state = AuthState::Empty;
|
return AuthKeyState::Empty;
|
||||||
} else if (auth_key.auth_flag()) {
|
} else if (auth_key.auth_flag()) {
|
||||||
state = AuthState::OK;
|
return AuthKeyState::OK;
|
||||||
} else {
|
} else {
|
||||||
state = AuthState::KeyNoAuth;
|
return AuthKeyState::NoAuth;
|
||||||
}
|
}
|
||||||
return state;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<AuthDataShared> create(DcId dc_id, std::shared_ptr<PublicRsaKeyShared> public_rsa_key,
|
static std::shared_ptr<AuthDataShared> create(DcId dc_id, std::shared_ptr<PublicRsaKeyShared> public_rsa_key,
|
||||||
|
@ -50,7 +50,7 @@ void DcAuthManager::add_dc(std::shared_ptr<AuthDataShared> auth_data) {
|
|||||||
if (!dc_manager_.is_alive()) {
|
if (!dc_manager_.is_alive()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
send_closure(dc_manager_, &DcAuthManager::update_auth_state);
|
send_closure(dc_manager_, &DcAuthManager::update_auth_key_state);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ void DcAuthManager::add_dc(std::shared_ptr<AuthDataShared> auth_data) {
|
|||||||
info.dc_id = auth_data->dc_id();
|
info.dc_id = auth_data->dc_id();
|
||||||
CHECK(info.dc_id.is_exact());
|
CHECK(info.dc_id.is_exact());
|
||||||
info.shared_auth_data = std::move(auth_data);
|
info.shared_auth_data = std::move(auth_data);
|
||||||
auto state_was_auth = info.shared_auth_data->get_auth_state();
|
auto state_was_auth = info.shared_auth_data->get_auth_key_state();
|
||||||
info.auth_state = state_was_auth.first;
|
info.auth_key_state = state_was_auth.first;
|
||||||
was_auth_ |= state_was_auth.second;
|
was_auth_ |= state_was_auth.second;
|
||||||
if (!main_dc_id_.is_exact()) {
|
if (!main_dc_id_.is_exact()) {
|
||||||
main_dc_id_ = info.dc_id;
|
main_dc_id_ = info.dc_id;
|
||||||
@ -91,13 +91,13 @@ DcAuthManager::DcInfo *DcAuthManager::find_dc(int32 dc_id) {
|
|||||||
return &*it;
|
return &*it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DcAuthManager::update_auth_state() {
|
void DcAuthManager::update_auth_key_state() {
|
||||||
int32 dc_id = narrow_cast<int32>(get_link_token());
|
int32 dc_id = narrow_cast<int32>(get_link_token());
|
||||||
auto &dc = get_dc(dc_id);
|
auto &dc = get_dc(dc_id);
|
||||||
auto state_was_auth = dc.shared_auth_data->get_auth_state();
|
auto state_was_auth = dc.shared_auth_data->get_auth_key_state();
|
||||||
VLOG(dc) << "Update dc auth state " << tag("dc_id", dc_id) << tag("old_auth_state", dc.auth_state)
|
VLOG(dc) << "Update DC auth key state " << tag("dc_id", dc_id) << tag("old_auth_key_state", dc.auth_key_state)
|
||||||
<< tag("new_auth_state", state_was_auth.first);
|
<< tag("new_auth_key_state", state_was_auth.first);
|
||||||
dc.auth_state = state_was_auth.first;
|
dc.auth_key_state = state_was_auth.first;
|
||||||
was_auth_ |= state_was_auth.second;
|
was_auth_ |= state_was_auth.second;
|
||||||
|
|
||||||
loop();
|
loop();
|
||||||
@ -149,8 +149,8 @@ void DcAuthManager::on_result(NetQueryPtr result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DcAuthManager::dc_loop(DcInfo &dc) {
|
void DcAuthManager::dc_loop(DcInfo &dc) {
|
||||||
VLOG(dc) << "In dc_loop: " << dc.dc_id << " " << dc.auth_state;
|
VLOG(dc) << "In dc_loop: " << dc.dc_id << " " << dc.auth_key_state;
|
||||||
if (dc.auth_state == AuthState::OK) {
|
if (dc.auth_key_state == AuthKeyState::OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CHECK(dc.shared_auth_data);
|
CHECK(dc.shared_auth_data);
|
||||||
@ -209,7 +209,7 @@ void DcAuthManager::destroy_loop() {
|
|||||||
}
|
}
|
||||||
bool is_ready{true};
|
bool is_ready{true};
|
||||||
for (auto &dc : dcs_) {
|
for (auto &dc : dcs_) {
|
||||||
is_ready &= dc.auth_state == AuthState::Empty;
|
is_ready &= dc.auth_key_state == AuthKeyState::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_ready) {
|
if (is_ready) {
|
||||||
@ -231,13 +231,13 @@ void DcAuthManager::loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto main_dc = find_dc(main_dc_id_.get_raw_id());
|
auto main_dc = find_dc(main_dc_id_.get_raw_id());
|
||||||
if (!main_dc || main_dc->auth_state != AuthState::OK) {
|
if (!main_dc || main_dc->auth_key_state != AuthKeyState::OK) {
|
||||||
if (was_auth_) {
|
if (was_auth_) {
|
||||||
G()->shared_config().set_option_boolean("auth", false);
|
G()->shared_config().set_option_boolean("auth", false);
|
||||||
destroy_loop();
|
destroy_loop();
|
||||||
}
|
}
|
||||||
VLOG(dc) << "Skip loop because auth state of main dc " << main_dc_id_.get_raw_id() << " is "
|
VLOG(dc) << "Skip loop because auth state of main dc " << main_dc_id_.get_raw_id() << " is "
|
||||||
<< (main_dc != nullptr ? (PSTRING() << main_dc->auth_state) : "unknown");
|
<< (main_dc != nullptr ? (PSTRING() << main_dc->auth_key_state) : "unknown");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ class DcAuthManager : public NetQueryCallback {
|
|||||||
struct DcInfo {
|
struct DcInfo {
|
||||||
DcId dc_id;
|
DcId dc_id;
|
||||||
std::shared_ptr<AuthDataShared> shared_auth_data;
|
std::shared_ptr<AuthDataShared> shared_auth_data;
|
||||||
AuthState auth_state;
|
AuthKeyState auth_key_state;
|
||||||
|
|
||||||
enum class State : int32 { Waiting, Export, Import, BeforeOk, Ok };
|
enum class State : int32 { Waiting, Export, Import, BeforeOk, Ok };
|
||||||
State state = State::Waiting;
|
State state = State::Waiting;
|
||||||
@ -52,7 +52,7 @@ class DcAuthManager : public NetQueryCallback {
|
|||||||
DcInfo &get_dc(int32 dc_id);
|
DcInfo &get_dc(int32 dc_id);
|
||||||
DcInfo *find_dc(int32 dc_id);
|
DcInfo *find_dc(int32 dc_id);
|
||||||
|
|
||||||
void update_auth_state();
|
void update_auth_key_state();
|
||||||
|
|
||||||
void on_result(NetQueryPtr result) override;
|
void on_result(NetQueryPtr result) override;
|
||||||
void dc_loop(DcInfo &dc);
|
void dc_loop(DcInfo &dc);
|
||||||
|
@ -58,8 +58,6 @@ class SessionMultiProxy : public Actor {
|
|||||||
|
|
||||||
bool get_pfs_flag() const;
|
bool get_pfs_flag() const;
|
||||||
|
|
||||||
void update_auth_state();
|
|
||||||
|
|
||||||
void on_query_finished(uint32 generation, int session_id);
|
void on_query_finished(uint32 generation, int session_id);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,14 +95,14 @@ void SessionProxy::start_up() {
|
|||||||
if (!session_proxy_.is_alive()) {
|
if (!session_proxy_.is_alive()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
send_closure(session_proxy_, &SessionProxy::update_auth_state);
|
send_closure(session_proxy_, &SessionProxy::update_auth_key_state);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ActorShared<SessionProxy> session_proxy_;
|
ActorShared<SessionProxy> session_proxy_;
|
||||||
};
|
};
|
||||||
auth_state_ = auth_data_->get_auth_state().first;
|
auth_key_state_ = auth_data_->get_auth_key_state().first;
|
||||||
auth_data_->add_auth_key_listener(make_unique<Listener>(actor_shared(this)));
|
auth_data_->add_auth_key_listener(make_unique<Listener>(actor_shared(this)));
|
||||||
open_session();
|
open_session();
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ void SessionProxy::tear_down() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void SessionProxy::send(NetQueryPtr query) {
|
void SessionProxy::send(NetQueryPtr query) {
|
||||||
if (query->auth_flag() == NetQuery::AuthFlag::On && auth_state_ != AuthState::OK) {
|
if (query->auth_flag() == NetQuery::AuthFlag::On && auth_key_state_ != AuthKeyState::OK) {
|
||||||
query->debug(PSTRING() << get_name() << ": wait for auth");
|
query->debug(PSTRING() << get_name() << ": wait for auth");
|
||||||
pending_queries_.emplace_back(std::move(query));
|
pending_queries_.emplace_back(std::move(query));
|
||||||
return;
|
return;
|
||||||
@ -176,9 +176,9 @@ void SessionProxy::open_session(bool force) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (need_destroy_) {
|
if (need_destroy_) {
|
||||||
return auth_state_ != AuthState::Empty;
|
return auth_key_state_ != AuthKeyState::Empty;
|
||||||
}
|
}
|
||||||
if (auth_state_ != AuthState::OK) {
|
if (auth_key_state_ != AuthKeyState::OK) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return is_main_ || !pending_queries_.empty();
|
return is_main_ || !pending_queries_.empty();
|
||||||
@ -205,14 +205,14 @@ void SessionProxy::open_session(bool force) {
|
|||||||
auth_data_, int_dc_id, is_main_, use_pfs_, is_cdn_, need_destroy_, tmp_auth_key_, server_salts_);
|
auth_data_, int_dc_id, is_main_, use_pfs_, is_cdn_, need_destroy_, tmp_auth_key_, server_salts_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SessionProxy::update_auth_state() {
|
void SessionProxy::update_auth_key_state() {
|
||||||
auto old_auth_state = auth_state_;
|
auto old_auth_key_state = auth_key_state_;
|
||||||
auth_state_ = auth_data_->get_auth_state().first;
|
auth_key_state_ = auth_data_->get_auth_key_state().first;
|
||||||
if (auth_state_ != old_auth_state && old_auth_state == AuthState::OK) {
|
if (auth_key_state_ != old_auth_key_state && old_auth_key_state == AuthKeyState::OK) {
|
||||||
close_session();
|
close_session();
|
||||||
}
|
}
|
||||||
open_session();
|
open_session();
|
||||||
if (session_.empty() || auth_state_ != AuthState::OK) {
|
if (session_.empty() || auth_key_state_ != AuthKeyState::OK) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (auto &query : pending_queries_) {
|
for (auto &query : pending_queries_) {
|
||||||
|
@ -40,7 +40,7 @@ class SessionProxy : public Actor {
|
|||||||
private:
|
private:
|
||||||
unique_ptr<Callback> callback_;
|
unique_ptr<Callback> callback_;
|
||||||
std::shared_ptr<AuthDataShared> auth_data_;
|
std::shared_ptr<AuthDataShared> auth_data_;
|
||||||
AuthState auth_state_;
|
AuthKeyState auth_key_state_;
|
||||||
bool is_main_;
|
bool is_main_;
|
||||||
bool allow_media_only_;
|
bool allow_media_only_;
|
||||||
bool is_media_;
|
bool is_media_;
|
||||||
@ -58,7 +58,7 @@ class SessionProxy : public Actor {
|
|||||||
void close_session();
|
void close_session();
|
||||||
void open_session(bool force = false);
|
void open_session(bool force = false);
|
||||||
|
|
||||||
void update_auth_state();
|
void update_auth_key_state();
|
||||||
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key);
|
void on_tmp_auth_key_updated(mtproto::AuthKey auth_key);
|
||||||
void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts);
|
void on_server_salt_updated(std::vector<mtproto::ServerSalt> server_salts);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user