1
+ use std:: ops:: AddAssign ;
2
+
1
3
use derive_more:: Constructor ;
2
4
3
5
/// Swarm statistics for one torrent.
6
+ ///
4
7
/// Swarm metadata dictionary in the scrape response.
5
8
///
6
9
/// See [BEP 48: Tracker Protocol Extension: Scrape](https://www.bittorrent.org/beps/bep_0048.html)
7
10
#[ derive( Copy , Clone , Debug , PartialEq , Default , Constructor ) ]
8
11
pub struct SwarmMetadata {
9
- /// (i.e `completed`): The number of peers that have ever completed
12
+ /// (i.e `completed`): The number of peers that have ever completed
10
13
/// downloading a given torrent.
11
14
pub downloaded : u32 ,
12
15
13
- /// (i.e `seeders`): The number of active peers that have completed
16
+ /// (i.e `seeders`): The number of active peers that have completed
14
17
/// downloading (seeders) a given torrent.
15
18
pub complete : u32 ,
16
19
17
- /// (i.e `leechers`): The number of active peers that have not completed
20
+ /// (i.e `leechers`): The number of active peers that have not completed
18
21
/// downloading (leechers) a given torrent.
19
22
pub incomplete : u32 ,
20
23
}
@@ -25,3 +28,31 @@ impl SwarmMetadata {
25
28
Self :: default ( )
26
29
}
27
30
}
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