@@ -9,6 +9,7 @@ use axum::http::StatusCode;
9
9
use axum:: response:: { IntoResponse , Response } ;
10
10
use serde:: { self , Deserialize , Serialize } ;
11
11
use thiserror:: Error ;
12
+ use torrust_tracker_configuration:: AnnouncePolicy ;
12
13
use torrust_tracker_contrib_bencode:: { ben_bytes, ben_int, ben_list, ben_map, BMutAccess , BencodeMut } ;
13
14
14
15
use crate :: core:: { self , AnnounceData } ;
@@ -20,11 +21,14 @@ use crate::servers::http::v1::responses;
20
21
///
21
22
/// ```rust
22
23
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
24
+ /// use torrust_tracker_configuration::AnnouncePolicy;
23
25
/// use torrust_tracker::servers::http::v1::responses::announce::{Normal, NormalPeer};
24
26
///
25
27
/// let response = Normal {
26
- /// interval: 111,
27
- /// interval_min: 222,
28
+ /// policy: AnnouncePolicy {
29
+ /// interval: 111,
30
+ /// interval_min: 222,
31
+ /// },
28
32
/// complete: 333,
29
33
/// incomplete: 444,
30
34
/// peers: vec![
@@ -58,31 +62,8 @@ use crate::servers::http::v1::responses;
58
62
/// for more information.
59
63
#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
60
64
pub 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 ,
86
67
/// Number of peers with the entire file, i.e. seeders.
87
68
pub complete : u32 ,
88
69
/// Number of non-seeder peers, aka "leechers".
@@ -152,8 +133,8 @@ impl Normal {
152
133
( ben_map ! {
153
134
"complete" => ben_int!( i64 :: from( self . complete) ) ,
154
135
"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) ) ,
157
138
"peers" => peers_list. clone( )
158
139
} )
159
140
. encode ( )
@@ -175,8 +156,10 @@ impl From<AnnounceData> for Normal {
175
156
. collect ( ) ;
176
157
177
158
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
+ } ,
180
163
complete : domain_announce_response. swarm_stats . seeders ,
181
164
incomplete : domain_announce_response. swarm_stats . leechers ,
182
165
peers,
@@ -192,11 +175,14 @@ impl From<AnnounceData> for Normal {
192
175
///
193
176
/// ```rust
194
177
/// use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
178
+ /// use torrust_tracker_configuration::AnnouncePolicy;
195
179
/// use torrust_tracker::servers::http::v1::responses::announce::{Compact, CompactPeer};
196
180
///
197
181
/// let response = Compact {
198
- /// interval: 111,
199
- /// interval_min: 222,
182
+ /// policy: AnnouncePolicy {
183
+ /// interval: 111,
184
+ /// interval_min: 222,
185
+ /// },
200
186
/// complete: 333,
201
187
/// incomplete: 444,
202
188
/// peers: vec
233
219
#[ derive( Serialize , Deserialize , Debug , PartialEq ) ]
234
220
pub 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 ,
260
223
/// Number of seeders, aka "completed".
261
224
pub complete : u32 ,
262
225
/// Number of non-seeder peers, aka "incomplete".
@@ -335,8 +298,8 @@ impl Compact {
335
298
let bytes = ( ben_map ! {
336
299
"complete" => ben_int!( i64 :: from( self . complete) ) ,
337
300
"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) ) ,
340
303
"peers" => ben_bytes!( self . peers_v4_bytes( ) ?) ,
341
304
"peers6" => ben_bytes!( self . peers_v6_bytes( ) ?)
342
305
} )
@@ -414,8 +377,10 @@ impl From<AnnounceData> for Compact {
414
377
. collect ( ) ;
415
378
416
379
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
+ } ,
419
384
complete : domain_announce_response. swarm_stats . seeders ,
420
385
incomplete : domain_announce_response. swarm_stats . leechers ,
421
386
peers,
@@ -428,6 +393,8 @@ mod tests {
428
393
429
394
use std:: net:: { IpAddr , Ipv4Addr , Ipv6Addr } ;
430
395
396
+ use torrust_tracker_configuration:: AnnouncePolicy ;
397
+
431
398
use super :: { Normal , NormalPeer } ;
432
399
use crate :: servers:: http:: v1:: responses:: announce:: { Compact , CompactPeer } ;
433
400
@@ -446,8 +413,10 @@ mod tests {
446
413
#[ test]
447
414
fn normal_announce_response_can_be_bencoded ( ) {
448
415
let response = Normal {
449
- interval : 111 ,
450
- interval_min : 222 ,
416
+ policy : AnnouncePolicy {
417
+ interval : 111 ,
418
+ interval_min : 222 ,
419
+ } ,
451
420
complete : 333 ,
452
421
incomplete : 444 ,
453
422
peers : vec ! [
@@ -480,8 +449,10 @@ mod tests {
480
449
#[ test]
481
450
fn compact_announce_response_can_be_bencoded ( ) {
482
451
let response = Compact {
483
- interval : 111 ,
484
- interval_min : 222 ,
452
+ policy : AnnouncePolicy {
453
+ interval : 111 ,
454
+ interval_min : 222 ,
455
+ } ,
485
456
complete : 333 ,
486
457
incomplete : 444 ,
487
458
peers : vec ! [
0 commit comments