td: relax limits for connection creation during logout

GitOrigin-RevId: 2c7e81d931a36cecaaf8dd1b463365d3e039873f
This commit is contained in:
Arseny Smirnov 2020-08-05 19:49:34 +03:00
parent 71867f372d
commit 3fb9b8a992
6 changed files with 37 additions and 5 deletions

View File

@ -837,6 +837,9 @@ void AuthManager::update_state(State new_state, bool force, bool should_save_sta
if (should_save_state) {
save_state();
}
if (new_state == State::LoggingOut || new_state == State::DestroyingKeys || new_state == State::Closing) {
send_closure(G()->state_manager(), &StateManager::on_logging_out, true);
}
send_closure(G()->td(), &Td::send_update,
make_tl_object<td_api::updateAuthorizationState>(get_authorization_state_object(state_)));

View File

@ -78,6 +78,11 @@ void StateManager::on_proxy(bool use_proxy) {
loop();
}
void StateManager::on_logging_out(bool is_logging_out) {
is_logging_out_ = is_logging_out;
notify_flag(Flag::LoggingOut);
}
void StateManager::add_callback(unique_ptr<Callback> callback) {
if (callback->on_network(network_type_, network_generation_) && callback->on_online(online_flag_) &&
callback->on_state(get_real_state())) {
@ -121,6 +126,8 @@ void StateManager::notify_flag(Flag flag) {
return (*it)->on_state(flush_state_);
case Flag::Network:
return (*it)->on_network(network_type_, network_generation_);
case Flag::LoggingOut:
return (*it)->on_logging_out(is_logging_out_);
default:
UNREACHABLE();
return true;

View File

@ -34,6 +34,9 @@ class StateManager final : public Actor {
virtual bool on_online(bool is_online) {
return true;
}
virtual bool on_logging_out(bool is_logging_out) {
return true;
}
};
explicit StateManager(ActorShared<> parent) : parent_(std::move(parent)) {
@ -49,6 +52,8 @@ class StateManager final : public Actor {
void on_proxy(bool use_proxy);
void on_logging_out(bool is_logging_out);
void add_callback(unique_ptr<Callback> net_callback);
void wait_first_sync(Promise<> promise);
@ -104,6 +109,7 @@ class StateManager final : public Actor {
uint32 network_generation_ = 1;
bool online_flag_ = false;
bool use_proxy_ = false;
bool is_logging_out_ = true;
static constexpr double UP_DELAY = 0.05;
static constexpr double DOWN_DELAY = 0.3;
@ -121,7 +127,7 @@ class StateManager final : public Actor {
void inc_connect();
void dec_connect();
enum class Flag : int32 { Online, State, Network };
enum class Flag : int32 { Online, State, Network, LoggingOut };
void notify_flag(Flag flag);
void start_up() override;

View File

@ -572,6 +572,15 @@ void ConnectionCreator::on_online(bool online_flag) {
}
}
}
void ConnectionCreator::on_logging_out(bool is_logging_out) {
VLOG(connections) << "Receive logging out flag " << is_logging_out;
is_logging_out_ = is_logging_out;
for (auto &client : clients_) {
client.second.backoff.clear();
client.second.flood_control_online.clear_events();
client_loop(client.second);
}
}
void ConnectionCreator::on_pong(size_t hash) {
G()->save_server_time();
@ -852,17 +861,18 @@ void ConnectionCreator::client_loop(ClientInfo &client) {
}
}
bool act_as_if_online = online_flag_ || is_logging_out_;
// Check flood
auto &flood_control = online_flag_ ? client.flood_control_online : client.flood_control;
auto &flood_control = act_as_if_online ? client.flood_control_online : client.flood_control;
auto wakeup_at = max(flood_control.get_wakeup_at(), client.mtproto_error_flood_control.get_wakeup_at());
if (!online_flag_) {
if (!act_as_if_online) {
wakeup_at = max(wakeup_at, client.backoff.get_wakeup_at());
}
if (wakeup_at > Time::now()) {
return client_set_timeout_at(client, wakeup_at);
}
flood_control.add_event(static_cast<int32>(Time::now()));
if (!online_flag_) {
if (!act_as_if_online) {
client.backoff.add_event(static_cast<int32>(Time::now()));
}
@ -1057,6 +1067,10 @@ void ConnectionCreator::start_up() {
send_closure(connection_creator_, &ConnectionCreator::on_online, online_flag);
return connection_creator_.is_alive();
}
bool on_logging_out(bool is_logging_out) override {
send_closure(connection_creator_, &ConnectionCreator::on_logging_out, is_logging_out);
return connection_creator_.is_alive();
}
private:
ActorId<ConnectionCreator> connection_creator_;

View File

@ -103,6 +103,7 @@ class ConnectionCreator : public NetQueryCallback {
bool network_flag_ = false;
uint32 network_generation_ = 0;
bool online_flag_ = false;
bool is_logging_out_ = false;
bool is_inited_ = false;
static constexpr int32 MAX_PROXY_LAST_USED_SAVE_DELAY = 60;
@ -211,6 +212,7 @@ class ConnectionCreator : public NetQueryCallback {
void on_network(bool network_flag, uint32 network_generation);
void on_online(bool online_flag);
void on_logging_out(bool is_logging_out);
static void update_mtproto_header(const Proxy &proxy);

View File

@ -227,7 +227,7 @@ void NetQueryDispatcher::update_session_count() {
}
void NetQueryDispatcher::destroy_auth_keys(Promise<> promise) {
std::lock_guard<std::mutex> guard(main_dc_id_mutex_);
LOG(INFO) << "Destory auth keys";
LOG(INFO) << "Destroy auth keys";
need_destroy_auth_key_ = true;
for (size_t i = 1; i < MAX_DC_COUNT; i++) {
if (is_dc_inited(narrow_cast<int32>(i)) && dcs_[i - 1].id_.is_internal()) {