Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration overhaul: version 2 for the configuration toml file (breaking changes) #897

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ axum = { version = "0", features = ["macros"] }
axum-client-ip = "0"
axum-extra = { version = "0", features = ["query"] }
axum-server = { version = "0", features = ["tls-rustls"] }
camino = { version = "1.1.6", features = ["serde"] }
camino = { version = "1.1.6", features = ["serde", "serde1"] }
chrono = { version = "0", default-features = false, features = ["clock"] }
clap = { version = "4", features = ["derive", "env"] }
crossbeam-skiplist = "0.1"
Expand Down
4 changes: 2 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ RUN ["/busybox/cp", "-sp", "/busybox/sh","/busybox/cat","/busybox/ls","/busybox/
COPY --from=gcc --chmod=0555 /usr/local/bin/su-exec /bin/su-exec

ARG TORRUST_TRACKER_CONFIG_TOML_PATH="/etc/torrust/tracker/tracker.toml"
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER="Sqlite3"
ARG TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER="Sqlite3"
ARG USER_ID=1000
ARG UDP_PORT=6969
ARG HTTP_PORT=7070
ARG API_PORT=1212
ARG HEALTH_CHECK_API_PORT=1313

ENV TORRUST_TRACKER_CONFIG_TOML_PATH=${TORRUST_TRACKER_CONFIG_TOML_PATH}
ENV TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER}
ENV TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER}
ENV USER_ID=${USER_ID}
ENV UDP_PORT=${UDP_PORT}
ENV HTTP_PORT=${HTTP_PORT}
Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: torrust-tracker:release
tty: true
environment:
- TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_DB_DRIVER:-MySQL}
- TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER=${TORRUST_TRACKER_CONFIG_OVERRIDE_CORE__DATABASE__DRIVER:-MySQL}
- TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN=${TORRUST_TRACKER_CONFIG_OVERRIDE_HTTP_API__ACCESS_TOKENS__ADMIN:-MyAccessToken}
networks:
- server_side
Expand Down
6 changes: 4 additions & 2 deletions docs/benchmarking.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ cargo build --release -p aquatic_udp_load_test
Run the tracker with UDP service enabled and other services disabled and set log level to `error`.

```toml
[logging]
log_level = "error"

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

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

```toml
[logging]
log_level = "error"

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

```console
Expand Down
30 changes: 15 additions & 15 deletions docs/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ The following environmental variables can be set:

- `TORRUST_TRACKER_CONFIG_TOML_PATH` - The in-container path to the tracker configuration file, (default: `"/etc/torrust/tracker/tracker.toml"`).
- `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.
- `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.
- `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.
- `TORRUST_TRACKER_CONFIG_TOML` - Load config from this environmental variable instead from a file, (i.e: `TORRUST_TRACKER_CONFIG_TOML=$(cat tracker-tracker.toml)`).
- `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`).
- `UDP_PORT` - The port for the UDP tracker. This should match the port used in the configuration, (default `6969`).
Expand Down Expand Up @@ -243,8 +243,9 @@ podman run -it \
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:

```toml
db_driver = "MySQL"
db_path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
[core.database]
driver = "MySQL"
path = "mysql://db_user:db_user_secret_password@mysql:3306/torrust_tracker"
```

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

```s
storage/tracker/lib/tls
├── localhost.crt
└── localhost.key
├── localhost.crt
└── localhost.key
storage/http_api/lib/tls
├── localhost.crt
└── localhost.key
```

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

```toml
[http_trackers.tsl_config]
ssl_cert_path = "./storage/tracker/lib/tls/localhost.crt"
ssl_key_path = "./storage/tracker/lib/tls/localhost.key"

[[http_trackers]]
# ...
ssl_enabled = true
# ...

[http_api]
# ...
ssl_enabled = true
# ...

[http_api.tsl_config]
ssl_cert_path = "./storage/http_api/lib/tls/localhost.crt"
ssl_key_path = "./storage/http_api/lib/tls/localhost.key"
```

