Skip to content

Commit de7c6f0

Browse files
committed
Merge #1222: Overhaul core Tracker: reorganize code
4921f7b fix: [#1221] docs links (Jose Celano) 1db58b1 refactor: [#1221] move whitelist manager setup to whitelist context (Jose Celano) 716e7b2 refactor: [#1221] move DB setup to databases context (Jose Celano) d830c78 refactor: [#1221] move core torrent mod to torrent context (Jose Celano) 948cc8c refactor: [#1221] move core statistics mod to statistics context (Jose Celano) Pull request description: Overhaul core Tracker: reorganize code ACKs for top commit: josecelano: ACK 4921f7b Tree-SHA512: 5497f4318f80404ce5f4f4826b0bb99b3f633ec918c625b8acecc2bb0811e4cb82da80d0b06df3c733b68ff605bfd449736dd64c522aa2217f5391185826516f
2 parents 46e9d25 + 4921f7b commit de7c6f0

File tree

28 files changed

+85
-86
lines changed

28 files changed

+85
-86
lines changed

src/bootstrap/app.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ use crate::core::authentication::handler::KeysHandler;
2727
use crate::core::authentication::key::repository::in_memory::InMemoryKeyRepository;
2828
use crate::core::authentication::key::repository::persisted::DatabaseKeyRepository;
2929
use crate::core::authentication::service;
30+
use crate::core::databases::setup::initialize_database;
3031
use crate::core::scrape_handler::ScrapeHandler;
31-
use crate::core::services::{initialize_database, initialize_whitelist_manager, statistics};
32+
use crate::core::statistics;
3233
use crate::core::torrent::manager::TorrentsManager;
3334
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
3435
use crate::core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
3536
use crate::core::whitelist::authorization::WhitelistAuthorization;
3637
use crate::core::whitelist::repository::in_memory::InMemoryWhitelist;
38+
use crate::core::whitelist::setup::initialize_whitelist_manager;
3739
use crate::servers::udp::server::banning::BanService;
3840
use crate::servers::udp::server::launcher::MAX_CONNECTION_ID_ERRORS_PER_IP;
3941
use crate::shared::crypto::ephemeral_instance_keys;

src/core/announce_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ mod tests {
414414
use crate::core::announce_handler::tests::the_announce_handler::peer_ip;
415415
use crate::core::announce_handler::{AnnounceHandler, PeersWanted};
416416
use crate::core::core_tests::{sample_info_hash, sample_peer};
417-
use crate::core::services::initialize_database;
417+
use crate::core::databases::setup::initialize_database;
418418
use crate::core::torrent::manager::TorrentsManager;
419419
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
420420
use crate::core::torrent::repository::persisted::DatabasePersistentTorrentRepository;

src/core/authentication/handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ mod tests {
246246
use crate::core::authentication::handler::KeysHandler;
247247
use crate::core::authentication::key::repository::in_memory::InMemoryKeyRepository;
248248
use crate::core::authentication::key::repository::persisted::DatabaseKeyRepository;
249-
use crate::core::services::initialize_database;
249+
use crate::core::databases::setup::initialize_database;
250250

251251
fn instantiate_keys_handler() -> KeysHandler {
252252
let config = configuration::ephemeral_private();

src/core/authentication/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod tests {
2727
use crate::core::authentication::key::repository::persisted::DatabaseKeyRepository;
2828
use crate::core::authentication::service;
2929
use crate::core::authentication::service::AuthenticationService;
30-
use crate::core::services::initialize_database;
30+
use crate::core::databases::setup::initialize_database;
3131

3232
fn instantiate_keys_manager_and_authentication() -> (Arc<KeysHandler>, Arc<AuthenticationService>) {
3333
let config = configuration::ephemeral_private();

src/core/core_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use torrust_tracker_primitives::peer::Peer;
99
use torrust_tracker_primitives::DurationSinceUnixEpoch;
1010

1111
use super::announce_handler::AnnounceHandler;
12+
use super::databases::setup::initialize_database;
1213
use super::scrape_handler::ScrapeHandler;
13-
use super::services::initialize_database;
1414
use super::torrent::repository::in_memory::InMemoryTorrentRepository;
1515
use super::torrent::repository::persisted::DatabasePersistentTorrentRepository;
1616
use super::whitelist::repository::in_memory::InMemoryWhitelist;

src/core/databases/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
pub mod driver;
4747
pub mod error;
4848
pub mod mysql;
49+
pub mod setup;
4950
pub mod sqlite;
5051

5152
use std::marker::PhantomData;

src/core/databases/setup.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use std::sync::Arc;
2+
3+
use torrust_tracker_configuration::v2_0_0::database;
4+
use torrust_tracker_configuration::Configuration;
5+
6+
use super::driver::{self, Driver};
7+
use super::Database;
8+
9+
/// # Panics
10+
///
11+
/// Will panic if database cannot be initialized.
12+
#[must_use]
13+
pub fn initialize_database(config: &Configuration) -> Arc<Box<dyn Database>> {
14+
let driver = match config.core.database.driver {
15+
database::Driver::Sqlite3 => Driver::Sqlite3,
16+
database::Driver::MySQL => Driver::MySQL,
17+
};
18+
19+
Arc::new(driver::build(&driver, &config.core.database.path).expect("Database driver build failed."))
20+
}

src/core/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,10 @@
344344
//!
345345
//! # Services
346346
//!
347-
//! Services are domain services on top of the core tracker. Right now there are two types of service:
347+
//! Services are domain services on top of the core tracker domain. Right now there are two types of service:
348348
//!
349-
//! - For statistics
350-
//! - For torrents
349+
//! - For statistics: [`crate::core::statistics::services`]
350+
//! - For torrents: [`crate::core::torrent::services`]
351351
//!
352352
//! Services usually format the data inside the tracker to make it easier to consume by other parts.
353353
//! They also decouple the internal data structure, used by the tracker, from the way we deliver that data to the consumers.
@@ -356,8 +356,6 @@
356356
//!
357357
//! Services can include extra features like pagination, for example.
358358
//!
359-
//! Refer to [`services`] module for more information about services.
360-
//!
361359
//! # Authentication
362360
//!
363361
//! One of the core `Tracker` responsibilities is to create and keep authentication keys. Auth keys are used by HTTP trackers
@@ -444,7 +442,6 @@ pub mod authentication;
444442
pub mod databases;
445443
pub mod error;
446444
pub mod scrape_handler;
447-
pub mod services;
448445
pub mod statistics;
449446
pub mod torrent;
450447
pub mod whitelist;

src/core/services/mod.rs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/core/statistics/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ pub mod event;
2828
pub mod keeper;
2929
pub mod metrics;
3030
pub mod repository;
31+
pub mod services;
32+
pub mod setup;

0 commit comments

Comments
 (0)