Skip to content

Commit 29d87de

Browse files
committed
Merge #167: Installation and configurations docs
9baedfb docs: [#166] installation and configuration (Jose Celano) Pull request description: Move installation and configuration docs to Rust [Documentation Comments](https://doc.rust-lang.org/book/ch14-02-publishing-to-crates-io.html#making-useful-documentation-comments). Top commit has no ACKs. Tree-SHA512: 4667d630446b45e1b73485f8c64b0dc4aa59e980aa4896f96b77dff9c13a1e84b5308428fd8ffa00708b1500401ab0c52cce96ecf08e26abd99c96a3ac8b9b91
2 parents 25aad49 + 9baedfb commit 29d87de

File tree

12 files changed

+334
-13
lines changed

12 files changed

+334
-13
lines changed

project-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ leechers
3030
Leechers
3131
LEECHERS
3232
lettre
33+
libsqlite
3334
luckythelab
3435
mailcatcher
3536
mandelbrotset

src/bin/import_tracker_statistics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Import Tracker Statistics command.
2+
//!
23
//! It imports the number of seeders and leechers for all torrent from the linked tracker.
4+
//!
35
//! You can execute it with: `cargo run --bin import_tracker_statistics`
4-
56
use torrust_index_backend::console::commands::import_tracker_statistics::run_importer;
67

78
#[actix_web::main]

src/config.rs

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Configuration for the application.
12
use std::path::Path;
23
use std::{env, fs};
34

@@ -6,8 +7,10 @@ use log::warn;
67
use serde::{Deserialize, Serialize};
78
use tokio::sync::RwLock;
89

10+
/// Information displayed to the user in the website.
911
#[derive(Debug, Clone, Serialize, Deserialize)]
1012
pub struct Website {
13+
/// The name of the website.
1114
pub name: String,
1215
}
1316

@@ -19,12 +22,18 @@ impl Default for Website {
1922
}
2023
}
2124

25+
/// See `TrackerMode` in [`torrust-tracker-primitives`](https://docs.rs/torrust-tracker-primitives)
26+
/// crate for more information.
2227
#[derive(Debug, Clone, Serialize, Deserialize)]
2328
pub enum TrackerMode {
2429
// todo: use https://crates.io/crates/torrust-tracker-primitives
30+
/// Will track every new info hash and serve every peer.
2531
Public,
32+
/// Will only serve authenticated peers.
2633
Private,
34+
/// Will only track whitelisted info hashes.
2735
Whitelisted,
36+
/// Will only track whitelisted info hashes and serve authenticated peers.
2837
PrivateWhitelisted,
2938
}
3039

@@ -34,12 +43,20 @@ impl Default for TrackerMode {
3443
}
3544
}
3645

46+
/// Configuration for the associated tracker.
3747
#[derive(Debug, Clone, Serialize, Deserialize)]
3848
pub struct Tracker {
49+
/// Connection string for the tracker. For example: `udp://TRACKER_IP:6969`.
3950
pub url: String,
51+
/// The mode of the tracker. For example: `Public`.
52+
/// See `TrackerMode` in [`torrust-tracker-primitives`](https://docs.rs/torrust-tracker-primitives)
53+
/// crate for more information.
4054
pub mode: TrackerMode,
55+
/// The url of the tracker API. For example: `http://localhost:1212`.
4156
pub api_url: String,
57+
/// The token used to authenticate with the tracker API.
4258
pub token: String,
59+
/// The amount of seconds the token is valid.
4360
pub token_valid_seconds: u64,
4461
}
4562

@@ -55,12 +72,18 @@ impl Default for Tracker {
5572
}
5673
}
5774

58-
/// Port 0 means that the OS will choose a random free port.
75+
/// Port number representing that the OS will choose one randomly from the available ports.
76+
///
77+
/// It's the port number `0`
5978
pub const FREE_PORT: u16 = 0;
6079

80+
/// The the base URL for the API.
6181
#[derive(Debug, Clone, Serialize, Deserialize)]
6282
pub struct Network {
83+
/// The port to listen on. Default to `3000`.
6384
pub port: u16,
85+
/// The base URL for the API. For example: `http://localhost`.
86+
/// If not set, the base URL will be inferred from the request.
6487
pub base_url: Option<String>,
6588
}
6689

@@ -73,11 +96,15 @@ impl Default for Network {
7396
}
7497
}
7598

99+
/// Whether the email is required on signup or not.
76100
#[derive(Debug, Clone, Serialize, Deserialize)]
77101
pub enum EmailOnSignup {
102+
/// The email is required on signup.
78103
Required,
104+
/// The email is optional on signup.
79105
Optional,
80-
None,
106+
/// The email is not allowed on signup. It will only be ignored if provided.
107+
None, // code-review: rename to `Ignored`?
81108
}
82109

83110
impl Default for EmailOnSignup {
@@ -86,11 +113,16 @@ impl Default for EmailOnSignup {
86113
}
87114
}
88115

116+
/// Authentication options.
89117
#[derive(Debug, Clone, Serialize, Deserialize)]
90118
pub struct Auth {
119+
/// Whether or not to require an email on signup.
91120
pub email_on_signup: EmailOnSignup,
121+
/// The minimum password length.
92122
pub min_password_length: usize,
123+
/// The maximum password length.
93124
pub max_password_length: usize,
125+
/// The secret key used to sign JWT tokens.
94126
pub secret_key: String,
95127
}
96128

@@ -105,8 +137,10 @@ impl Default for Auth {
105137
}
106138
}
107139

