Skip to content

Commit fe7e039

Browse files
committed
feat!: [torrust#878] extract announce_policy section in core config section
1 parent edc706c commit fe7e039

File tree

5 files changed

+36
-31
lines changed

5 files changed

+36
-31
lines changed

packages/configuration/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Info {
8686
}
8787

8888
/// Announce policy
89-
#[derive(PartialEq, Eq, Debug, Clone, Copy, Constructor)]
89+
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy, Constructor)]
9090
pub struct AnnouncePolicy {
9191
/// Interval in seconds that the client should wait between sending regular
9292
/// announce requests to the tracker.

packages/configuration/src/v1/core.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ pub struct Core {
1212
#[serde(default = "Core::default_mode")]
1313
pub mode: TrackerMode,
1414

15-
/// See [`AnnouncePolicy::interval`]
16-
#[serde(default = "AnnouncePolicy::default_interval")]
17-
pub announce_interval: u32,
18-
19-
/// See [`AnnouncePolicy::interval_min`]
20-
#[serde(default = "AnnouncePolicy::default_interval_min")]
21-
pub min_announce_interval: u32,
22-
2315
/// Weather the tracker should collect statistics about tracker usage.
2416
/// If enabled, the tracker will collect statistics like the number of
2517
/// connections handled, the number of announce requests handled, etc.
@@ -53,6 +45,10 @@ pub struct Core {
5345
#[serde(default = "Core::default_remove_peerless_torrents")]
5446
pub remove_peerless_torrents: bool,
5547

48+
// Announce policy configuration.
49+
#[serde(default = "Core::default_announce_policy")]
50+
pub announce_policy: AnnouncePolicy,
51+
5652
// Database configuration.
5753
#[serde(default = "Core::default_database")]
5854
pub database: Database,
@@ -64,17 +60,14 @@ pub struct Core {
6460

6561
impl Default for Core {
6662
fn default() -> Self {
67-
let announce_policy = AnnouncePolicy::default();
68-
6963
Self {
7064
mode: Self::default_mode(),
71-
announce_interval: announce_policy.interval,
72-
min_announce_interval: announce_policy.interval_min,
7365
max_peer_timeout: Self::default_max_peer_timeout(),
7466
tracker_usage_statistics: Self::default_tracker_usage_statistics(),
7567
persistent_torrent_completed_stat: Self::default_persistent_torrent_completed_stat(),
7668
inactive_peer_cleanup_interval: Self::default_inactive_peer_cleanup_interval(),
7769
remove_peerless_torrents: Self::default_remove_peerless_torrents(),
70+
announce_policy: Self::default_announce_policy(),
7871
database: Self::default_database(),
7972
net: Self::default_network(),
8073
}
@@ -106,6 +99,10 @@ impl Core {
10699
true
107100
}
108101

102+
fn default_announce_policy() -> AnnouncePolicy {
103+
AnnouncePolicy::default()
104+
}
105+
109106
fn default_database() -> Database {
110107
Database::default()
111108
}

packages/configuration/src/v1/mod.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,16 @@
198198
//!
199199
//! [core]
200200
//! mode = "public"
201-
//! announce_interval = 120
202-
//! min_announce_interval = 120
203201
//! tracker_usage_statistics = true
204202
//! persistent_torrent_completed_stat = false
205203
//! max_peer_timeout = 900
206204
//! inactive_peer_cleanup_interval = 600
207205
//! remove_peerless_torrents = true
208206
//!
207+
//! [core.announce_policy]
208+
//! interval = 120
209+
//! interval_min = 120
210+
//!
209211
//! [core.database]
210212
//! driver = "Sqlite3"
211213
//! path = "./storage/tracker/lib/database/sqlite3.db"
@@ -388,14 +390,16 @@ mod tests {
388390
389391
[core]
390392
mode = "public"
391-
announce_interval = 120
392-
min_announce_interval = 120
393393
tracker_usage_statistics = true
394394
persistent_torrent_completed_stat = false
395395
max_peer_timeout = 900
396396
inactive_peer_cleanup_interval = 600
397397
remove_peerless_torrents = true
398398
399+
[core.announce_policy]
400+
interval = 120
401+
interval_min = 120
402+
399403
[core.database]
400404
driver = "Sqlite3"
401405
path = "./storage/tracker/lib/database/sqlite3.db"

src/core/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@
113113
//! }
114114
//!
115115
//! // Core tracker configuration
116-
//! pub struct Configuration {
116+
//! pub struct AnnounceInterval {
117117
//! // ...
118-
//! pub announce_interval: u32, // Interval in seconds that the client should wait between sending regular announce requests to the tracker
119-
//! pub min_announce_interval: u32, // Minimum announce interval. Clients must not reannounce more frequently than this
118+
//! pub interval: u32, // Interval in seconds that the client should wait between sending regular announce requests to the tracker
119+
//! pub interval_min: u32, // Minimum announce interval. Clients must not reannounce more frequently than this
120120
//! // ...
121121
//! }
122122
//! ```
@@ -317,14 +317,16 @@
317317
//!
318318
//! [core]
319319
//! mode = "public"
320-
//! announce_interval = 120
321-
//! min_announce_interval = 120
322320
//! max_peer_timeout = 900
323321
//! tracker_usage_statistics = true
324322
//! persistent_torrent_completed_stat = true
325323
//! inactive_peer_cleanup_interval = 600
326324
//! remove_peerless_torrents = false
327325
//!
326+
//! [core.announce_policy]
327+
//! interval = 120
328+
//! interval_min = 120
329+
//!
328330
//! [core.database]
329331
//! driver = "Sqlite3"
330332
//! path = "./storage/tracker/lib/database/sqlite3.db"
@@ -558,7 +560,7 @@ impl Tracker {
558560

559561
Ok(Tracker {
560562
//config,
561-
announce_policy: AnnouncePolicy::new(config.announce_interval, config.min_announce_interval),
563+
announce_policy: config.announce_policy,
562564
mode,
563565
keys: tokio::sync::RwLock::new(std::collections::HashMap::new()),
564566
whitelist: tokio::sync::RwLock::new(std::collections::HashSet::new()),

src/lib.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -171,22 +171,24 @@
171171
//! log_level = "info"
172172
//!
173173
//! [core]
174-
//! announce_interval = 120
175174
//! inactive_peer_cleanup_interval = 600
176175
//! max_peer_timeout = 900
177-
//! min_announce_interval = 120
178176
//! mode = "public"
179177
//! persistent_torrent_completed_stat = false
180178
//! remove_peerless_torrents = true
181179
//! tracker_usage_statistics = true
182180
//!
183-
//! [core.database]
184-
//! driver = "Sqlite3"
185-
//! path = "./storage/tracker/lib/database/sqlite3.db"
181+
//! [core.announce_policy]
182+
//! interval = 120
183+
//! interval_min = 120
186184
//!
187-
//! [core.net]
188-
//! external_ip = "0.0.0.0"
189-
//! on_reverse_proxy = false
185+
//! [core.database]
186+
//! driver = "Sqlite3"
187+
//! path = "./storage/tracker/lib/database/sqlite3.db"
188+
//!
189+
//! [core.net]
190+
//! external_ip = "0.0.0.0"
191+
//! on_reverse_proxy = false
190192
//!
191193
//! [[udp_trackers]]
192194
//! bind_address = "0.0.0.0:6969"

0 commit comments

Comments
 (0)