Skip to content

Commit 06ad5da

Browse files
committed
feat!: [torrust#878] remove enabled fields in config
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.
1 parent 50bef25 commit 06ad5da

23 files changed

+156
-189
lines changed

docs/benchmarking.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Run the tracker with UDP service enabled and other services disabled and set log
3333
log_level = "error"
3434

3535
[[udp_trackers]]
36-
enabled = true
36+
bind_address = "0.0.0.0:6969"
3737
```
3838

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

170170
[[udp_trackers]]
171-
enabled = true
171+
bind_address = "0.0.0.0:6969"
172172
```
173173

174174
```console

packages/configuration/src/v1/http_tracker.rs

-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ use crate::TslConfig;
99
#[serde_as]
1010
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
1111
pub struct HttpTracker {
12-
/// Weather the HTTP tracker is enabled or not.
13-
#[serde(default = "HttpTracker::default_enabled")]
14-
pub enabled: bool,
15-
1612
/// The address the tracker will bind to.
1713
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
1814
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
@@ -28,18 +24,13 @@ pub struct HttpTracker {
2824
impl Default for HttpTracker {
2925
fn default() -> Self {
3026
Self {
31-
enabled: Self::default_enabled(),
3227
bind_address: Self::default_bind_address(),
3328
tsl_config: Self::default_tsl_config(),
3429
}
3530
}
3631
}
3732

3833
impl HttpTracker {
39-
fn default_enabled() -> bool {
40-
false
41-
}
42-
4334
fn default_bind_address() -> SocketAddr {
4435
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 7070)
4536
}

packages/configuration/src/v1/mod.rs

+5-42
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,7 @@
220220
//! external_ip = "0.0.0.0"
221221
//! on_reverse_proxy = false
222222
//!
223-
//! [[udp_trackers]]
224-
//! enabled = false
225-
//! bind_address = "0.0.0.0:6969"
226-
//!
227-
//! [[http_trackers]]
228-
//! enabled = false
229-
//! bind_address = "0.0.0.0:7070"
230-
//!
231223
//! [http_api]
232-
//! enabled = true
233224
//! bind_address = "127.0.0.1:1212"
234225
//!
235226
//! [http_api.access_tokens]
@@ -267,7 +258,7 @@ const CONFIG_OVERRIDE_PREFIX: &str = "TORRUST_TRACKER_CONFIG_OVERRIDE_";
267258
const CONFIG_OVERRIDE_SEPARATOR: &str = "__";
268259

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

283274
/// The list of HTTP trackers the tracker is running. Each HTTP tracker
284275
/// represents a HTTP server that the tracker is running and it has its own
285276
/// configuration.
286-
pub http_trackers: Vec<HttpTracker>,
277+
pub http_trackers: Option<Vec<HttpTracker>>,
287278

288279
/// The HTTP API configuration.
289-
pub http_api: HttpApi,
280+
pub http_api: Option<HttpApi>,
290281

291282
/// The Health Check API configuration.
292283
pub health_check_api: HealthCheckApi,
293284
}
294285

295-
impl Default for Configuration {
296-
fn default() -> Self {
297-
Self {
298-
logging: Logging::default(),
299-
core: Core::default(),
300-
udp_trackers: vec![UdpTracker::default()],
301-
http_trackers: vec![HttpTracker::default()],
302-
http_api: HttpApi::default(),
303-
health_check_api: HealthCheckApi::default(),
304-
}
305-
}
306-
}
307-
308286
impl Configuration {
309287
/// Returns the tracker public IP address id defined in the configuration,
310288
/// and `None` otherwise.
@@ -408,21 +386,6 @@ mod tests {
408386
external_ip = "0.0.0.0"
409387
on_reverse_proxy = false
410388
411-
[[udp_trackers]]
412-
enabled = false
413-
bind_address = "0.0.0.0:6969"
414-
415-
[[http_trackers]]
416-
enabled = false
417-
bind_address = "0.0.0.0:7070"
418-
419-
[http_api]
420-
enabled = true
421-
bind_address = "127.0.0.1:1212"
422-
423-
[http_api.access_tokens]
424-
admin = "MyAccessToken"
425-
426389
[health_check_api]
427390
bind_address = "127.0.0.1:1313"
428391
"#
@@ -556,7 +519,7 @@ mod tests {
556519
let configuration = Configuration::load(&info).expect("Could not load configuration from file");
557520

558521
assert_eq!(
559-
configuration.http_api.access_tokens.get("admin"),
522+
configuration.http_api.unwrap().access_tokens.get("admin"),
560523
Some("NewToken".to_owned()).as_ref()
561524
);
562525

packages/configuration/src/v1/tracker_api.rs

-9
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ pub type AccessTokens = HashMap<String, String>;
1212
#[serde_as]
1313
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
1414
pub struct HttpApi {
15-
/// Weather the HTTP API is enabled or not.
16-
#[serde(default = "HttpApi::default_enabled")]
17-
pub enabled: bool,
18-
1915
/// The address the tracker will bind to.
2016
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
2117
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
@@ -38,7 +34,6 @@ pub struct HttpApi {
3834
impl Default for HttpApi {
3935
fn default() -> Self {
4036
Self {
41-
enabled: Self::default_enabled(),
4237
bind_address: Self::default_bind_address(),
4338
tsl_config: Self::default_tsl_config(),
4439
access_tokens: Self::default_access_tokens(),
@@ -47,10 +42,6 @@ impl Default for HttpApi {
4742
}
4843

4944
impl HttpApi {
50-
fn default_enabled() -> bool {
51-
true
52-
}
53-
5445
fn default_bind_address() -> SocketAddr {
5546
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1212)
5647
}

packages/configuration/src/v1/udp_tracker.rs

-8
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ use serde::{Deserialize, Serialize};
44

55
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
66
pub struct UdpTracker {
7-
/// Weather the UDP tracker is enabled or not.
8-
#[serde(default = "UdpTracker::default_enabled")]
9-
pub enabled: bool,
107
/// The address the tracker will bind to.
118
/// The format is `ip:port`, for example `0.0.0.0:6969`. If you want to
129
/// listen to all interfaces, use `0.0.0.0`. If you want the operating
@@ -17,17 +14,12 @@ pub struct UdpTracker {
1714
impl Default for UdpTracker {
1815
fn default() -> Self {
1916
Self {
20-
enabled: Self::default_enabled(),
2117
bind_address: Self::default_bind_address(),
2218
}
2319
}
2420
}
2521

2622
impl UdpTracker {
27-
fn default_enabled() -> bool {
28-
false
29-
}
30-
3123
fn default_bind_address() -> SocketAddr {
3224
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 6969)
3325
}

packages/test-helpers/src/configuration.rs

+26-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::env;
33
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
44

5-
use torrust_tracker_configuration::{Configuration, LogLevel};
5+
use torrust_tracker_configuration::{Configuration, HttpApi, HttpTracker, LogLevel, UdpTracker};
66
use torrust_tracker_primitives::TrackerMode;
77

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

3434
// Ephemeral socket address for API
3535
let api_port = 0u16;
36-
config.http_api.enabled = true;
37-
config.http_api.bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), api_port);
36+
config.http_api = Some(HttpApi {
37+
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), api_port),
38+
..Default::default()
39+
});
3840

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

4345
// Ephemeral socket address for UDP tracker
4446
let udp_port = 0u16;
45-
config.udp_trackers[0].enabled = true;
46-
config.udp_trackers[0].bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), udp_port);
47+
config.udp_trackers = Some(vec![UdpTracker {
48+
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), udp_port),
49+
}]);
4750

4851
// Ephemeral socket address for HTTP tracker
4952
let http_port = 0u16;
50-
config.http_trackers[0].enabled = true;
51-
config.http_trackers[0].bind_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), http_port);
53+
config.http_trackers = Some(vec![HttpTracker {
54+
bind_address: SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), http_port),
55+
tsl_config: None,
56+
}]);
5257

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

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

140-
cfg.http_api.bind_address.clone_from(&ipv6);
141-
cfg.http_trackers[0].bind_address.clone_from(&ipv6);
142-
cfg.udp_trackers[0].bind_address = ipv6;
145+
if let Some(ref mut http_api) = cfg.http_api {
146+
http_api.bind_address.clone_from(&ipv6);
147+
};
148+
149+
if let Some(ref mut http_trackers) = cfg.http_trackers {
150+
http_trackers[0].bind_address.clone_from(&ipv6);
151+
}
152+
153+
if let Some(ref mut udp_trackers) = cfg.udp_trackers {
154+
udp_trackers[0].bind_address.clone_from(&ipv6);
155+
}
143156

144157
cfg
145158
}
@@ -149,9 +162,9 @@ pub fn ephemeral_ipv6() -> Configuration {
149162
pub fn ephemeral_with_no_services() -> Configuration {
150163
let mut cfg = ephemeral();
151164

152-
cfg.http_api.enabled = false;
153-
cfg.http_trackers[0].enabled = false;
154-
cfg.udp_trackers[0].enabled = false;
165+
cfg.http_api = None;
166+
cfg.http_trackers = None;
167+
cfg.udp_trackers = None;
155168

156169
cfg
157170
}

share/default/config/tracker.container.mysql.toml

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
driver = "MySQL"
33
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
44

5-
[[http_trackers]]
6-
bind_address = "0.0.0.0:7070"
7-
enabled = true
5+
# Uncomment to enable services
6+
7+
#[[udp_trackers]]
8+
#bind_address = "0.0.0.0:6969"
9+
10+
#[[http_trackers]]
11+
#bind_address = "0.0.0.0:7070"
12+
13+
#[http_api]
14+
#bind_address = "0.0.0.0:1212"
15+
16+
#[http_api.access_tokens]
17+
#admin = "MyAccessToken"
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
[core.database]
22
path = "/var/lib/torrust/tracker/database/sqlite3.db"
3+
4+
# Uncomment to enable services
5+
6+
#[[udp_trackers]]
7+
#bind_address = "0.0.0.0:6969"
8+
9+
#[[http_trackers]]
10+
#bind_address = "0.0.0.0:7070"
11+
12+
#[http_api]
13+
#bind_address = "0.0.0.0:1212"
14+
15+
#[http_api.access_tokens]
16+
#admin = "MyAccessToken"
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[[udp_trackers]]
2-
enabled = true
2+
bind_address = "0.0.0.0:6969"
33

44
[[http_trackers]]
5-
enabled = true
5+
bind_address = "0.0.0.0:7070"
6+
7+
[http_api]
8+
bind_address = "0.0.0.0:1212"
9+
10+
[http_api.access_tokens]
11+
admin = "MyAccessToken"

share/default/config/tracker.e2e.container.sqlite3.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
path = "/var/lib/torrust/tracker/database/sqlite3.db"
33

44
[[udp_trackers]]
5-
enabled = true
5+
bind_address = "0.0.0.0:6969"
66

77
[[http_trackers]]
8-
enabled = true
8+
bind_address = "0.0.0.0:7070"
9+
10+
[http_api]
11+
bind_address = "0.0.0.0:1212"
12+
13+
[http_api.access_tokens]
14+
admin = "MyAccessToken"
915

1016
[health_check_api]
1117
# Must be bound to wildcard IP to be accessible from outside the container

share/default/config/tracker.udp.benchmarking.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,4 @@ remove_peerless_torrents = false
66
tracker_usage_statistics = false
77

88
[[udp_trackers]]
9-
enabled = true
10-
11-
[http_api]
12-
enabled = false
9+
bind_address = "0.0.0.0:6969"

0 commit comments

Comments
 (0)