@@ -3,7 +3,7 @@ use std::sync::Arc;
3
3
use std:: time:: Duration ;
4
4
5
5
use bittorrent_tracker_client:: udp:: client:: check;
6
- use bloom:: CountingBloomFilter ;
6
+ use bloom:: { CountingBloomFilter , ASMS } ;
7
7
use derive_more:: Constructor ;
8
8
use futures_util:: StreamExt ;
9
9
use tokio:: select;
@@ -24,6 +24,7 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
24
24
/// The maximum number of connection id errors per ip. Clients will be banned if
25
25
/// they exceed this limit.
26
26
const MAX_CONNECTION_ID_ERRORS_PER_IP : u32 = 10 ;
27
+ const RESET_CONNECTION_ID_ERRORS_COUNTER_FREQUENCY_IN_SECS : u64 = 3600 ;
27
28
28
29
/// A UDP server instance launcher.
29
30
#[ derive( Constructor ) ]
@@ -123,12 +124,24 @@ impl Launcher {
123
124
// false positive rate of 0.01 when 100 items have been inserted
124
125
let connection_id_errors_per_ip = Arc :: new ( RwLock :: new ( CountingBloomFilter :: with_rate ( 4 , 0.01 , 100 ) ) ) ;
125
126
127
+ // Timer to track when to clear the filter
128
+ let mut last_connection_id_errors_reset = tokio:: time:: Instant :: now ( ) ;
129
+
126
130
let addr = receiver. bound_socket_address ( ) ;
131
+
127
132
let local_addr = format ! ( "udp://{addr}" ) ;
128
133
129
134
let cookie_lifetime = cookie_lifetime. as_secs_f64 ( ) ;
130
135
131
136
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
+
132
145
let processor = Processor :: new ( receiver. socket . clone ( ) , tracker. clone ( ) , cookie_lifetime) ;
133
146
134
147
if let Some ( req) = {
0 commit comments