diff --git a/td/telegram/net/ConnectionCreator.cpp b/td/telegram/net/ConnectionCreator.cpp index 424850620..1e1460eff 100644 --- a/td/telegram/net/ConnectionCreator.cpp +++ b/td/telegram/net/ConnectionCreator.cpp @@ -90,6 +90,8 @@ class StatsCallback final : public mtproto::RawConnection::StatsCallback { } // namespace detail ConnectionCreator::ClientInfo::ClientInfo() { + sanity_flood_control.add_limit(5, 10); + flood_control.add_limit(1, 1); flood_control.add_limit(4, 2); flood_control.add_limit(8, 3); @@ -549,6 +551,7 @@ void ConnectionCreator::on_network(bool network_flag, uint32 network_generation) for (auto &client : clients_) { client.second.backoff.clear(); + client.second.sanity_flood_control.clear_events(); client.second.flood_control.clear_events(); client.second.flood_control_online.clear_events(); client_loop(client.second); @@ -566,6 +569,7 @@ void ConnectionCreator::on_online(bool online_flag) { online_flag_ = online_flag; if (need_drop_flood_control) { for (auto &client : clients_) { + client.second.sanity_flood_control.clear_events(); client.second.backoff.clear(); client.second.flood_control_online.clear_events(); client_loop(client.second); @@ -576,6 +580,7 @@ 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.sanity_flood_control.clear_events(); client.second.backoff.clear(); client.second.flood_control_online.clear_events(); client_loop(client.second); @@ -865,16 +870,15 @@ void ConnectionCreator::client_loop(ClientInfo &client) { // Check flood 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()); + wakeup_at = max(client.sanity_flood_control.get_wakeup_at(), wakeup_at); + 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(Time::now())); - if (!act_as_if_online) { - client.backoff.add_event(static_cast(Time::now())); - } + client.sanity_flood_control.add_event(static_cast(Time::now())); // Create new RawConnection // sync part @@ -889,6 +893,12 @@ void ConnectionCreator::client_loop(ClientInfo &client) { return client_set_timeout_at(client, Time::now() + 0.1); } + // Events with failed socket creation are ignored + flood_control.add_event(static_cast(Time::now())); + if (!act_as_if_online) { + client.backoff.add_event(static_cast(Time::now())); + } + auto socket_fd = r_socket_fd.move_as_ok(); IPAddress debug_ip; auto debug_ip_status = debug_ip.init_socket_address(socket_fd); diff --git a/td/telegram/net/ConnectionCreator.h b/td/telegram/net/ConnectionCreator.h index 5e43ebb6c..38c5bb9e7 100644 --- a/td/telegram/net/ConnectionCreator.h +++ b/td/telegram/net/ConnectionCreator.h @@ -147,6 +147,7 @@ class ConnectionCreator : public NetQueryCallback { void add_session_id(int64 session_id); Backoff backoff; + FloodControlStrict sanity_flood_control; FloodControlStrict flood_control; FloodControlStrict flood_control_online; FloodControlStrict mtproto_error_flood_control;