Skip to content

Commit

Permalink
feat!: [torrust#878] extract announce_policy section in core config s…
Browse files Browse the repository at this point in the history
…ection
  • Loading branch information
josecelano committed Jun 17, 2024
1 parent edc706c commit fe7e039
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Info {
}

/// Announce policy
#[derive(PartialEq, Eq, Debug, Clone, Copy, Constructor)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy, Constructor)]
pub struct AnnouncePolicy {
/// Interval in seconds that the client should wait between sending regular
/// announce requests to the tracker.
Expand Down
21 changes: 9 additions & 12 deletions packages/configuration/src/v1/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ pub struct Core {
#[serde(default = "Core::default_mode")]
pub mode: TrackerMode,

/// See [`AnnouncePolicy::interval`]
#[serde(default = "AnnouncePolicy::default_interval")]
pub announce_interval: u32,

/// See [`AnnouncePolicy::interval_min`]
#[serde(default = "AnnouncePolicy::default_interval_min")]
pub min_announce_interval: u32,

/// Weather the tracker should collect statistics about tracker usage.
/// If enabled, the tracker will collect statistics like the number of
/// connections handled, the number of announce requests handled, etc.
Expand Down Expand Up @@ -53,6 +45,10 @@ pub struct Core {
#[serde(default = "Core::default_remove_peerless_torrents")]
pub remove_peerless_torrents: bool,

// Announce policy configuration.
#[serde(default = "Core::default_announce_policy")]
pub announce_policy: AnnouncePolicy,

// Database configuration.
#[serde(default = "Core::default_database")]
pub database: Database,
Expand All @@ -64,17 +60,14 @@ pub struct Core {

impl Default for Core {
fn default() -> Self {
let announce_policy = AnnouncePolicy::default();

Self {
mode: Self::default_mode(),
announce_interval: announce_policy.interval,
min_announce_interval: announce_policy.interval_min,
max_peer_timeout: Self::default_max_peer_timeout(),
tracker_usage_statistics: Self::default_tracker_usage_statistics(),
persistent_torrent_completed_stat: Self::default_persistent_torrent_completed_stat(),
inactive_peer_cleanup_interval: Self::default_inactive_peer_cleanup_interval(),
remove_peerless_torrents: Self::default_remove_peerless_torrents(),
announce_policy: Self::default_announce_policy(),
database: Self::default_database(),
net: Self::default_network(),
}
Expand Down Expand Up @@ -106,6 +99,10 @@ impl Core {
true
}

fn default_announce_policy() -> AnnouncePolicy {
AnnouncePolicy::default()
}

fn default_database() -> Database {
Database::default()
}
Expand Down
12 changes: 8 additions & 4 deletions packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,16 @@
//!
//! [core]
//! mode = "public"
//! announce_interval = 120
//! min_announce_interval = 120
//! tracker_usage_statistics = true
//! persistent_torrent_completed_stat = false
//! max_peer_timeout = 900
//! inactive_peer_cleanup_interval = 600
//! remove_peerless_torrents = true
//!
//! [core.announce_policy]
//! interval = 120
//! interval_min = 120
//!
//! [core.database]
//! driver = "Sqlite3"
//! path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down Expand Up @@ -388,14 +390,16 @@ mod tests {
[core]
mode = "public"
announce_interval = 120
min_announce_interval = 120
tracker_usage_statistics = true
persistent_torrent_completed_stat = false
max_peer_timeout = 900
inactive_peer_cleanup_interval = 600
remove_peerless_torrents = true
[core.announce_policy]
interval = 120
interval_min = 120
[core.database]
driver = "Sqlite3"
path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down
14 changes: 8 additions & 6 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@
//! }
//!
//! // Core tracker configuration
//! pub struct Configuration {
//! pub struct AnnounceInterval {
//! // ...
//! pub announce_interval: u32, // Interval in seconds that the client should wait between sending regular announce requests to the tracker
//! pub min_announce_interval: u32, // Minimum announce interval. Clients must not reannounce more frequently than this
//! pub interval: u32, // Interval in seconds that the client should wait between sending regular announce requests to the tracker
//! pub interval_min: u32, // Minimum announce interval. Clients must not reannounce more frequently than this
//! // ...
//! }
//! ```
Expand Down Expand Up @@ -317,14 +317,16 @@
//!
//! [core]
//! mode = "public"
//! announce_interval = 120
//! min_announce_interval = 120
//! max_peer_timeout = 900
//! tracker_usage_statistics = true
//! persistent_torrent_completed_stat = true
//! inactive_peer_cleanup_interval = 600
//! remove_peerless_torrents = false
//!
//! [core.announce_policy]
//! interval = 120
//! interval_min = 120
//!
//! [core.database]
//! driver = "Sqlite3"
//! path = "./storage/tracker/lib/database/sqlite3.db"
Expand Down Expand Up @@ -558,7 +560,7 @@ impl Tracker {

Ok(Tracker {
//config,
announce_policy: AnnouncePolicy::new(config.announce_interval, config.min_announce_interval),
announce_policy: config.announce_policy,
mode,
keys: tokio::sync::RwLock::new(std::collections::HashMap::new()),
whitelist: tokio::sync::RwLock::new(std::collections::HashSet::new()),
Expand Down
18 changes: 10 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,22 +171,24 @@
//! log_level = "info"
//!
//! [core]
//! announce_interval = 120
//! inactive_peer_cleanup_interval = 600
//! max_peer_timeout = 900
//! min_announce_interval = 120
//! mode = "public"
//! persistent_torrent_completed_stat = false
//! remove_peerless_torrents = true
//! tracker_usage_statistics = true
//!
//! [core.database]
//! driver = "Sqlite3"
//! path = "./storage/tracker/lib/database/sqlite3.db"
//! [core.announce_policy]
//! interval = 120
//! interval_min = 120
//!
//! [core.net]
//! external_ip = "0.0.0.0"
//! on_reverse_proxy = false
//! [core.database]
//! driver = "Sqlite3"
//! path = "./storage/tracker/lib/database/sqlite3.db"
//!
//! [core.net]
//! external_ip = "0.0.0.0"
//! on_reverse_proxy = false
//!
//! [[udp_trackers]]
//! bind_address = "0.0.0.0:6969"
Expand Down

0 comments on commit fe7e039

Please sign in to comment.