Add global flood limit.

main
levlam 9 months ago
parent 460f8bb219
commit 090e1e98e9

@ -116,11 +116,20 @@ void ClientManager::send(PromisedQueryPtr query) {
auto now = td::Time::now();
auto wakeup_at = flood_control.get_wakeup_at();
if (wakeup_at > now) {
LOG(INFO) << "Failed to create Client from IP address " << ip_address;
LOG(INFO) << "Failed to create Client from IP address " << ip_address << " with token";
return query->set_retry_after_error(static_cast<int>(wakeup_at - now) + 1);
}
flood_control.add_event(now);
}
if (is_global_flood_control_enabled_) {
auto now = td::Time::now();
auto wakeup_at = global_flood_control_.get_wakeup_at();
if (wakeup_at > now) {
LOG(WARNING) << "Failed to create Client with token " << token;
return query->set_retry_after_error(static_cast<int>(wakeup_at - now) + 1);
}
global_flood_control_.add_event(now);
}
auto tqueue_id = get_tqueue_id(user_id, query->is_test_dc());
if (active_client_count_.count(tqueue_id) != 0) {
// return query->set_retry_after_error(1);
@ -552,6 +561,12 @@ void ClientManager::timeout_expired() {
last_tqueue_deleted_events_ = tqueue_deleted_events_;
}
}
if (!is_global_flood_control_enabled_ && !parameters_->local_mode_) {
is_global_flood_control_enabled_ = true;
global_flood_control_.add_limit(60, 1000); // 1000 in a minute
global_flood_control_.add_limit(60 * 60, 10000); // 10000 in an hour
}
}
void ClientManager::hangup_shared() {

@ -66,6 +66,8 @@ class ClientManager final : public td::Actor {
td::FlatHashMap<td::string, td::uint64> token_to_id_;
td::FlatHashMap<td::string, td::FloodControlFast> flood_controls_;
td::FloodControlFast global_flood_control_;
bool is_global_flood_control_enabled_ = false;
td::FlatHashMap<td::int64, td::uint64> active_client_count_;
bool close_flag_ = false;

Loading…
Cancel
Save