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 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.
14
22
pub incomplete : u32 ,
15
23
}
16
24
@@ -20,3 +28,31 @@ impl SwarmMetadata {
20
28
Self :: default ( )
21
29
}
22
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