1+ use std:: ops:: AddAssign ;
2+
13use derive_more:: Constructor ;
24
35/// Swarm statistics for one torrent.
6+ ///
47/// Swarm metadata dictionary in the scrape response.
58///
69/// See [BEP 48: Tracker Protocol Extension: Scrape](https://www.bittorrent.org/beps/bep_0048.html)
710#[ derive( Copy , Clone , Debug , PartialEq , Default , Constructor ) ]
811pub struct SwarmMetadata {
9- /// (i.e `completed`): The number of peers that have ever completed downloading
10- pub downloaded : u32 , //
11- /// (i.e `seeders`): The number of active peers that have completed downloading (seeders)
12- pub complete : u32 , //seeders
13- /// (i.e `leechers`): The number of active peers that have not completed downloading (leechers)
12+ /// (i.e `completed`): The number of peers that have ever completed
13+ /// downloading a given torrent.
14+ pub downloaded : u32 ,
15+
16+ /// (i.e `seeders`): The number of active peers that have completed
17+ /// downloading (seeders) a given torrent.
18+ pub complete : u32 ,
19+
20+ /// (i.e `leechers`): The number of active peers that have not completed
21+ /// downloading (leechers) a given torrent.
1422 pub incomplete : u32 ,
1523}
1624
@@ -20,3 +28,31 @@ impl SwarmMetadata {
2028 Self :: default ( )
2129 }
2230}
31+
32+ /// Structure that holds aggregate swarm metadata.
33+ ///
34+ /// Metrics are aggregate values for all torrents.
35+ #[ derive( Copy , Clone , Debug , PartialEq , Default ) ]
36+ pub struct AggregateSwarmMetadata {
37+ /// Total number of peers that have ever completed downloading for all
38+ /// torrents.
39+ pub total_downloaded : u64 ,
40+
41+ /// Total number of seeders for all torrents.
42+ pub total_complete : u64 ,
43+
44+ /// Total number of leechers for all torrents.
45+ pub total_incomplete : u64 ,
46+
47+ /// Total number of torrents.
48+ pub total_torrents : u64 ,
49+ }
50+
51+ impl AddAssign for AggregateSwarmMetadata {
52+ fn add_assign ( & mut self , rhs : Self ) {
53+ self . total_complete += rhs. total_complete ;
54+ self . total_downloaded += rhs. total_downloaded ;
55+ self . total_incomplete += rhs. total_incomplete ;
56+ self . total_torrents += rhs. total_torrents ;
57+ }
58+ }
0 commit comments