230
230
//! [health_check_api]
231
231
//! bind_address = "127.0.0.1:1313"
232
232
//!```
233
+ pub mod core;
233
234
pub mod health_check_api;
234
235
pub mod http_tracker;
235
236
pub mod tracker_api;
236
237
pub mod udp_tracker;
237
238
238
239
use std:: fs;
239
- use std:: net:: { IpAddr , Ipv4Addr } ;
240
+ use std:: net:: IpAddr ;
240
241
241
242
use figment:: providers:: { Env , Format , Serialized , Toml } ;
242
243
use figment:: Figment ;
243
244
use serde:: { Deserialize , Serialize } ;
244
- use torrust_tracker_primitives:: { DatabaseDriver , TrackerMode } ;
245
245
246
+ use self :: core:: Core ;
246
247
use self :: health_check_api:: HealthCheckApi ;
247
248
use self :: http_tracker:: HttpTracker ;
248
249
use self :: tracker_api:: HttpApi ;
249
250
use self :: udp_tracker:: UdpTracker ;
250
- use crate :: { AnnouncePolicy , Error , Info , LogLevel } ;
251
+ use crate :: { Error , Info } ;
251
252
252
253
/// Core configuration for the tracker.
253
- #[ allow( clippy:: struct_excessive_bools) ]
254
254
#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug ) ]
255
255
pub struct Configuration {
256
- /// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
257
- /// `Debug` and `Trace`. Default is `Info`.
258
- pub log_level : Option < LogLevel > ,
259
- /// Tracker mode. See [`TrackerMode`] for more information.
260
- pub mode : TrackerMode ,
261
-
262
- // Database configuration
263
- /// Database driver. Possible values are: `Sqlite3`, and `MySQL`.
264
- pub db_driver : DatabaseDriver ,
265
- /// Database connection string. The format depends on the database driver.
266
- /// For `Sqlite3`, the format is `path/to/database.db`, for example:
267
- /// `./storage/tracker/lib/database/sqlite3.db`.
268
- /// For `Mysql`, the format is `mysql://db_user:db_user_password:port/db_name`, for
269
- /// example: `root:password@localhost:3306/torrust`.
270
- pub db_path : String ,
271
-
272
- /// See [`AnnouncePolicy::interval`]
273
- pub announce_interval : u32 ,
274
-
275
- /// See [`AnnouncePolicy::interval_min`]
276
- pub min_announce_interval : u32 ,
277
- /// Weather the tracker is behind a reverse proxy or not.
278
- /// If the tracker is behind a reverse proxy, the `X-Forwarded-For` header
279
- /// sent from the proxy will be used to get the client's IP address.
280
- pub on_reverse_proxy : bool ,
281
- /// The external IP address of the tracker. If the client is using a
282
- /// loopback IP address, this IP address will be used instead. If the peer
283
- /// is using a loopback IP address, the tracker assumes that the peer is
284
- /// in the same network as the tracker and will use the tracker's IP
285
- /// address instead.
286
- pub external_ip : Option < IpAddr > ,
287
- /// Weather the tracker should collect statistics about tracker usage.
288
- /// If enabled, the tracker will collect statistics like the number of
289
- /// connections handled, the number of announce requests handled, etc.
290
- /// Refer to the [`Tracker`](https://docs.rs/torrust-tracker) for more
291
- /// information about the collected metrics.
292
- pub tracker_usage_statistics : bool ,
293
- /// If enabled the tracker will persist the number of completed downloads.
294
- /// That's how many times a torrent has been downloaded completely.
295
- pub persistent_torrent_completed_stat : bool ,
296
-
297
- // Cleanup job configuration
298
- /// Maximum time in seconds that a peer can be inactive before being
299
- /// considered an inactive peer. If a peer is inactive for more than this
300
- /// time, it will be removed from the torrent peer list.
301
- pub max_peer_timeout : u32 ,
302
- /// Interval in seconds that the cleanup job will run to remove inactive
303
- /// peers from the torrent peer list.
304
- pub inactive_peer_cleanup_interval : u64 ,
305
- /// If enabled, the tracker will remove torrents that have no peers.
306
- /// The clean up torrent job runs every `inactive_peer_cleanup_interval`
307
- /// seconds and it removes inactive peers. Eventually, the peer list of a
308
- /// torrent could be empty and the torrent will be removed if this option is
309
- /// enabled.
310
- pub remove_peerless_torrents : bool ,
311
-
312
- // Server jobs configuration
256
+ /// Core configuration.
257
+ #[ serde( flatten) ]
258
+ pub core : Core ,
313
259
/// The list of UDP trackers the tracker is running. Each UDP tracker
314
260
/// represents a UDP server that the tracker is running and it has its own
315
261
/// configuration.
@@ -326,30 +272,13 @@ pub struct Configuration {
326
272
327
273
impl Default for Configuration {
328
274
fn default ( ) -> Self {
329
- let announce_policy = AnnouncePolicy :: default ( ) ;
330
-
331
- let mut configuration = Configuration {
332
- log_level : Some ( LogLevel :: Info ) ,
333
- mode : TrackerMode :: Public ,
334
- db_driver : DatabaseDriver :: Sqlite3 ,
335
- db_path : String :: from ( "./storage/tracker/lib/database/sqlite3.db" ) ,
336
- announce_interval : announce_policy. interval ,
337
- min_announce_interval : announce_policy. interval_min ,
338
- max_peer_timeout : 900 ,
339
- on_reverse_proxy : false ,
340
- external_ip : Some ( IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) ) ,
341
- tracker_usage_statistics : true ,
342
- persistent_torrent_completed_stat : false ,
343
- inactive_peer_cleanup_interval : 600 ,
344
- remove_peerless_torrents : true ,
345
- udp_trackers : Vec :: new ( ) ,
346
- http_trackers : Vec :: new ( ) ,
275
+ Self {
276
+ core : Core :: default ( ) ,
277
+ udp_trackers : vec ! [ UdpTracker :: default ( ) ] ,
278
+ http_trackers : vec ! [ HttpTracker :: default ( ) ] ,
347
279
http_api : HttpApi :: default ( ) ,
348
280
health_check_api : HealthCheckApi :: default ( ) ,
349
- } ;
350
- configuration. udp_trackers . push ( UdpTracker :: default ( ) ) ;
351
- configuration. http_trackers . push ( HttpTracker :: default ( ) ) ;
352
- configuration
281
+ }
353
282
}
354
283
}
355
284
@@ -362,7 +291,7 @@ impl Configuration {
362
291
/// and `None` otherwise.
363
292
#[ must_use]
364
293
pub fn get_ext_ip ( & self ) -> Option < IpAddr > {
365
- self . external_ip . as_ref ( ) . map ( |external_ip| * external_ip)
294
+ self . core . external_ip . as_ref ( ) . map ( |external_ip| * external_ip)
366
295
}
367
296
368
297
/// Saves the default configuration at the given path.
@@ -490,7 +419,7 @@ mod tests {
490
419
fn configuration_should_contain_the_external_ip ( ) {
491
420
let configuration = Configuration :: default ( ) ;
492
421
493
- assert_eq ! ( configuration. external_ip, Some ( IpAddr :: V4 ( Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) ) ) ;
422
+ assert_eq ! ( configuration. core . external_ip, Some ( IpAddr :: V4 ( Ipv4Addr :: new( 0 , 0 , 0 , 0 ) ) ) ) ;
494
423
}
495
424
496
425
#[ test]
0 commit comments