> NOTE: you can enable it independently for each HTTP tracker or the API.
Expand Down
2 changes: 1 addition & 1 deletion packages/configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version.workspace = true
version.workspace = true

[dependencies]
camino = { version = "1.1.6", features = ["serde"] }
camino = { version = "1.1.6", features = ["serde", "serde1"] }
derive_more = "0"
figment = { version = "0.10.18", features = ["env", "test", "toml"] }
serde = { version = "1", features = ["derive"] }
Expand Down
65 changes: 53 additions & 12 deletions packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::Arc;
use camino::Utf8PathBuf;
use derive_more::Constructor;
use serde::{Deserialize, Serialize};
use serde_with::{serde_as, NoneAsEmptyString};
use serde_with::serde_as;
use thiserror::Error;
use torrust_tracker_located_error::{DynError, LocatedError};

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

pub type AccessTokens = HashMap<String, String>;

#[derive(Copy, Clone, Debug, PartialEq, Constructor)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Constructor)]
pub struct TrackerPolicy {
pub remove_peerless_torrents: bool,
// Cleanup job configuration
/// Maximum time in seconds that a peer can be inactive before being
/// considered an inactive peer. If a peer is inactive for more than this
/// time, it will be removed from the torrent peer list.
#[serde(default = "TrackerPolicy::default_max_peer_timeout")]
pub max_peer_timeout: u32,

/// If enabled the tracker will persist the number of completed downloads.
/// That's how many times a torrent has been downloaded completely.
#[serde(default = "TrackerPolicy::default_persistent_torrent_completed_stat")]
pub persistent_torrent_completed_stat: bool,

/// If enabled, the tracker will remove torrents that have no peers.
/// The clean up torrent job runs every `inactive_peer_cleanup_interval`
/// seconds and it removes inactive peers. Eventually, the peer list of a
/// torrent could be empty and the torrent will be removed if this option is
/// enabled.
#[serde(default = "TrackerPolicy::default_remove_peerless_torrents")]
pub remove_peerless_torrents: bool,
}

impl Default for TrackerPolicy {
fn default() -> Self {
Self {
max_peer_timeout: Self::default_max_peer_timeout(),
persistent_torrent_completed_stat: Self::default_persistent_torrent_completed_stat(),
remove_peerless_torrents: Self::default_remove_peerless_torrents(),
}
}
}

impl TrackerPolicy {
fn default_max_peer_timeout() -> u32 {
900
}

fn default_persistent_torrent_completed_stat() -> bool {
false
}

fn default_remove_peerless_torrents() -> bool {
true
}
}

/// Information required for loading config
Expand Down Expand Up @@ -86,7 +126,7 @@ impl Info {
}

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

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

Expand Down Expand Up @@ -173,24 +215,23 @@ impl From<figment::Error> for Error {
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Default)]
pub struct TslConfig {
/// Path to the SSL certificate file.
#[serde_as(as = "NoneAsEmptyString")]
#[serde(default = "TslConfig::default_ssl_cert_path")]
pub ssl_cert_path: Option<Utf8PathBuf>,
pub ssl_cert_path: Utf8PathBuf,

/// Path to the SSL key file.
#[serde_as(as = "NoneAsEmptyString")]
#[serde(default = "TslConfig::default_ssl_key_path")]
pub ssl_key_path: Option<Utf8PathBuf>,
pub ssl_key_path: Utf8PathBuf,
}

impl TslConfig {
#[allow(clippy::unnecessary_wraps)]
fn default_ssl_cert_path() -> Option<Utf8PathBuf> {
Some(Utf8PathBuf::new())
fn default_ssl_cert_path() -> Utf8PathBuf {
Utf8PathBuf::new()
}

#[allow(clippy::unnecessary_wraps)]
fn default_ssl_key_path() -> Option<Utf8PathBuf> {
Some(Utf8PathBuf::new())
fn default_ssl_key_path() -> Utf8PathBuf {
Utf8PathBuf::new()
}
}

Expand Down
Loading
Loading