Skip to content

Commit 4801edf

Browse files
committed
feat: [torrust#1096] reset IP banning list for connections errors every hour
1 parent 7869aaf commit 4801edf

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/servers/udp/server/launcher.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use std::time::Duration;
44

55
use bittorrent_tracker_client::udp::client::check;
6-
use bloom::CountingBloomFilter;
6+
use bloom::{CountingBloomFilter, ASMS};
77
use derive_more::Constructor;
88
use futures_util::StreamExt;
99
use tokio::select;
@@ -24,6 +24,7 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
2424
/// The maximum number of connection id errors per ip. Clients will be banned if
2525
/// they exceed this limit.
2626
const MAX_CONNECTION_ID_ERRORS_PER_IP: u32 = 10;
27+
const RESET_CONNECTION_ID_ERRORS_COUNTER_FREQUENCY_IN_SECS: u64 = 3600;
2728

2829
/// A UDP server instance launcher.
2930
#[derive(Constructor)]
@@ -123,12 +124,24 @@ impl Launcher {
123124
// false positive rate of 0.01 when 100 items have been inserted
124125
let connection_id_errors_per_ip = Arc::new(RwLock::new(CountingBloomFilter::with_rate(4, 0.01, 100)));
125126

127+
// Timer to track when to clear the filter
128+
let mut last_connection_id_errors_reset = tokio::time::Instant::now();
129+
126130
let addr = receiver.bound_socket_address();
131+
127132
let local_addr = format!("udp://{addr}");
128133

129134
let cookie_lifetime = cookie_lifetime.as_secs_f64();
130135

131136
loop {
137+
if last_connection_id_errors_reset.elapsed()
138+
>= Duration::from_secs(RESET_CONNECTION_ID_ERRORS_COUNTER_FREQUENCY_IN_SECS)
139+
{
140+
connection_id_errors_per_ip.write().await.clear();
141+
tracing::info!(target: UDP_TRACKER_LOG_TARGET, local_addr, "Udp::run_udp_server::loop (connection id errors filter cleared)");
142+
last_connection_id_errors_reset = tokio::time::Instant::now();
143+
}
144+
132145
let processor = Processor::new(receiver.socket.clone(), tracker.clone(), cookie_lifetime);
133146

134147
if let Some(req) = {

0 commit comments

Comments
 (0)