@@ -9,6 +9,7 @@ use axum::http::StatusCode;
99use axum:: response:: { IntoResponse , Response } ;
1010use serde:: { self , Deserialize , Serialize } ;
1111use thiserror:: Error ;
12+ use torrust_tracker_configuration:: AnnouncePolicy ;
1213use torrust_tracker_contrib_bencode:: { ben_bytes, ben_int, ben_list, ben_map, BMutAccess , BencodeMut } ;
1314
1415use crate :: core:: { self , AnnounceData } ;
@@ -20,11 +21,14 @@ use crate::servers::http::v1::responses;
2021///
2122/// ```rust
2223/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
24+ /// use torrust_tracker_configuration::AnnouncePolicy;
2325/// use torrust_tracker::servers::http::v1::responses::announce::{Normal, NormalPeer};
2426///
2527/// let response = Normal {
26- /// interval: 111,
27- /// interval_min: 222,
28+ /// policy: AnnouncePolicy {
29+ /// interval: 111,
30+ /// interval_min: 222,
31+ /// },
2832/// complete: 333,
2933/// incomplete: 444,
3034/// peers: vec![
@@ -58,31 +62,8 @@ use crate::servers::http::v1::responses;
5862/// for more information.
5963#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
6064pub struct Normal {
61- /// Interval in seconds that the client should wait between sending regular
62- /// announce requests to the tracker.
63- ///
64- /// It's a **recommended** wait time between announcements.
65- ///
66- /// This is the standard amount of time that clients should wait between
67- /// sending consecutive announcements to the tracker. This value is set by
68- /// the tracker and is typically provided in the tracker's response to a
69- /// client's initial request. It serves as a guideline for clients to know
70- /// how often they should contact the tracker for updates on the peer list,
71- /// while ensuring that the tracker is not overwhelmed with requests.
72- pub interval : u32 ,
73- /// Minimum announce interval. Clients must not reannounce more frequently
74- /// than this.
75- ///
76- /// It establishes the shortest allowed wait time.
77- ///
78- /// This is an optional parameter in the protocol that the tracker may
79- /// provide in its response. It sets a lower limit on the frequency at which
80- /// clients are allowed to send announcements. Clients should respect this
81- /// value to prevent sending too many requests in a short period, which
82- /// could lead to excessive load on the tracker or even getting banned by
83- /// the tracker for not adhering to the rules.
84- #[ serde( rename = "min interval" ) ]
85- pub interval_min : u32 ,
65+ /// Announce policy
66+ pub policy : AnnouncePolicy ,
8667 /// Number of peers with the entire file, i.e. seeders.
8768 pub complete : u32 ,
8869 /// Number of non-seeder peers, aka "leechers".
@@ -152,8 +133,8 @@ impl Normal {
152133 ( ben_map ! {
153134 "complete" => ben_int!( i64 :: from( self . complete) ) ,
154135 "incomplete" => ben_int!( i64 :: from( self . incomplete) ) ,
155- "interval" => ben_int!( i64 :: from( self . interval) ) ,
156- "min interval" => ben_int!( i64 :: from( self . interval_min) ) ,
136+ "interval" => ben_int!( i64 :: from( self . policy . interval) ) ,
137+ "min interval" => ben_int!( i64 :: from( self . policy . interval_min) ) ,
157138 "peers" => peers_list. clone( )
158139 } )
159140 . encode ( )
@@ -175,8 +156,10 @@ impl From<AnnounceData> for Normal {
175156 . collect ( ) ;
176157
177158 Self {
178- interval : domain_announce_response. interval ,
179- interval_min : domain_announce_response. interval_min ,
159+ policy : AnnouncePolicy {
160+ interval : domain_announce_response. interval ,
161+ interval_min : domain_announce_response. interval_min ,
162+ } ,
180163 complete : domain_announce_response. swarm_stats . seeders ,
181164 incomplete : domain_announce_response. swarm_stats . leechers ,
182165 peers,
@@ -192,11 +175,14 @@ impl From<AnnounceData> for Normal {
192175///
193176/// ```rust
194177/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
178+ /// use torrust_tracker_configuration::AnnouncePolicy;
195179/// use torrust_tracker::servers::http::v1::responses::announce::{Compact, CompactPeer};
196180///
197181/// let response = Compact {
198- /// interval: 111,
199- /// interval_min: 222,
182+ /// policy: AnnouncePolicy {
183+ /// interval: 111,
184+ /// interval_min: 222,
185+ /// },
200186/// complete: 333,
201187/// incomplete: 444,
202188/// peers: vec
233219#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
234220pub struct Compact {
235- /// Interval in seconds that the client should wait between sending regular
236- /// announce requests to the tracker.
237- ///
238- /// It's a **recommended** wait time between announcements.
239- ///
240- /// This is the standard amount of time that clients should wait between
241- /// sending consecutive announcements to the tracker. This value is set by
242- /// the tracker and is typically provided in the tracker's response to a
243- /// client's initial request. It serves as a guideline for clients to know
244- /// how often they should contact the tracker for updates on the peer list,
245- /// while ensuring that the tracker is not overwhelmed with requests.
246- pub interval : u32 ,
247- /// Minimum announce interval. Clients must not reannounce more frequently
248- /// than this.
249- ///
250- /// It establishes the shortest allowed wait time.
251- ///
252- /// This is an optional parameter in the protocol that the tracker may
253- /// provide in its response. It sets a lower limit on the frequency at which
254- /// clients are allowed to send announcements. Clients should respect this
255- /// value to prevent sending too many requests in a short period, which
256- /// could lead to excessive load on the tracker or even getting banned by
257- /// the tracker for not adhering to the rules.
258- #[ serde( rename = "min interval" ) ]
259- pub interval_min : u32 ,
221+ /// Announce policy
222+ pub policy : AnnouncePolicy ,
260223 /// Number of seeders, aka "completed".
261224 pub complete : u32 ,
262225 /// Number of non-seeder peers, aka "incomplete".
@@ -335,8 +298,8 @@ impl Compact {
335298 let bytes = ( ben_map ! {
336299 "complete" => ben_int!( i64 :: from( self . complete) ) ,
337300 "incomplete" => ben_int!( i64 :: from( self . incomplete) ) ,
338- "interval" => ben_int!( i64 :: from( self . interval) ) ,
339- "min interval" => ben_int!( i64 :: from( self . interval_min) ) ,
301+ "interval" => ben_int!( i64 :: from( self . policy . interval) ) ,
302+ "min interval" => ben_int!( i64 :: from( self . policy . interval_min) ) ,
340303 "peers" => ben_bytes!( self . peers_v4_bytes( ) ?) ,
341304 "peers6" => ben_bytes!( self . peers_v6_bytes( ) ?)
342305 } )
@@ -414,8 +377,10 @@ impl From<AnnounceData> for Compact {
414377 . collect ( ) ;
415378
416379 Self {
417- interval : domain_announce_response. interval ,
418- interval_min : domain_announce_response. interval_min ,
380+ policy : AnnouncePolicy {
381+ interval : domain_announce_response. interval ,
382+ interval_min : domain_announce_response. interval_min ,
383+ } ,
419384 complete : domain_announce_response. swarm_stats . seeders ,
420385 incomplete : domain_announce_response. swarm_stats . leechers ,
421386 peers,
@@ -428,6 +393,8 @@ mod tests {
428393
429394 use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
430395
396+ use torrust_tracker_configuration:: AnnouncePolicy ;
397+
431398 use super :: { Normal , NormalPeer } ;
432399 use crate :: servers:: http:: v1:: responses:: announce:: { Compact , CompactPeer } ;
433400
@@ -446,8 +413,10 @@ mod tests {
446413 #[ test]
447414 fn normal_announce_response_can_be_bencoded ( ) {
448415 let response = Normal {
449- interval : 111 ,
450- interval_min : 222 ,
416+ policy : AnnouncePolicy {
417+ interval : 111 ,
418+ interval_min : 222 ,
419+ } ,
451420 complete : 333 ,
452421 incomplete : 444 ,
453422 peers : vec ! [
@@ -480,8 +449,10 @@ mod tests {
480449 #[ test]
481450 fn compact_announce_response_can_be_bencoded ( ) {
482451 let response = Compact {
483- interval : 111 ,
484- interval_min : 222 ,
452+ policy : AnnouncePolicy {
453+ interval : 111 ,
454+ interval_min : 222 ,
455+ } ,
485456 complete : 333 ,
486457 incomplete : 444 ,
487458 peers : vec ! [
0 commit comments