98
98
//!
99
99
//! ```rust,no_run
100
100
//! use torrust_tracker::core::peer::Peer;
101
+ //! use torrust_tracker_configuration::AnnouncePolicy;
101
102
//!
102
103
//! pub struct AnnounceData {
103
104
//! pub peers: Vec<Peer>,
104
105
//! 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.
107
107
//! }
108
108
//!
109
109
//! pub struct SwarmStats {
@@ -445,9 +445,10 @@ use std::panic::Location;
445
445
use std:: sync:: Arc ;
446
446
use std:: time:: Duration ;
447
447
448
+ use derive_more:: Constructor ;
448
449
use futures:: future:: join_all;
449
450
use tokio:: sync:: mpsc:: error:: SendError ;
450
- use torrust_tracker_configuration:: Configuration ;
451
+ use torrust_tracker_configuration:: { AnnouncePolicy , Configuration } ;
451
452
use torrust_tracker_primitives:: TrackerMode ;
452
453
453
454
use self :: auth:: Key ;
@@ -487,7 +488,7 @@ pub struct Tracker {
487
488
/// Structure that holds general `Tracker` torrents metrics.
488
489
///
489
490
/// Metrics are aggregate values for all torrents.
490
- #[ derive( Debug , PartialEq , Default ) ]
491
+ #[ derive( Copy , Clone , Debug , PartialEq , Default ) ]
491
492
pub struct TorrentsMetrics {
492
493
/// Total number of seeders for all torrents
493
494
pub seeders : u64 ,
@@ -500,20 +501,14 @@ pub struct TorrentsMetrics {
500
501
}
501
502
502
503
/// Structure that holds the data returned by the `announce` request.
503
- #[ derive( Debug , PartialEq , Default ) ]
504
+ #[ derive( Clone , Debug , PartialEq , Constructor , Default ) ]
504
505
pub struct AnnounceData {
505
506
/// The list of peers that are downloading the same torrent.
506
507
/// It excludes the peer that made the request.
507
508
pub peers : Vec < Peer > ,
508
509
/// 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 ,
517
512
}
518
513
519
514
/// Structure that holds the data returned by the `scrape` request.
@@ -628,11 +623,12 @@ impl Tracker {
628
623
629
624
let peers = self . get_torrent_peers_for_peer ( info_hash, peer) . await ;
630
625
626
+ let policy = AnnouncePolicy :: new ( self . config . announce_interval , self . config . min_announce_interval ) ;
627
+
631
628
AnnounceData {
632
629
peers,
633
- swarm_stats,
634
- interval : self . config . announce_interval ,
635
- interval_min : self . config . min_announce_interval ,
630
+ stats : swarm_stats,
631
+ policy,
636
632
}
637
633
}
638
634
@@ -1390,7 +1386,7 @@ mod tests {
1390
1386
1391
1387
let announce_data = tracker. announce ( & sample_info_hash ( ) , & mut peer, & peer_ip ( ) ) . await ;
1392
1388
1393
- assert_eq ! ( announce_data. swarm_stats . complete, 1 ) ;
1389
+ assert_eq ! ( announce_data. stats . complete, 1 ) ;
1394
1390
}
1395
1391
1396
1392
#[ tokio:: test]
@@ -1401,7 +1397,7 @@ mod tests {
1401
1397
1402
1398
let announce_data = tracker. announce ( & sample_info_hash ( ) , & mut peer, & peer_ip ( ) ) . await ;
1403
1399
1404
- assert_eq ! ( announce_data. swarm_stats . incomplete, 1 ) ;
1400
+ assert_eq ! ( announce_data. stats . incomplete, 1 ) ;
1405
1401
}
1406
1402
1407
1403
#[ tokio:: test]
@@ -1415,7 +1411,7 @@ mod tests {
1415
1411
let mut completed_peer = completed_peer ( ) ;
1416
1412
let announce_data = tracker. announce ( & sample_info_hash ( ) , & mut completed_peer, & peer_ip ( ) ) . await ;
1417
1413
1418
- assert_eq ! ( announce_data. swarm_stats . downloaded, 1 ) ;
1414
+ assert_eq ! ( announce_data. stats . downloaded, 1 ) ;
1419
1415
}
1420
1416
}
1421
1417
}
0 commit comments