140+
/// Database configuration.
108141
#[derive(Debug, Clone, Serialize, Deserialize)]
109142
pub struct Database {
143+
/// The connection string for the database. For example: `sqlite://data.db?mode=rwc`.
110144
pub connect_url: String,
111145
}
112146

@@ -118,14 +152,22 @@ impl Default for Database {
118152
}
119153
}
120154

155+
/// SMTP configuration.
121156
#[derive(Debug, Clone, Serialize, Deserialize)]
122157
pub struct Mail {
158+
/// Whether or not to enable email verification on signup.
123159
pub email_verification_enabled: bool,
160+
/// The email address to send emails from.
124161
pub from: String,
162+
/// The email address to reply to.
125163
pub reply_to: String,
164+
/// The username to use for SMTP authentication.
126165
pub username: String,
166+
/// The password to use for SMTP authentication.
127167
pub password: String,
168+
/// The SMTP server to use.
128169
pub server: String,
170+
/// The SMTP port to use.
129171
pub port: u16,
130172
}
131173

@@ -143,19 +185,36 @@ impl Default for Mail {
143185
}
144186
}
145187

188+
/// Configuration for the image proxy cache.
189+
///
190+
/// Users have a cache quota per period. For example: 100MB per day.
191+
/// When users are navigating the site, they will be downloading images that are
192+
/// embedded in the torrent description. These images will be cached in the
193+
/// proxy. The proxy will not download new images if the user has reached the
194+
/// quota.
146195
#[allow(clippy::module_name_repetitions)]
147196
#[derive(Debug, Clone, Serialize, Deserialize)]
148197
pub struct ImageCache {
198+
/// Maximum time in seconds to wait for downloading the image form the original source.
149199
pub max_request_timeout_ms: u64,
200+
/// Cache size in bytes.
150201
pub capacity: usize,
202+
/// Maximum size in bytes for a single image.
151203
pub entry_size_limit: usize,
204+
/// Users have a cache quota per period. For example: 100MB per day.
205+
/// This is the period in seconds (1 day in seconds).
152206
pub user_quota_period_seconds: u64,
207+
/// Users have a cache quota per period. For example: 100MB per day.
208+
/// This is the maximum size in bytes (100MB in bytes).
153209
pub user_quota_bytes: usize,
154210
}
155211

212+
/// Core configuration for the API
156213
#[derive(Debug, Clone, Serialize, Deserialize)]
157214
pub struct Api {
215+
/// The default page size for torrent lists.
158216
pub default_torrent_page_size: u8,
217+
/// The maximum page size for torrent lists.
159218
pub max_torrent_page_size: u8,
160219
}
161220

@@ -168,8 +227,10 @@ impl Default for Api {
168227
}
169228
}
170229

230+
/// Configuration for the tracker statistics importer.
171231
#[derive(Debug, Clone, Serialize, Deserialize)]
172232
pub struct TrackerStatisticsImporter {
233+
/// The interval in seconds to get statistics from the tracker.
173234
pub torrent_info_update_interval: u64,
174235
}
175236

@@ -193,22 +254,36 @@ impl Default for ImageCache {
193254
}
194255
}
195256

257+
/// The whole configuration for the backend.
196258
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
197259
pub struct TorrustBackend {
260+
/// The website customizable values.
198261
pub website: Website,
262+
/// The tracker configuration.
199263
pub tracker: Tracker,
264+
/// The network configuration.
200265
pub net: Network,
266+
/// The authentication configuration.
201267
pub auth: Auth,
268+
/// The database configuration.
202269
pub database: Database,
270+
/// The SMTP configuration.
203271
pub mail: Mail,
272+
/// The image proxy cache configuration.
204273
pub image_cache: ImageCache,
274+
/// The API configuration.
205275
pub api: Api,
276+
/// The tracker statistics importer job configuration.
206277
pub tracker_statistics_importer: TrackerStatisticsImporter,
207278
}
208279

280+
/// The configuration service.
209281
#[derive(Debug)]
210282
pub struct Configuration {
283+
/// The state of the configuration.
211284
pub settings: RwLock<TorrustBackend>,
285+
/// The path to the configuration file. This is `None` if the configuration
286+
/// was loaded from the environment.
212287
pub config_path: Option<String>,
213288
}
214289

@@ -237,13 +312,14 @@ impl Configuration {
237312
if Path::new(config_path).exists() {
238313
config = config_builder.add_source(File::with_name(config_path)).build()?;
239314
} else {
240-
warn!("No config file found.");
241-
warn!("Creating config file..");
315+
warn!("No config file found. Creating default config file ...");
316+
242317
let config = Configuration::default();
243318
let _ = config.save_to_file(config_path).await;
244-
return Err(ConfigError::Message(
245-
"Please edit the config.TOML in the root folder and restart the tracker.".to_string(),
246-
));
319+
320+
return Err(ConfigError::Message(format!(
321+
"No config file found. Created default config file in {config_path}. Edit the file and start the application."
322+
)));
247323
}
248324

249325
let torrust_config: TorrustBackend = match config.try_deserialize() {
@@ -345,6 +421,8 @@ impl Configuration {
345421
}
346422
}
347423

424+
/// The public backend configuration.
425+
/// There is an endpoint to get this configuration.
348426
#[derive(Debug, Clone, Serialize, Deserialize)]
349427
pub struct ConfigurationPublic {
350428
website_name: String,

src/console/commands/import_tracker_statistics.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
//! It imports statistics for all torrents from the linked tracker.
2-
2+
//!
3+
//! It imports the number of seeders and leechers for all torrent from the linked tracker.
4+
//!
5+
//! You can execute it with: `cargo run --bin import_tracker_statistics`
36
use std::env;
47
use std::sync::Arc;
58

0 commit comments

Comments
 (0)