Skip to content

Commit

Permalink
dev: refactor: rename tracker mod to core
Browse files Browse the repository at this point in the history
  • Loading branch information
da2ce7 committed Dec 3, 2023
1 parent 3428660 commit 986ab64
Show file tree
Hide file tree
Showing 73 changed files with 281 additions and 283 deletions.
6 changes: 3 additions & 3 deletions packages/configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
//!
//! Each section in the toml structure is mapped to a data structure. For
//! example, the `[http_api]` section (configuration for the tracker HTTP API)
//! is mapped to the [`HttpApi`](HttpApi) structure.
//! is mapped to the [`HttpApi`] structure.
//!
//! > **NOTICE**: some sections are arrays of structures. For example, the
//! > `[[udp_trackers]]` section is an array of [`UdpTracker`](UdpTracker) since
//! > `[[udp_trackers]]` section is an array of [`UdpTracker`] since
//! > you can have multiple running UDP trackers bound to different ports.
//!
//! Please refer to the documentation of each structure for more information
Expand Down Expand Up @@ -394,7 +394,7 @@ pub struct Configuration {
/// Logging level. Possible values are: `Off`, `Error`, `Warn`, `Info`,
/// `Debug` and `Trace`. Default is `Info`.
pub log_level: Option<String>,
/// Tracker mode. See [`TrackerMode`](torrust_tracker_primitives::TrackerMode) for more information.
/// Tracker mode. See [`TrackerMode`] for more information.
pub mode: TrackerMode,

// Database configuration
Expand Down
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ use tokio::task::JoinHandle;
use torrust_tracker_configuration::Configuration;

use crate::bootstrap::jobs::{health_check_api, http_tracker, torrent_cleanup, tracker_apis, udp_tracker};
use crate::core;
use crate::servers::http::Version;
use crate::tracker;

/// # Panics
///
/// Will panic if:
///
/// - Can't retrieve tracker keys from database.
/// - Can't load whitelist from database.
pub async fn start(config: Arc<Configuration>, tracker: Arc<tracker::Tracker>) -> Vec<JoinHandle<()>> {
pub async fn start(config: Arc<Configuration>, tracker: Arc<core::Tracker>) -> Vec<JoinHandle<()>> {

Check warning on line 40 in src/app.rs

View check run for this annotation

Codecov / codecov/patch

src/app.rs#L40

Added line #L40 was not covered by tests
let mut jobs: Vec<JoinHandle<()>> = Vec::new();

// Load peer keys
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use torrust_tracker_configuration::Configuration;

use super::config::initialize_configuration;
use crate::bootstrap;
use crate::core::services::tracker_factory;
use crate::core::Tracker;
use crate::shared::clock::static_time;
use crate::shared::crypto::ephemeral_instance_keys;
use crate::tracker::services::tracker_factory;
use crate::tracker::Tracker;

/// It loads the configuration from the environment and builds the main domain [`Tracker`] struct.
#[must_use]
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HttpTracker;

use crate::core;
use crate::servers::http::v1::launcher;
use crate::servers::http::Version;
use crate::tracker;

/// This is the message that the "**launcher**" spawned task sends to the main application process to notify that the HTTP server was successfully started.
///
Expand All @@ -33,7 +33,7 @@ pub struct ServerJobStarted();
///
/// Right now there is only one version but in the future we could support more than one HTTP tracker version at the same time.
/// This feature allows supporting breaking changes on `BitTorrent` BEPs.
pub async fn start_job(config: &HttpTracker, tracker: Arc<tracker::Tracker>, version: Version) -> JoinHandle<()> {
pub async fn start_job(config: &HttpTracker, tracker: Arc<core::Tracker>, version: Version) -> JoinHandle<()> {

Check warning on line 36 in src/bootstrap/jobs/http_tracker.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/jobs/http_tracker.rs#L36

Added line #L36 was not covered by tests
match version {
Version::V1 => start_v1(config, tracker.clone()).await,
}
Expand All @@ -42,7 +42,7 @@ pub async fn start_job(config: &HttpTracker, tracker: Arc<tracker::Tracker>, ver
/// # Panics
///
/// It would panic if the `config::HttpTracker` struct would contain inappropriate values.
async fn start_v1(config: &HttpTracker, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
async fn start_v1(config: &HttpTracker, tracker: Arc<core::Tracker>) -> JoinHandle<()> {

Check warning on line 45 in src/bootstrap/jobs/http_tracker.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/jobs/http_tracker.rs#L45

Added line #L45 was not covered by tests
let bind_addr = config
.bind_address
.parse::<std::net::SocketAddr>()
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/torrent_cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use log::info;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::Configuration;

use crate::tracker;
use crate::core;

/// It starts a jobs for cleaning up the torrent data in the tracker.
///
/// The cleaning task is executed on an `inactive_peer_cleanup_interval`.
///
/// Refer to [`torrust-tracker-configuration documentation`](https://docs.rs/torrust-tracker-configuration) for more info about that option.
#[must_use]
pub fn start_job(config: &Arc<Configuration>, tracker: &Arc<tracker::Tracker>) -> JoinHandle<()> {
pub fn start_job(config: &Arc<Configuration>, tracker: &Arc<core::Tracker>) -> JoinHandle<()> {

Check warning on line 28 in src/bootstrap/jobs/torrent_cleanup.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/jobs/torrent_cleanup.rs#L28

Added line #L28 was not covered by tests
let weak_tracker = std::sync::Arc::downgrade(tracker);
let interval = config.inactive_peer_cleanup_interval;

Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/tracker_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use tokio::sync::oneshot;
use tokio::task::JoinHandle;
use torrust_tracker_configuration::HttpApi;

use crate::core;
use crate::servers::apis::server;
use crate::tracker;

/// This is the message that the "launcher" spawned task sends to the main
/// application process to notify the API server was successfully started.
Expand All @@ -49,7 +49,7 @@ pub struct ApiServerJobStarted();
/// # Panics
///
/// It would panic if unable to send the `ApiServerJobStarted` notice.
pub async fn start_job(config: &HttpApi, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
pub async fn start_job(config: &HttpApi, tracker: Arc<core::Tracker>) -> JoinHandle<()> {

Check warning on line 52 in src/bootstrap/jobs/tracker_apis.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/jobs/tracker_apis.rs#L52

Added line #L52 was not covered by tests
let bind_addr = config
.bind_address
.parse::<std::net::SocketAddr>()
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/udp_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use log::{error, info, warn};
use tokio::task::JoinHandle;
use torrust_tracker_configuration::UdpTracker;

use crate::core;
use crate::servers::udp::server::Udp;
use crate::tracker;

/// It starts a new UDP server with the provided configuration.
///
/// It spawns a new asynchronous task for the new UDP server.
#[must_use]
pub fn start_job(config: &UdpTracker, tracker: Arc<tracker::Tracker>) -> JoinHandle<()> {
pub fn start_job(config: &UdpTracker, tracker: Arc<core::Tracker>) -> JoinHandle<()> {

Check warning on line 22 in src/bootstrap/jobs/udp_tracker.rs

View check run for this annotation

Codecov / codecov/patch

src/bootstrap/jobs/udp_tracker.rs#L22

Added line #L22 was not covered by tests
let bind_addr = config.bind_address.clone();

tokio::spawn(async move {
Expand Down
12 changes: 6 additions & 6 deletions src/tracker/auth.rs → src/core/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//! Keys are stored in this struct:
//!
//! ```rust,no_run
//! use torrust_tracker::tracker::auth::Key;
//! use torrust_tracker::core::auth::Key;
//! use torrust_tracker::shared::clock::DurationSinceUnixEpoch;
//!
//! pub struct ExpiringKey {
Expand All @@ -26,7 +26,7 @@
//! You can generate a new key valid for `9999` seconds and `0` nanoseconds from the current time with the following:
//!
//! ```rust,no_run
//! use torrust_tracker::tracker::auth;
//! use torrust_tracker::core::auth;
//! use std::time::Duration;
//!
//! let expiring_key = auth::generate(Duration::new(9999, 0));
Expand Down Expand Up @@ -138,7 +138,7 @@ pub struct Key(String);
/// Error returned when a key cannot be parsed from a string.
///
/// ```rust,no_run
/// use torrust_tracker::tracker::auth::Key;
/// use torrust_tracker::core::auth::Key;
/// use std::str::FromStr;
///
/// let key_string = "YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ";
Expand All @@ -164,7 +164,7 @@ impl FromStr for Key {
}
}

/// Verification error. Error returned when an [`ExpiringKey`] cannot be verified with the [`verify(...)`](crate::tracker::auth::verify) function.
/// Verification error. Error returned when an [`ExpiringKey`] cannot be verified with the [`verify(...)`](crate::core::auth::verify) function.
///
#[derive(Debug, Error)]
#[allow(dead_code)]
Expand Down Expand Up @@ -196,7 +196,7 @@ mod tests {
mod key {
use std::str::FromStr;

use crate::tracker::auth::Key;
use crate::core::auth::Key;

#[test]
fn should_be_parsed_from_an_string() {
Expand All @@ -212,8 +212,8 @@ mod tests {
use std::str::FromStr;
use std::time::Duration;

use crate::core::auth;
use crate::shared::clock::{Current, StoppedTime};
use crate::tracker::auth;

#[test]
fn should_be_parsed_from_an_string() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Database driver factory.
//!
//! See [`databases::driver::build`](crate::tracker::databases::driver::build)
//! See [`databases::driver::build`](crate::core::databases::driver::build)
//! function for more information.
use torrust_tracker_primitives::DatabaseDriver;

Expand All @@ -14,7 +14,7 @@ use super::{Builder, Database};
/// Example for `SQLite3`:
///
/// ```rust,no_run
/// use torrust_tracker::tracker::databases;
/// use torrust_tracker::core::databases;
/// use torrust_tracker_primitives::DatabaseDriver;
///
/// let db_driver = DatabaseDriver::Sqlite3;
Expand All @@ -25,7 +25,7 @@ use super::{Builder, Database};
/// Example for `MySQL`:
///
/// ```rust,no_run
/// use torrust_tracker::tracker::databases;
/// use torrust_tracker::core::databases;
/// use torrust_tracker_primitives::DatabaseDriver;
///
/// let db_driver = DatabaseDriver::MySQL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Database errors.
//!
//! This module contains the [Database errors](crate::tracker::databases::error::Error).
//! This module contains the [Database errors](crate::core::databases::error::Error).
use std::panic::Location;
use std::sync::Arc;

Expand Down
16 changes: 8 additions & 8 deletions src/tracker/databases/mod.rs → src/core/databases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
//!
//! There are two implementations of the trait (two drivers):
//!
//! - [`Mysql`](crate::tracker::databases::mysql::Mysql)
//! - [`Sqlite`](crate::tracker::databases::sqlite::Sqlite)
//! - [`Mysql`](crate::core::databases::mysql::Mysql)
//! - [`Sqlite`](crate::core::databases::sqlite::Sqlite)
//!
//! > **NOTICE**: There are no database migrations. If there are any changes,
//! we will implemented them or provide a script to migrate to the new schema.
Expand All @@ -22,7 +22,7 @@
//! ---|---|---
//! `id` | 1 | Autoincrement id
//! `info_hash` | `c1277613db1d28709b034a017ab2cae4be07ae10` | `BitTorrent` infohash V1
//! `completed` | 20 | The number of peers that have ever completed downloading the torrent associated to this entry. See [`Entry`](crate::tracker::torrent::Entry) for more information.
//! `completed` | 20 | The number of peers that have ever completed downloading the torrent associated to this entry. See [`Entry`](crate::core::torrent::Entry) for more information.
//!
//! > **NOTICE**: The peer list for a torrent is not persisted. Since peer have to re-announce themselves on intervals, the data is be
//! regenerated again after some minutes.
Expand Down Expand Up @@ -53,8 +53,8 @@ use std::marker::PhantomData;
use async_trait::async_trait;

use self::error::Error;
use crate::core::auth::{self, Key};
use crate::shared::bit_torrent::info_hash::InfoHash;
use crate::tracker::auth::{self, Key};

struct Builder<T>
where
Expand Down Expand Up @@ -116,9 +116,9 @@ pub trait Database: Sync + Send {
///
/// It returns an array of tuples with the torrent
/// [`InfoHash`] and the
/// [`completed`](crate::tracker::torrent::Entry::completed) counter
/// [`completed`](crate::core::torrent::Entry::completed) counter
/// which is the number of times the torrent has been downloaded.
/// See [`Entry::completed`](crate::tracker::torrent::Entry::completed).
/// See [`Entry::completed`](crate::core::torrent::Entry::completed).
///
/// # Context: Torrent Metrics
///
Expand Down Expand Up @@ -200,8 +200,8 @@ pub trait Database: Sync + Send {

/// It gets an expiring authentication key from the database.
///
/// It returns `Some(ExpiringKey)` if a [`ExpiringKey`](crate::tracker::auth::ExpiringKey)
/// with the input [`Key`](crate::tracker::auth::Key) exists, `None` otherwise.
/// It returns `Some(ExpiringKey)` if a [`ExpiringKey`](crate::core::auth::ExpiringKey)
/// with the input [`Key`](crate::core::auth::Key) exists, `None` otherwise.
///
/// # Context: Authentication Keys
///
Expand Down
Loading

0 comments on commit 986ab64

Please sign in to comment.