@@ -10,58 +10,71 @@ use crate::{AnnouncePolicy, LogLevel};
1010pub struct Core {
1111 /// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
1212 /// `Debug` and `Trace`. Default is `Info`.
13+ #[ serde( default = "Core::default_log_level" ) ]
1314 pub log_level : Option < LogLevel > ,
1415 /// Tracker mode. See [`TrackerMode`] for more information.
16+ #[ serde( default = "Core::default_mode" ) ]
1517 pub mode : TrackerMode ,
1618
1719 // Database configuration
1820 /// Database driver. Possible values are: `Sqlite3`, and `MySQL`.
21+ #[ serde( default = "Core::default_db_driver" ) ]
1922 pub db_driver : DatabaseDriver ,
2023 /// Database connection string. The format depends on the database driver.
2124 /// For `Sqlite3`, the format is `path/to/database.db`, for example:
2225 /// `./storage/tracker/lib/database/sqlite3.db`.
2326 /// For `Mysql`, the format is `mysql://db_user:db_user_password:port/db_name`, for
2427 /// example: `root:password@localhost:3306/torrust`.
28+ #[ serde( default = "Core::default_db_path" ) ]
2529 pub db_path : String ,
2630
2731 /// See [`AnnouncePolicy::interval`]
32+ #[ serde( default = "AnnouncePolicy::default_interval" ) ]
2833 pub announce_interval : u32 ,
2934
3035 /// See [`AnnouncePolicy::interval_min`]
36+ #[ serde( default = "AnnouncePolicy::default_interval_min" ) ]
3137 pub min_announce_interval : u32 ,
3238 /// Weather the tracker is behind a reverse proxy or not.
3339 /// If the tracker is behind a reverse proxy, the `X-Forwarded-For` header
3440 /// sent from the proxy will be used to get the client's IP address.
41+ #[ serde( default = "Core::default_on_reverse_proxy" ) ]
3542 pub on_reverse_proxy : bool ,
3643 /// The external IP address of the tracker. If the client is using a
3744 /// loopback IP address, this IP address will be used instead. If the peer
3845 /// is using a loopback IP address, the tracker assumes that the peer is
3946 /// in the same network as the tracker and will use the tracker's IP
4047 /// address instead.
48+ #[ serde( default = "Core::default_external_ip" ) ]
4149 pub external_ip : Option < IpAddr > ,
4250 /// Weather the tracker should collect statistics about tracker usage.
4351 /// If enabled, the tracker will collect statistics like the number of
4452 /// connections handled, the number of announce requests handled, etc.
4553 /// Refer to the [`Tracker`](https://docs.rs/torrust-tracker) for more
4654 /// information about the collected metrics.
55+ #[ serde( default = "Core::default_tracker_usage_statistics" ) ]
4756 pub tracker_usage_statistics : bool ,
4857 /// If enabled the tracker will persist the number of completed downloads.
4958 /// That's how many times a torrent has been downloaded completely.
59+ #[ serde( default = "Core::default_persistent_torrent_completed_stat" ) ]
5060 pub persistent_torrent_completed_stat : bool ,
5161
5262 // Cleanup job configuration
5363 /// Maximum time in seconds that a peer can be inactive before being
5464 /// considered an inactive peer. If a peer is inactive for more than this
5565 /// time, it will be removed from the torrent peer list.
66+ #[ serde( default = "Core::default_max_peer_timeout" ) ]
5667 pub max_peer_timeout : u32 ,
5768 /// Interval in seconds that the cleanup job will run to remove inactive
5869 /// peers from the torrent peer list.
70+ #[ serde( default = "Core::default_inactive_peer_cleanup_interval" ) ]
5971 pub inactive_peer_cleanup_interval : u64 ,
6072 /// If enabled, the tracker will remove torrents that have no peers.
6173 /// The clean up torrent job runs every `inactive_peer_cleanup_interval`
6274 /// seconds and it removes inactive peers. Eventually, the peer list of a
6375 /// torrent could be empty and the torrent will be removed if this option is
6476 /// enabled.
77+ #[ serde( default = "Core::default_remove_peerless_torrents" ) ]
6578 pub remove_peerless_torrents : bool ,
6679}
6780
@@ -70,19 +83,67 @@ impl Default for Core {
7083 let announce_policy = AnnouncePolicy :: default ( ) ;
7184
7285 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" ) ,
86+ log_level : Self :: default_log_level ( ) ,
87+ mode : Self :: default_mode ( ) ,
88+ db_driver : Self :: default_db_driver ( ) ,
89+ db_path : Self :: default_db_path ( ) ,
7790 announce_interval : announce_policy. interval ,
7891 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 ,
92+ max_peer_timeout : Self :: default_max_peer_timeout ( ) ,
93+ on_reverse_proxy : Self :: default_on_reverse_proxy ( ) ,
94+ external_ip : Self :: default_external_ip ( ) ,
95+ tracker_usage_statistics : Self :: default_tracker_usage_statistics ( ) ,
96+ persistent_torrent_completed_stat : Self :: default_persistent_torrent_completed_stat ( ) ,
97+ inactive_peer_cleanup_interval : Self :: default_inactive_peer_cleanup_interval ( ) ,
98+ remove_peerless_torrents : Self :: default_remove_peerless_torrents ( ) ,
8699 }
87100 }
88101}
102+
103+ impl Core {
104+ #[ allow( clippy:: unnecessary_wraps) ]
105+ fn default_log_level ( ) -> Option < LogLevel > {
106+ Some ( LogLevel :: Info )
107+ }
108+
109+ fn default_mode ( ) -> TrackerMode {
110+ TrackerMode :: Public
111+ }
112+
113+ fn default_db_driver ( ) -> DatabaseDriver {
114+ DatabaseDriver :: Sqlite3
115+ }
116+
117+ fn default_db_path ( ) -> String {
118+ String :: from ( "./storage/tracker/lib/database/sqlite3.db" )
119+ }
120+
121+ fn default_on_reverse_proxy ( ) -> bool {
122+ false
123+ }
124+
125+ #[ allow( clippy:: unnecessary_wraps) ]
126+ fn default_external_ip ( ) -> Option < IpAddr > {
127+ Some ( IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) )
128+ }
129+
130+ fn default_tracker_usage_statistics ( ) -> bool {
131+ true
132+ }
133+
134+ fn default_persistent_torrent_completed_stat ( ) -> bool {
135+ false
136+ }
137+
138+ fn default_max_peer_timeout ( ) -> u32 {
139+ 900
140+ }
141+
142+ fn default_inactive_peer_cleanup_interval ( ) -> u64 {
143+ 600
144+ }
145+
146+ fn default_remove_peerless_torrents ( ) -> bool {
147+ true
148+ }
149+ }
0 commit comments