|
| 1 | +use std::net::{IpAddr, Ipv4Addr}; |
| 2 | + |
| 3 | +use serde::{Deserialize, Serialize}; |
| 4 | +use torrust_tracker_primitives::{DatabaseDriver, TrackerMode}; |
| 5 | + |
| 6 | +use crate::{AnnouncePolicy, LogLevel}; |
| 7 | + |
| 8 | +#[allow(clippy::struct_excessive_bools)] |
| 9 | +#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] |
| 10 | +pub struct Core { |
| 11 | + /// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`, |
| 12 | + /// `Debug` and `Trace`. Default is `Info`. |
| 13 | + pub log_level: Option<LogLevel>, |
| 14 | + /// Tracker mode. See [`TrackerMode`] for more information. |
| 15 | + pub mode: TrackerMode, |
| 16 | + |
| 17 | + // Database configuration |
| 18 | + /// Database driver. Possible values are: `Sqlite3`, and `MySQL`. |
| 19 | + pub db_driver: DatabaseDriver, |
| 20 | + /// Database connection string. The format depends on the database driver. |
| 21 | + /// For `Sqlite3`, the format is `path/to/database.db`, for example: |
| 22 | + /// `./storage/tracker/lib/database/sqlite3.db`. |
| 23 | + /// For `Mysql`, the format is `mysql://db_user:db_user_password:port/db_name`, for |
| 24 | + /// example: `root:password@localhost:3306/torrust`. |
| 25 | + pub db_path: String, |
| 26 | + |
| 27 | + /// See [`AnnouncePolicy::interval`] |
| 28 | + pub announce_interval: u32, |
| 29 | + |
| 30 | + /// See [`AnnouncePolicy::interval_min`] |
| 31 | + pub min_announce_interval: u32, |
| 32 | + /// Weather the tracker is behind a reverse proxy or not. |
| 33 | + /// If the tracker is behind a reverse proxy, the `X-Forwarded-For` header |
| 34 | + /// sent from the proxy will be used to get the client's IP address. |
| 35 | + pub on_reverse_proxy: bool, |
| 36 | + /// The external IP address of the tracker. If the client is using a |
| 37 | + /// loopback IP address, this IP address will be used instead. If the peer |
| 38 | + /// is using a loopback IP address, the tracker assumes that the peer is |
| 39 | + /// in the same network as the tracker and will use the tracker's IP |
| 40 | + /// address instead. |
| 41 | + pub external_ip: Option<IpAddr>, |
| 42 | + /// Weather the tracker should collect statistics about tracker usage. |
| 43 | + /// If enabled, the tracker will collect statistics like the number of |
| 44 | + /// connections handled, the number of announce requests handled, etc. |
| 45 | + /// Refer to the [`Tracker`](https://docs.rs/torrust-tracker) for more |
| 46 | + /// information about the collected metrics. |
| 47 | + pub tracker_usage_statistics: bool, |
| 48 | + /// If enabled the tracker will persist the number of completed downloads. |
| 49 | + /// That's how many times a torrent has been downloaded completely. |
| 50 | + pub persistent_torrent_completed_stat: bool, |
| 51 | + |
| 52 | + // Cleanup job configuration |
| 53 | + /// Maximum time in seconds that a peer can be inactive before being |
| 54 | + /// considered an inactive peer. If a peer is inactive for more than this |
| 55 | + /// time, it will be removed from the torrent peer list. |
| 56 | + pub max_peer_timeout: u32, |
| 57 | + /// Interval in seconds that the cleanup job will run to remove inactive |
| 58 | + /// peers from the torrent peer list. |
| 59 | + pub inactive_peer_cleanup_interval: u64, |
| 60 | + /// If enabled, the tracker will remove torrents that have no peers. |
| 61 | + /// The clean up torrent job runs every `inactive_peer_cleanup_interval` |
| 62 | + /// seconds and it removes inactive peers. Eventually, the peer list of a |
| 63 | + /// torrent could be empty and the torrent will be removed if this option is |
| 64 | + /// enabled. |
| 65 | + pub remove_peerless_torrents: bool, |
| 66 | +} |
| 67 | + |
| 68 | +impl Default for Core { |
| 69 | + fn default() -> Self { |
| 70 | + let announce_policy = AnnouncePolicy::default(); |
| 71 | + |
| 72 | + Self { |
| 73 | + log_level: Some(LogLevel::Info), |
| 74 | + mode: TrackerMode::Public, |
| 75 | + db_driver: DatabaseDriver::Sqlite3, |
| 76 | + db_path: String::from("./storage/tracker/lib/database/sqlite3.db"), |
| 77 | + announce_interval: announce_policy.interval, |
| 78 | + min_announce_interval: announce_policy.interval_min, |
| 79 | + max_peer_timeout: 900, |
| 80 | + on_reverse_proxy: false, |
| 81 | + external_ip: Some(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))), |
| 82 | + tracker_usage_statistics: true, |
| 83 | + persistent_torrent_completed_stat: false, |
| 84 | + inactive_peer_cleanup_interval: 600, |
| 85 | + remove_peerless_torrents: true, |
| 86 | + } |
| 87 | + } |
| 88 | +} |
0 commit comments