@@ -3,7 +3,7 @@ use std::sync::Arc;
33use std:: time:: Duration ;
44
55use bittorrent_tracker_client:: udp:: client:: check;
6- use bloom:: CountingBloomFilter ;
6+ use bloom:: { CountingBloomFilter , ASMS } ;
77use derive_more:: Constructor ;
88use futures_util:: StreamExt ;
99use 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.
2626const 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,22 @@ 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 ( ) >= Duration :: from_secs ( RESET_CONNECTION_ID_ERRORS_COUNTER_FREQUENCY_IN_SECS ) {
138+ connection_id_errors_per_ip. write ( ) . await . clear ( ) ;
139+ tracing:: info!( target: UDP_TRACKER_LOG_TARGET , local_addr, "Udp::run_udp_server::loop (connection id errors filter cleared)" ) ;
140+ last_connection_id_errors_reset = tokio:: time:: Instant :: now ( ) ;
141+ }
142+
132143 let processor = Processor :: new ( receiver. socket . clone ( ) , tracker. clone ( ) , cookie_lifetime) ;
133144
134145 if let Some ( req) = {
0 commit comments