Skip to content

Commit

Permalink
feat!: [torrust#878] remove enabled fields in config
Browse files Browse the repository at this point in the history
By default all services are disabled. If the service section is missing
in the TOML config file it means the service is disabled.

From:

```toml
[[udp_trackers]]
enabled = false
bind_address = "0.0.0.0:6969"
```

To:

```toml
```

The `http_api` section has been disabled by default becuase there is no
way to override it to disable it, if it's enabled by default. You nned
to explicitly enabled the API now.
  • Loading branch information
josecelano authored and da2ce7 committed Jun 25, 2024
1 parent 6d07cf4 commit 855bd4f
Show file tree
Hide file tree
Showing 23 changed files with 417 additions and 199 deletions.
4 changes: 2 additions & 2 deletions docs/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Run the tracker with UDP service enabled and other services disabled and set log
log_level = "error"

[[udp_trackers]]
enabled = true
bind_address = "0.0.0.0:6969"
```

Build and run the tracker:
Expand Down Expand Up @@ -168,7 +168,7 @@ Run the tracker with UDP service enabled and other services disabled and set log
log_level = "error"

[[udp_trackers]]
enabled = true
bind_address = "0.0.0.0:6969"
```

```console
Expand Down
9 changes: 0 additions & 9 deletions packages/configuration/src/v1/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ use crate::TslConfig;
#[serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct HttpTracker {
/// Weather the HTTP tracker is enabled or not.
#[serde(default = "HttpTracker::default_enabled")]
pub enabled: bool,

/// The address the tracker will bind to.
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
Expand All @@ -28,18 +24,13 @@ pub struct HttpTracker {
impl Default for HttpTracker {
fn default() -> Self {
Self {
enabled: Self::default_enabled(),
bind_address: Self::default_bind_address(),
tsl_config: Self::default_tsl_config(),
}
}
}

impl HttpTracker {
fn default_enabled() -> bool {
false
}

fn default_bind_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 7070)
}
Expand Down
47 changes: 5 additions & 42 deletions packages/configuration/src/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,7 @@
//! external_ip = "0.0.0.0"
//! on_reverse_proxy = false
//!
//! [[udp_trackers]]
//! enabled = false
//! bind_address = "0.0.0.0:6969"
//!
//! [[http_trackers]]
//! enabled = false
//! bind_address = "0.0.0.0:7070"
//!
//! [http_api]
//! enabled = true
//! bind_address = "127.0.0.1:1212"
//!
//! [http_api.access_tokens]
Expand Down Expand Up @@ -267,7 +258,7 @@ const CONFIG_OVERRIDE_PREFIX: &str = "TORRUST_TRACKER_CONFIG_OVERRIDE_";
const CONFIG_OVERRIDE_SEPARATOR: &str = "__";

/// Core configuration for the tracker.
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Default)]
pub struct Configuration {
/// Logging configuration
pub logging: Logging,
Expand All @@ -278,33 +269,20 @@ pub struct Configuration {
/// The list of UDP trackers the tracker is running. Each UDP tracker
/// represents a UDP server that the tracker is running and it has its own
/// configuration.
pub udp_trackers: Vec<UdpTracker>,
pub udp_trackers: Option<Vec<UdpTracker>>,

/// The list of HTTP trackers the tracker is running. Each HTTP tracker
/// represents a HTTP server that the tracker is running and it has its own
/// configuration.
pub http_trackers: Vec<HttpTracker>,
pub http_trackers: Option<Vec<HttpTracker>>,

/// The HTTP API configuration.
pub http_api: HttpApi,
pub http_api: Option<HttpApi>,

/// The Health Check API configuration.
pub health_check_api: HealthCheckApi,
}

impl Default for Configuration {
fn default() -> Self {
Self {
logging: Logging::default(),
core: Core::default(),
udp_trackers: vec![UdpTracker::default()],
http_trackers: vec![HttpTracker::default()],
http_api: HttpApi::default(),
health_check_api: HealthCheckApi::default(),
}
}
}

impl Configuration {
/// Returns the tracker public IP address id defined in the configuration,
/// and `None` otherwise.
Expand Down Expand Up @@ -408,21 +386,6 @@ mod tests {
external_ip = "0.0.0.0"
on_reverse_proxy = false
[[udp_trackers]]
enabled = false
bind_address = "0.0.0.0:6969"
[[http_trackers]]
enabled = false
bind_address = "0.0.0.0:7070"
[http_api]
enabled = true
bind_address = "127.0.0.1:1212"
[http_api.access_tokens]
admin = "MyAccessToken"
[health_check_api]
bind_address = "127.0.0.1:1313"
"#
Expand Down Expand Up @@ -556,7 +519,7 @@ mod tests {
let configuration = Configuration::load(&info).expect("Could not load configuration from file");

assert_eq!(
configuration.http_api.access_tokens.get("admin"),
configuration.http_api.unwrap().access_tokens.get("admin"),
Some("NewToken".to_owned()).as_ref()
);

Expand Down
9 changes: 0 additions & 9 deletions packages/configuration/src/v1/tracker_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ pub type AccessTokens = HashMap<String, String>;
#[serde_as]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct HttpApi {
/// Weather the HTTP API is enabled or not.
#[serde(default = "HttpApi::default_enabled")]
pub enabled: bool,

/// The address the tracker will bind to.
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
Expand All @@ -38,7 +34,6 @@ pub struct HttpApi {
impl Default for HttpApi {
fn default() -> Self {
Self {
enabled: Self::default_enabled(),
bind_address: Self::default_bind_address(),
tsl_config: Self::default_tsl_config(),
access_tokens: Self::default_access_tokens(),
Expand All @@ -47,10 +42,6 @@ impl Default for HttpApi {
}

impl HttpApi {
fn default_enabled() -> bool {
true
}

fn default_bind_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1212)
}
Expand Down
8 changes: 0 additions & 8 deletions packages/configuration/src/v1/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct UdpTracker {
/// Weather the UDP tracker is enabled or not.
#[serde(default = "UdpTracker::default_enabled")]
pub enabled: bool,
/// The address the tracker will bind to.
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
Expand All @@ -17,17 +14,12 @@ pub struct UdpTracker {
impl Default for UdpTracker {
fn default() -> Self {
Self {
enabled: Self::default_enabled(),
bind_address: Self::default_bind_address(),
}
}
}

impl UdpTracker {
fn default_enabled() -> bool {
false
}

fn default_bind_address() -> SocketAddr {
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 6969)
}
Expand Down
39 changes: 26 additions & 13 deletions packages/test-helpers/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::env;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};

use torrust_tracker_configuration::{Configuration, LogLevel};
use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, LogLevel, UdpTracker};
use torrust_tracker_primitives::TrackerMode;

use crate::random;
Expand Down Expand Up @@ -33,22 +33,27 @@ pub fn ephemeral() -> Configuration {

// Ephemeral socket address for API
let api_port = 0u16;
config.http_api.enabled = true;
config.http_api.bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), api_port);
config.http_api = Some(HttpApi {
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), api_port),
..Default::default()
});

// Ephemeral socket address for Health Check API
let health_check_api_port = 0u16;
config.health_check_api.bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), health_check_api_port);

// Ephemeral socket address for UDP tracker
let udp_port = 0u16;
config.udp_trackers[0].enabled = true;
config.udp_trackers[0].bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), udp_port);
config.udp_trackers = Some(vec![UdpTracker {
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), udp_port),
}]);

// Ephemeral socket address for HTTP tracker
let http_port = 0u16;
config.http_trackers[0].enabled = true;
config.http_trackers[0].bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), http_port);
config.http_trackers = Some(vec![HttpTracker {
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), http_port),
tsl_config: None,
}]);

// Ephemeral sqlite database
let temp_directory = env::temp_dir();
Expand Down Expand Up @@ -137,9 +142,17 @@ pub fn ephemeral_ipv6() -> Configuration {

let ipv6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)), 0);

cfg.http_api.bind_address.clone_from(&ipv6);
cfg.http_trackers[0].bind_address.clone_from(&ipv6);
cfg.udp_trackers[0].bind_address = ipv6;
if let Some(ref mut http_api) = cfg.http_api {
http_api.bind_address.clone_from(&ipv6);
};

if let Some(ref mut http_trackers) = cfg.http_trackers {
http_trackers[0].bind_address.clone_from(&ipv6);
}

if let Some(ref mut udp_trackers) = cfg.udp_trackers {
udp_trackers[0].bind_address.clone_from(&ipv6);
}

cfg
}
Expand All @@ -149,9 +162,9 @@ pub fn ephemeral_ipv6() -> Configuration {
pub fn ephemeral_with_no_services() -> Configuration {
let mut cfg = ephemeral();

cfg.http_api.enabled = false;
cfg.http_trackers[0].enabled = false;
cfg.udp_trackers[0].enabled = false;
cfg.http_api = None;
cfg.http_trackers = None;
cfg.udp_trackers = None;

cfg
}
16 changes: 13 additions & 3 deletions share/default/config/tracker.container.mysql.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
driver = "MySQL"
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"

[[http_trackers]]
bind_address = "0.0.0.0:7070"
enabled = true
# Uncomment to enable services

#[[udp_trackers]]
#bind_address = "0.0.0.0:6969"

#[[http_trackers]]
#bind_address = "0.0.0.0:7070"

#[http_api]
#bind_address = "0.0.0.0:1212"

#[http_api.access_tokens]
#admin = "MyAccessToken"
14 changes: 14 additions & 0 deletions share/default/config/tracker.container.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
[core.database]
path = "/var/lib/torrust/tracker/database/sqlite3.db"

# Uncomment to enable services

#[[udp_trackers]]
#bind_address = "0.0.0.0:6969"

#[[http_trackers]]
#bind_address = "0.0.0.0:7070"

#[http_api]
#bind_address = "0.0.0.0:1212"

#[http_api.access_tokens]
#admin = "MyAccessToken"
10 changes: 8 additions & 2 deletions share/default/config/tracker.development.sqlite3.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[[udp_trackers]]
enabled = true
bind_address = "0.0.0.0:6969"

[[http_trackers]]
enabled = true
bind_address = "0.0.0.0:7070"

[http_api]
bind_address = "0.0.0.0:1212"

[http_api.access_tokens]
admin = "MyAccessToken"
10 changes: 8 additions & 2 deletions share/default/config/tracker.e2e.container.sqlite3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
path = "/var/lib/torrust/tracker/database/sqlite3.db"

[[udp_trackers]]
enabled = true
bind_address = "0.0.0.0:6969"

[[http_trackers]]
enabled = true
bind_address = "0.0.0.0:7070"

[http_api]
bind_address = "0.0.0.0:1212"

[http_api.access_tokens]
admin = "MyAccessToken"

[health_check_api]
# Must be bound to wildcard IP to be accessible from outside the container
Expand Down
5 changes: 1 addition & 4 deletions share/default/config/tracker.udp.benchmarking.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ remove_peerless_torrents = false
tracker_usage_statistics = false

[[udp_trackers]]
enabled = true

[http_api]
enabled = false
bind_address = "0.0.0.0:6969"
Loading

0 comments on commit 855bd4f

Please sign in to comment.