@@ -236,6 +236,7 @@ use std::sync::Arc;
236236use std:: { env, fs} ;
237237
238238use config:: { Config , ConfigError , File , FileFormat } ;
239+ use derive_more:: Constructor ;
239240use serde:: { Deserialize , Serialize } ;
240241use serde_with:: { serde_as, NoneAsEmptyString } ;
241242use thiserror:: Error ;
@@ -303,6 +304,47 @@ impl Info {
303304 }
304305}
305306
307+ /// Announce policy
308+ #[ derive( Copy , Clone , Debug , PartialEq , Constructor ) ]
309+ pub struct AnnouncePolicy {
310+ /// Interval in seconds that the client should wait between sending regular
311+ /// announce requests to the tracker.
312+ ///
313+ /// It's a **recommended** wait time between announcements.
314+ ///
315+ /// This is the standard amount of time that clients should wait between
316+ /// sending consecutive announcements to the tracker. This value is set by
317+ /// the tracker and is typically provided in the tracker's response to a
318+ /// client's initial request. It serves as a guideline for clients to know
319+ /// how often they should contact the tracker for updates on the peer list,
320+ /// while ensuring that the tracker is not overwhelmed with requests.
321+ pub interval : u32 ,
322+
323+ /// Minimum announce interval. Clients must not reannounce more frequently
324+ /// than this.
325+ ///
326+ /// It establishes the shortest allowed wait time.
327+ ///
328+ /// This is an optional parameter in the protocol that the tracker may
329+ /// provide in its response. It sets a lower limit on the frequency at which
330+ /// clients are allowed to send announcements. Clients should respect this
331+ /// value to prevent sending too many requests in a short period, which
332+ /// could lead to excessive load on the tracker or even getting banned by
333+ /// the tracker for not adhering to the rules.
334+ pub interval_min : u32 ,
335+ }
336+
337+ impl Default for AnnouncePolicy {
338+ fn default ( ) -> Self {
339+ let announce_interval = 120 ;
340+ let min_announce_interval = 120 ;
341+ Self {
342+ interval : announce_interval,
343+ interval_min : min_announce_interval,
344+ }
345+ }
346+ }
347+
306348/// Configuration for each UDP tracker.
307349#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug , Clone ) ]
308350pub struct UdpTracker {
@@ -516,13 +558,15 @@ impl From<ConfigError> for Error {
516558
517559impl Default for Configuration {
518560 fn default ( ) -> Self {
561+ let announce_policy = AnnouncePolicy :: default ( ) ;
562+
519563 let mut configuration = Configuration {
520564 log_level : Option :: from ( String :: from ( "info" ) ) ,
521565 mode : TrackerMode :: Public ,
522566 db_driver : DatabaseDriver :: Sqlite3 ,
523567 db_path : String :: from ( "./storage/tracker/lib/database/sqlite3.db" ) ,
524- announce_interval : 120 ,
525- min_announce_interval : 120 ,
568+ announce_interval : announce_policy . interval ,
569+ min_announce_interval : announce_policy . interval_min ,
526570 max_peer_timeout : 900 ,
527571 on_reverse_proxy : false ,
528572 external_ip : Some ( String :: from ( "0.0.0.0" ) ) ,
0 commit comments