Skip to content

Commit 729739c

Browse files
committed
Merge torrust#897: Configuration overhaul: version 2 for the configuration toml file (breaking changes)
06ad5da feat!: [torrust#878] remove enabled fields in config (Jose Celano) 50bef25 feat: remove ambiguous log entry (Jose Celano) c5cc9fd feat: [torrust#878] extract tsl_config in toml config (Jose Celano) 7b2f757 feat!: [torrust#878] extract tracker_policy section in core config section (Jose Celano) fc046e0 feat!: [torrust#878] extract announce_policy section in core config section (Jose Celano) edc706c feat!: [torrust#878] extract net section in core config section (Jose Celano) 2f94f6c feat!: [torrust#878] extract database section in core config section (Jose Celano) 77dd938 feat!: [torrust#878] make log_level config value mandatory (Jose Celano) ef9461a feat!: [torrust#878] extract logging and core section in toml config files (Jose Celano) Pull request description: Configuration overhaul: version 2 for the configuration TOML file (breaking changes). See the [issue](torrust#878) for a full description of changes. ### Subtasks - [x] make `log_level` mandatory with default `info` value. - [x] extract `logging` and `core` sections. - [x] extract `database` subsection in `core` section. - [x] extract `net` subsection in `core` section. - [x] extract `announce_policy` subsection in `core` section. - [x] extract `tracker_policy` subsection in `core` section. - [x] extract `tsl_config` subsection for `http_trackers` and `http_api`. - [x] remove `enabled` field from services. If the configuration is present, the service is enabled. ACKs for top commit: josecelano: ACK 06ad5da Tree-SHA512: 406a848a6a8dc70d6aef19702823db8304bdddd869b045ac303520962f04918b06de4d8247e409f65869a2aafcef79217b64e4c05c305073e3403e0a824f2f7f
2 parents aa8b787 + 06ad5da commit 729739c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+569
-513
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ axum = { version = "0", features = ["macros"] }
3737
axum-client-ip = "0"
3838
axum-extra = { version = "0", features = ["query"] }
3939
axum-server = { version = "0", features = ["tls-rustls"] }
40-
camino = { version = "1.1.6", features = ["serde"] }
40+
camino = { version = "1.1.6", features = ["serde", "serde1"] }
4141
chrono = { version = "0", default-features = false, features = ["clock"] }
4242
clap = { version = "4", features = ["derive", "env"] }
4343
crossbeam-skiplist = "0.1"

Containerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ RUN ["/busybox/cp", "-sp", "/busybox/sh","/busybox/cat","/busybox/ls","/busybox/
9696
COPY --from=gcc --chmod=0555 /usr/local/bin/su-exec /bin/su-exec
9797

9898
ARG TORRUST_TRACKER_CONFIG_TOML_PATH="/etc/torrust/tracker/tracker.toml"
99-
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3"
99+
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER="Sqlite3"
100100
ARG USER_ID=1000
101101
ARG UDP_PORT=6969
102102
ARG HTTP_PORT=7070
103103
ARG API_PORT=1212
104104
ARG HEALTH_CHECK_API_PORT=1313
105105

106106
ENV TORRUST_TRACKER_CONFIG_TOML_PATH=${TORRUST_TRACKER_CONFIG_TOML_PATH}
107-
ENV TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER}
107+
ENV TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER}
108108
ENV USER_ID=${USER_ID}
109109
ENV UDP_PORT=${UDP_PORT}
110110
ENV HTTP_PORT=${HTTP_PORT}

compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
image: torrust-tracker:release
55
tty: true
66
environment:
7-
- TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER:-MySQL}
7+
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-MySQL}
88
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
99
networks:
1010
- server_side

docs/benchmarking.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ cargo build --release -p aquatic_udp_load_test
2929
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.
3030

3131
```toml
32+
[logging]
3233
log_level = "error"
3334

3435
[[udp_trackers]]
35-
enabled = true
36+
bind_address = "0.0.0.0:6969"
3637
```
3738

3839
Build and run the tracker:
@@ -163,10 +164,11 @@ Announce responses per info hash:
163164
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.
164165

165166
```toml
167+
[logging]
166168
log_level = "error"
167169

168170
[[udp_trackers]]
169-
enabled = true
171+
bind_address = "0.0.0.0:6969"
170172
```
171173

