@@ -236,8 +236,7 @@ pub mod tracker_api;
236
236
pub mod udp_tracker;
237
237
238
238
use std:: fs;
239
- use std:: net:: IpAddr ;
240
- use std:: str:: FromStr ;
239
+ use std:: net:: { IpAddr , Ipv4Addr } ;
241
240
242
241
use figment:: providers:: { Env , Format , Serialized , Toml } ;
243
242
use figment:: Figment ;
@@ -248,15 +247,15 @@ use self::health_check_api::HealthCheckApi;
248
247
use self :: http_tracker:: HttpTracker ;
249
248
use self :: tracker_api:: HttpApi ;
250
249
use self :: udp_tracker:: UdpTracker ;
251
- use crate :: { AnnouncePolicy , Error , Info } ;
250
+ use crate :: { AnnouncePolicy , Error , Info , LogLevel } ;
252
251
253
252
/// Core configuration for the tracker.
254
253
#[ allow( clippy:: struct_excessive_bools) ]
255
254
#[ derive( Serialize , Deserialize , PartialEq , Eq , Debug ) ]
256
255
pub struct Configuration {
257
256
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
258
257
/// `Debug` and `Trace`. Default is `Info`.
259
- pub log_level : Option < String > ,
258
+ pub log_level : Option < LogLevel > ,
260
259
/// Tracker mode. See [`TrackerMode`] for more information.
261
260
pub mode : TrackerMode ,
262
261
@@ -284,7 +283,7 @@ pub struct Configuration {
284
283
/// is using a loopback IP address, the tracker assumes that the peer is
285
284
/// in the same network as the tracker and will use the tracker's IP
286
285
/// address instead.
287
- pub external_ip : Option < String > ,
286
+ pub external_ip : Option < IpAddr > ,
288
287
/// Weather the tracker should collect statistics about tracker usage.
289
288
/// If enabled, the tracker will collect statistics like the number of
290
289
/// connections handled, the number of announce requests handled, etc.
@@ -330,15 +329,15 @@ impl Default for Configuration {
330
329
let announce_policy = AnnouncePolicy :: default ( ) ;
331
330
332
331
let mut configuration = Configuration {
333
- log_level : Option :: from ( String :: from ( "info" ) ) ,
332
+ log_level : Some ( LogLevel :: Info ) ,
334
333
mode : TrackerMode :: Public ,
335
334
db_driver : DatabaseDriver :: Sqlite3 ,
336
335
db_path : String :: from ( "./storage/tracker/lib/database/sqlite3.db" ) ,
337
336
announce_interval : announce_policy. interval ,
338
337
min_announce_interval : announce_policy. interval_min ,
339
338
max_peer_timeout : 900 ,
340
339
on_reverse_proxy : false ,
341
- external_ip : Some ( String :: from ( "0.0.0.0" ) ) ,
340
+ external_ip : Some ( IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) ) ,
342
341
tracker_usage_statistics : true ,
343
342
persistent_torrent_completed_stat : false ,
344
343
inactive_peer_cleanup_interval : 600 ,
@@ -363,13 +362,7 @@ impl Configuration {
363
362
/// and `None` otherwise.
364
363
#[ must_use]
365
364
pub fn get_ext_ip ( & self ) -> Option < IpAddr > {
366
- match & self . external_ip {
367
- None => None ,
368
- Some ( external_ip) => match IpAddr :: from_str ( external_ip) {
369
- Ok ( external_ip) => Some ( external_ip) ,
370
- Err ( _) => None ,
371
- } ,
372
- }
365
+ self . external_ip . as_ref ( ) . map ( |external_ip| * external_ip)
373
366
}
374
367
375
368
/// Saves the default configuration at the given path.
@@ -432,6 +425,8 @@ impl Configuration {
432
425
#[ cfg( test) ]
433
426
mod tests {
434
427
428
+ use std:: net:: { IpAddr , Ipv4Addr } ;
429
+
435
430
use crate :: v1:: Configuration ;
436
431
use crate :: Info ;
437
432
@@ -495,7 +490,7 @@ mod tests {
495
490
fn configuration_should_contain_the_external_ip ( ) {
496
491
let configuration = Configuration :: default ( ) ;
497
492
498
- assert_eq ! ( configuration. external_ip, Some ( String :: from ( "0.0.0.0" ) ) ) ;
493
+ assert_eq ! ( configuration. external_ip, Some ( IpAddr :: V4 ( Ipv4Addr :: new ( 0 , 0 , 0 , 0 ) ) ) ) ;
499
494
}
500
495
501
496
#[ test]
0 commit comments