forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolicy.rs
More file actions
54 lines (47 loc) · 1.99 KB
/
Copy pathpolicy.rs
File metadata and controls
54 lines (47 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Tracker policy types.
//!
//! This module contains the [`TrackerPolicy`] struct that governs
//! tracker-wide retention and cleanup behaviour.
use derive_more::Constructor;
use serde::{Deserialize, Serialize};
/// Policy settings that control tracker-wide torrent and peer retention.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Constructor)]
pub struct TrackerPolicy {
// Cleanup job configuration
/// Maximum time in seconds that a peer can be inactive before being
/// considered an inactive peer. If a peer is inactive for more than this
/// time, it will be removed from the torrent peer list.
#[serde(default = "TrackerPolicy::default_max_peer_timeout")]
pub max_peer_timeout: u32,
/// If enabled the tracker will persist the number of completed downloads.
/// That's how many times a torrent has been downloaded completely.
#[serde(default = "TrackerPolicy::default_persistent_torrent_completed_stat")]
pub persistent_torrent_completed_stat: bool,
/// If enabled, the tracker will remove torrents that have no peers.
/// The clean up torrent job runs every `inactive_peer_cleanup_interval`
/// seconds and it removes inactive peers. Eventually, the peer list of a
/// torrent could be empty and the torrent will be removed if this option is
/// enabled.
#[serde(default = "TrackerPolicy::default_remove_peerless_torrents")]
pub remove_peerless_torrents: bool,
}
impl Default for TrackerPolicy {
fn default() -> Self {
Self {
max_peer_timeout: Self::default_max_peer_timeout(),
persistent_torrent_completed_stat: Self::default_persistent_torrent_completed_stat(),
remove_peerless_torrents: Self::default_remove_peerless_torrents(),
}
}
}
impl TrackerPolicy {
fn default_max_peer_timeout() -> u32 {
900
}
fn default_persistent_torrent_completed_stat() -> bool {
false
}
fn default_remove_peerless_torrents() -> bool {
true
}
}