172174
```console

docs/containers.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ The following environmental variables can be set:
149149

150150
- `TORRUST_TRACKER_CONFIG_TOML_PATH` - The in-container path to the tracker configuration file, (default: `"/etc/torrust/tracker/tracker.toml"`).
151151
- `TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN` - Override of the admin token. If set, this value overrides any value set in the config.
152-
- `TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER` - The database type used for the container, (options: `Sqlite3`, `MySQL`, default `Sqlite3`). Please Note: This dose not override the database configuration within the `.toml` config file.
152+
- `TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER` - The database type used for the container, (options: `Sqlite3`, `MySQL`, default `Sqlite3`). Please Note: This dose not override the database configuration within the `.toml` config file.
153153
- `TORRUST_TRACKER_CONFIG_TOML` - Load config from this environmental variable instead from a file, (i.e: `TORRUST_TRACKER_CONFIG_TOML=$(cat tracker-tracker.toml)`).
154154
- `USER_ID` - The user id for the runtime crated `torrust` user. Please Note: This user id should match the ownership of the host-mapped volumes, (default `1000`).
155155
- `UDP_PORT` - The port for the UDP tracker. This should match the port used in the configuration, (default `6969`).
@@ -243,8 +243,9 @@ podman run -it \
243243
The docker-compose configuration includes the MySQL service configuration. If you want to use MySQL instead of SQLite you should verify the `/etc/torrust/tracker/tracker.toml` (i.e `./storage/tracker/etc/tracker.toml`) configuration:
244244

245245
```toml
246-
db_driver = "MySQL"
247-
db_path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
246+
[core.database]
247+
driver = "MySQL"
248+
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
248249
```
249250

250251
### Build and Run:
@@ -329,24 +330,23 @@ The storage folder must contain your certificates:
329330

330331
```s
331332
storage/tracker/lib/tls
332-
├── localhost.crt
333-
└── localhost.key
333+
├── localhost.crt
334+
└── localhost.key
335+
storage/http_api/lib/tls
336+
├── localhost.crt
337+
└── localhost.key
334338
```
335339

336340
You have not enabled it in your `tracker.toml` file:
337341

338342
```toml
343+
[http_trackers.tsl_config]
344+
ssl_cert_path = "./storage/tracker/lib/tls/localhost.crt"
345+
ssl_key_path = "./storage/tracker/lib/tls/localhost.key"
339346

