forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcore.rs
60 lines (54 loc) · 2.12 KB
/
core.rs
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
55
56
57
58
59
60
//! Validated configuration for the tracker core.
//!
//! This configuration is a first level of validation that can be perform
//! statically without running the service.
use serde::{Deserialize, Serialize};
use thiserror::Error;
use torrust_tracker_primitives::{DatabaseDriver, TrackerMode};
use crate::Configuration;
/// Errors that can occur when validating the plain configuration.
#[derive(Error, Debug, PartialEq)]
pub enum ValidationError {
/// Invalid bind address.
#[error("Invalid log level, got: {log_level}")]
InvalidLogLevel { log_level: String },
}
/// Configuration for each HTTP tracker.
#[allow(clippy::struct_excessive_bools)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct Config {
log_level: Option<String>, // todo: use enum
mode: TrackerMode,
db_driver: DatabaseDriver,
db_path: String, // todo: use Path
announce_interval: u32,
min_announce_interval: u32,
on_reverse_proxy: bool,
external_ip: Option<String>, // todo: use IpAddr
tracker_usage_statistics: bool,
persistent_torrent_completed_stat: bool,
max_peer_timeout: u32,
inactive_peer_cleanup_interval: u64,
remove_peerless_torrents: bool,
}
impl TryFrom<Configuration> for Config {
type Error = ValidationError;
fn try_from(config: Configuration) -> Result<Self, Self::Error> {
// todo: validation
Ok(Self {
log_level: config.log_level,
mode: config.mode,
db_driver: config.db_driver,
db_path: config.db_path,
announce_interval: config.announce_interval,
min_announce_interval: config.min_announce_interval,
on_reverse_proxy: config.on_reverse_proxy,
external_ip: config.external_ip,
tracker_usage_statistics: config.tracker_usage_statistics,
persistent_torrent_completed_stat: config.persistent_torrent_completed_stat,
max_peer_timeout: config.max_peer_timeout,
inactive_peer_cleanup_interval: config.inactive_peer_cleanup_interval,
remove_peerless_torrents: config.remove_peerless_torrents,
})
}
}