@@ -7,11 +7,11 @@ use std::panic::Location;
77
88use axum:: http:: StatusCode ;
99use axum:: response:: { IntoResponse , Response } ;
10- use serde:: { self , Deserialize , Serialize } ;
1110use thiserror:: Error ;
1211use torrust_tracker_configuration:: AnnouncePolicy ;
1312use torrust_tracker_contrib_bencode:: { ben_bytes, ben_int, ben_list, ben_map, BMutAccess , BencodeMut } ;
1413
14+ use crate :: core:: torrent:: SwarmStats ;
1515use crate :: core:: { self , AnnounceData } ;
1616use crate :: servers:: http:: v1:: responses;
1717
@@ -22,15 +22,19 @@ use crate::servers::http::v1::responses;
2222/// ```rust
2323/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
2424/// use torrust_tracker_configuration::AnnouncePolicy;
25+ /// use torrust_tracker::core::torrent::SwarmStats;
2526/// use torrust_tracker::servers::http::v1::responses::announce::{Normal, NormalPeer};
2627///
2728/// let response = Normal {
2829/// policy: AnnouncePolicy {
2930/// interval: 111,
3031/// interval_min: 222,
3132/// },
32- /// complete: 333,
33- /// incomplete: 444,
33+ /// stats: SwarmStats {
34+ /// downloaded: 0,
35+ /// complete: 333,
36+ /// incomplete: 444,
37+ /// },
3438/// peers: vec
6266/// for more information.
63- #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
67+ #[ derive( Debug , PartialEq ) ]
6468pub struct Normal {
65- /// Announce policy
6669 pub policy : AnnouncePolicy ,
67- /// Number of peers with the entire file, i.e. seeders.
68- pub complete : u32 ,
69- /// Number of non-seeder peers, aka "leechers".
70- pub incomplete : u32 ,
71- /// A list of peers. The value is a list of dictionaries.
70+ pub stats : SwarmStats ,
7271 pub peers : Vec < NormalPeer > ,
7372}
7473
@@ -85,7 +84,7 @@ pub struct Normal {
8584/// port: 0x7070, // 28784
8685/// };
8786/// ```
88- #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
87+ #[ derive( Debug , PartialEq ) ]
8988pub struct NormalPeer {
9089 /// The peer's ID.
9190 pub peer_id : [ u8 ; 20 ] ,
@@ -131,8 +130,8 @@ impl Normal {
131130 }
132131
133132 ( ben_map ! {
134- "complete" => ben_int!( i64 :: from( self . complete) ) ,
135- "incomplete" => ben_int!( i64 :: from( self . incomplete) ) ,
133+ "complete" => ben_int!( i64 :: from( self . stats . complete) ) ,
134+ "incomplete" => ben_int!( i64 :: from( self . stats . incomplete) ) ,
136135 "interval" => ben_int!( i64 :: from( self . policy. interval) ) ,
137136 "min interval" => ben_int!( i64 :: from( self . policy. interval_min) ) ,
138137 "peers" => peers_list. clone( )
@@ -160,8 +159,11 @@ impl From<AnnounceData> for Normal {
160159 interval : domain_announce_response. interval ,
161160 interval_min : domain_announce_response. interval_min ,
162161 } ,
163- complete : domain_announce_response. swarm_stats . seeders ,
164- incomplete : domain_announce_response. swarm_stats . leechers ,
162+ stats : SwarmStats {
163+ complete : domain_announce_response. swarm_stats . complete ,
164+ incomplete : domain_announce_response. swarm_stats . incomplete ,
165+ downloaded : 0 ,
166+ } ,
165167 peers,
166168 }
167169 }
@@ -176,15 +178,19 @@ impl From<AnnounceData> for Normal {
176178/// ```rust
177179/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
178180/// use torrust_tracker_configuration::AnnouncePolicy;
181+ /// use torrust_tracker::core::torrent::SwarmStats;
179182/// use torrust_tracker::servers::http::v1::responses::announce::{Compact, CompactPeer};
180183///
181184/// let response = Compact {
182185/// policy: AnnouncePolicy {
183186/// interval: 111,
184187/// interval_min: 222,
185188/// },
186- /// complete: 333,
187- /// incomplete: 444,
189+ /// stats: SwarmStats {
190+ /// downloaded: 0,
191+ /// complete: 333,
192+ /// incomplete: 444,
193+ /// },
188194/// peers: vec
218224/// - [BEP 07: IPv6 Tracker Extension](https://www.bittorrent.org/beps/bep_0007.html)
219- #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
225+ #[ derive( Debug , PartialEq ) ]
220226pub struct Compact {
221- /// Announce policy
222227 pub policy : AnnouncePolicy ,
223- /// Number of seeders, aka "completed".
224- pub complete : u32 ,
225- /// Number of non-seeder peers, aka "incomplete".
226- pub incomplete : u32 ,
227- /// Compact peer list.
228+ pub stats : SwarmStats ,
228229 pub peers : Vec < CompactPeer > ,
229230}
230231
@@ -250,7 +251,7 @@ pub struct Compact {
250251///
251252/// Refer to [BEP 23: Tracker Returns Compact Peer Lists](https://www.bittorrent.org/beps/bep_0023.html)
252253/// for more information.
253- #[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
254+ #[ derive( Debug , PartialEq ) ]
254255pub struct CompactPeer {
255256 /// The peer's IP address.
256257 pub ip : IpAddr ,
@@ -296,8 +297,8 @@ impl Compact {
296297 /// Will return `Err` if internally interrupted.
297298 pub fn body ( & self ) -> Result < Vec < u8 > , Box < dyn std:: error:: Error > > {
298299 let bytes = ( ben_map ! {
299- "complete" => ben_int!( i64 :: from( self . complete) ) ,
300- "incomplete" => ben_int!( i64 :: from( self . incomplete) ) ,
300+ "complete" => ben_int!( i64 :: from( self . stats . complete) ) ,
301+ "incomplete" => ben_int!( i64 :: from( self . stats . incomplete) ) ,
301302 "interval" => ben_int!( i64 :: from( self . policy. interval) ) ,
302303 "min interval" => ben_int!( i64 :: from( self . policy. interval_min) ) ,
303304 "peers" => ben_bytes!( self . peers_v4_bytes( ) ?) ,
@@ -381,8 +382,11 @@ impl From<AnnounceData> for Compact {
381382 interval : domain_announce_response. interval ,
382383 interval_min : domain_announce_response. interval_min ,
383384 } ,
384- complete : domain_announce_response. swarm_stats . seeders ,
385- incomplete : domain_announce_response. swarm_stats . leechers ,
385+ stats : SwarmStats {
386+ complete : domain_announce_response. swarm_stats . complete ,
387+ incomplete : domain_announce_response. swarm_stats . incomplete ,
388+ downloaded : 0 ,
389+ } ,
386390 peers,
387391 }
388392 }
@@ -396,6 +400,7 @@ mod tests {
396400 use torrust_tracker_configuration:: AnnouncePolicy ;
397401
398402 use super :: { Normal , NormalPeer } ;
403+ use crate :: core:: torrent:: SwarmStats ;
399404 use crate :: servers:: http:: v1:: responses:: announce:: { Compact , CompactPeer } ;
400405
401406 // Some ascii values used in tests:
@@ -417,8 +422,11 @@ mod tests {
417422 interval : 111 ,
418423 interval_min : 222 ,
419424 } ,
420- complete : 333 ,
421- incomplete : 444 ,
425+ stats : SwarmStats {
426+ downloaded : 0 ,
427+ complete : 333 ,
428+ incomplete : 444 ,
429+ } ,
422430 peers : vec ! [
423431 // IPV4
424432 NormalPeer {
@@ -453,8 +461,11 @@ mod tests {
453461 interval : 111 ,
454462 interval_min : 222 ,
455463 } ,
456- complete : 333 ,
457- incomplete : 444 ,
464+ stats : SwarmStats {
465+ downloaded : 0 ,
466+ complete : 333 ,
467+ incomplete : 444 ,
468+ } ,
458469 peers : vec ! [
459470 // IPV4
460471 CompactPeer {
0 commit comments