340-
[[http_trackers]]
341-
# ...
342-
ssl_enabled = true
343-
# ...
344-
345-
[http_api]
346-
# ...
347-
ssl_enabled = true
348-
# ...
349-
347+
[http_api.tsl_config]
348+
ssl_cert_path = "./storage/http_api/lib/tls/localhost.crt"
349+
ssl_key_path = "./storage/http_api/lib/tls/localhost.key"
350350
```
351351

352352
> NOTE: you can enable it independently for each HTTP tracker or the API.

packages/configuration/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rust-version.workspace = true
1515
version.workspace = true
1616

1717
[dependencies]
18-
camino = { version = "1.1.6", features = ["serde"] }
18+
camino = { version = "1.1.6", features = ["serde", "serde1"] }
1919
derive_more = "0"
2020
figment = { version = "0.10.18", features = ["env", "test", "toml"] }
2121
serde = { version = "1", features = ["derive"] }

packages/configuration/src/lib.rs

+53-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::sync::Arc;
1313
use camino::Utf8PathBuf;
1414
use derive_more::Constructor;
1515
use serde::{Deserialize, Serialize};
16-
use serde_with::{serde_as, NoneAsEmptyString};
16+
use serde_with::serde_as;
1717
use thiserror::Error;
1818
use torrust_tracker_located_error::{DynError, LocatedError};
1919

@@ -37,11 +37,51 @@ pub type HealthCheckApi = v1::health_check_api::HealthCheckApi;
3737

3838
pub type AccessTokens = HashMap<String, String>;
3939

40-
#[derive(Copy, Clone, Debug, PartialEq, Constructor)]
40+
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Constructor)]
4141
pub struct TrackerPolicy {
42-
pub remove_peerless_torrents: bool,
42+
// Cleanup job configuration
43+
/// Maximum time in seconds that a peer can be inactive before being
44+
/// considered an inactive peer. If a peer is inactive for more than this
45+
/// time, it will be removed from the torrent peer list.
46+
#[serde(default = "TrackerPolicy::default_max_peer_timeout")]
4347
pub max_peer_timeout: u32,
48+
49+
/// If enabled the tracker will persist the number of completed downloads.
50+
/// That's how many times a torrent has been downloaded completely.
51+
#[serde(default = "TrackerPolicy::default_persistent_torrent_completed_stat")]
4452
pub persistent_torrent_completed_stat: bool,
53+
54+
/// If enabled, the tracker will remove torrents that have no peers.
55+
/// The clean up torrent job runs every `inactive_peer_cleanup_interval`
56+
/// seconds and it removes inactive peers. Eventually, the peer list of a
57+
/// torrent could be empty and the torrent will be removed if this option is
58+
/// enabled.
59+
#[serde(default = "TrackerPolicy::default_remove_peerless_torrents")]
60+
pub remove_peerless_torrents: bool,
61+
}
62+
63+
impl Default for TrackerPolicy {
64+
fn default() -> Self {
65+
Self {
66+
max_peer_timeout: Self::default_max_peer_timeout(),
67+
persistent_torrent_completed_stat: Self::default_persistent_torrent_completed_stat(),
68+
remove_peerless_torrents: Self::default_remove_peerless_torrents(),
69+
}
70+
}
71+
}
72+
73+
impl TrackerPolicy {
74+
fn default_max_peer_timeout() -> u32 {
75+
900
76+
}
77+
78+
fn default_persistent_torrent_completed_stat() -> bool {
79+
false
80+
}
81+
82+
fn default_remove_peerless_torrents() -> bool {
83+
true
84+
}
4585
}
4686

4787
/// Information required for loading config
@@ -86,7 +126,7 @@ impl Info {
86126
}
87127

88128
/// Announce policy
89-
#[derive(PartialEq, Eq, Debug, Clone, Copy, Constructor)]
129+
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Copy, Constructor)]
90130
pub struct AnnouncePolicy {
91131
/// Interval in seconds that the client should wait between sending regular
92132
/// announce requests to the tracker.
@@ -99,6 +139,7 @@ pub struct AnnouncePolicy {
99139
/// client's initial request. It serves as a guideline for clients to know
100140
/// how often they should contact the tracker for updates on the peer list,
101141
/// while ensuring that the tracker is not overwhelmed with requests.
142+
#[serde(default = "AnnouncePolicy::default_interval")]
102143
pub interval: u32,
103144

104145
/// Minimum announce interval. Clients must not reannounce more frequently
@@ -112,6 +153,7 @@ pub struct AnnouncePolicy {
112153
/// value to prevent sending too many requests in a short period, which
113154
/// could lead to excessive load on the tracker or even getting banned by
114155
/// the tracker for not adhering to the rules.
156+
#[serde(default = "AnnouncePolicy::default_interval_min")]
115157
pub interval_min: u32,
116158
}
117159

@@ -173,24 +215,23 @@ impl From<figment::Error> for Error {
173215
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Default)]
174216
pub struct TslConfig {
175217
/// Path to the SSL certificate file.
176-
#[serde_as(as = "NoneAsEmptyString")]
177218
#[serde(default = "TslConfig::default_ssl_cert_path")]
178-
pub ssl_cert_path: Option<Utf8PathBuf>,
219+
pub ssl_cert_path: Utf8PathBuf,
220+
179221
/// Path to the SSL key file.
180-
#[serde_as(as = "NoneAsEmptyString")]
181222
#[serde(default = "TslConfig::default_ssl_key_path")]
182-
pub ssl_key_path: Option<Utf8PathBuf>,
223+
pub ssl_key_path: Utf8PathBuf,
183224
}
184225

185226
impl TslConfig {
186227
#[allow(clippy::unnecessary_wraps)]
187-
fn default_ssl_cert_path() -> Option<Utf8PathBuf> {
188-
Some(Utf8PathBuf::new())
228+
fn default_ssl_cert_path() -> Utf8PathBuf {
229+
Utf8PathBuf::new()
189230
}
190231

191232
#[allow(clippy::unnecessary_wraps)]
192-
fn default_ssl_key_path() -> Option<Utf8PathBuf> {
193-
Some(Utf8PathBuf::new())
233+
fn default_ssl_key_path() -> Utf8PathBuf {
234+
Utf8PathBuf::new()
194235
}
195236
}
196237

0 commit comments

Comments
 (0)