9898//!
9999//! ```rust,no_run
100100//! use torrust_tracker::core::peer::Peer;
101+ //! use torrust_tracker_configuration::AnnouncePolicy;
101102//!
102103//! pub struct AnnounceData {
103104//! pub peers: Vec<Peer>,
104105//! pub swarm_stats: SwarmStats,
105- //! pub interval: u32, // Option `announce_interval` from core tracker configuration
106- //! pub interval_min: u32, // Option `min_announce_interval` from core tracker configuration
106+ //! pub policy: AnnouncePolicy, // the tracker announce policy.
107107//! }
108108//!
109109//! pub struct SwarmStats {
@@ -445,9 +445,10 @@ use std::panic::Location;
445445use std:: sync:: Arc ;
446446use std:: time:: Duration ;
447447
448+ use derive_more:: Constructor ;
448449use futures:: future:: join_all;
449450use tokio:: sync:: mpsc:: error:: SendError ;
450- use torrust_tracker_configuration:: Configuration ;
451+ use torrust_tracker_configuration:: { AnnouncePolicy , Configuration } ;
451452use torrust_tracker_primitives:: TrackerMode ;
452453
453454use self :: auth:: Key ;
@@ -487,7 +488,7 @@ pub struct Tracker {
487488/// Structure that holds general `Tracker` torrents metrics.
488489///
489490/// Metrics are aggregate values for all torrents.
490- #[ derive( Debug , PartialEq , Default ) ]
491+ #[ derive( Copy , Clone , Debug , PartialEq , Default ) ]
491492pub struct TorrentsMetrics {
492493 /// Total number of seeders for all torrents
493494 pub seeders : u64 ,
@@ -500,20 +501,14 @@ pub struct TorrentsMetrics {
500501}
501502
502503/// Structure that holds the data returned by the `announce` request.
503- #[ derive( Debug , PartialEq , Default ) ]
504+ #[ derive( Clone , Debug , PartialEq , Constructor , Default ) ]
504505pub struct AnnounceData {
505506 /// The list of peers that are downloading the same torrent.
506507 /// It excludes the peer that made the request.
507508 pub peers : Vec < Peer > ,
508509 /// Swarm statistics
509- pub swarm_stats : SwarmStats ,
510- /// The interval in seconds that the client should wait between sending
511- /// regular requests to the tracker.
512- /// Refer to [`announce_interval`](torrust_tracker_configuration::Configuration::announce_interval).
513- pub interval : u32 ,
514- /// The minimum announce interval in seconds that the client should wait.
515- /// Refer to [`min_announce_interval`](torrust_tracker_configuration::Configuration::min_announce_interval).
516- pub interval_min : u32 ,
510+ pub stats : SwarmStats ,
511+ pub policy : AnnouncePolicy ,
517512}
518513
519514/// Structure that holds the data returned by the `scrape` request.
@@ -628,11 +623,12 @@ impl Tracker {
628623
629624 let peers = self . get_torrent_peers_for_peer ( info_hash, peer) . await ;
630625
626+ let policy = AnnouncePolicy :: new ( self . config . announce_interval , self . config . min_announce_interval ) ;
627+
631628 AnnounceData {
632629 peers,
633- swarm_stats,
634- interval : self . config . announce_interval ,
635- interval_min : self . config . min_announce_interval ,
630+ stats : swarm_stats,
631+ policy,
636632 }
637633 }
638634
@@ -1390,7 +1386,7 @@ mod tests {
13901386
13911387 let announce_data = tracker. announce ( & sample_info_hash ( ) , & mut peer, & peer_ip ( ) ) . await ;
13921388
1393- assert_eq ! ( announce_data. swarm_stats . complete, 1 ) ;
1389+ assert_eq ! ( announce_data. stats . complete, 1 ) ;
13941390 }
13951391
13961392 #[ tokio:: test]
@@ -1401,7 +1397,7 @@ mod tests {
14011397
14021398 let announce_data = tracker. announce ( & sample_info_hash ( ) , & mut peer, & peer_ip ( ) ) . await ;
14031399
1404- assert_eq ! ( announce_data. swarm_stats . incomplete, 1 ) ;
1400+ assert_eq ! ( announce_data. stats . incomplete, 1 ) ;
14051401 }
14061402
14071403 #[ tokio:: test]
@@ -1415,7 +1411,7 @@ mod tests {
14151411 let mut completed_peer = completed_peer ( ) ;
14161412 let announce_data = tracker. announce ( & sample_info_hash ( ) , & mut completed_peer, & peer_ip ( ) ) . await ;
14171413
1418- assert_eq ! ( announce_data. swarm_stats . downloaded, 1 ) ;
1414+ assert_eq ! ( announce_data. stats . downloaded, 1 ) ;
14191415 }
14201416 }
14211417 }
0 commit comments