Skip to content

Commit

Permalink
refactor: [torrust#1187] rename fn tracker_factory to initialize_tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jan 17, 2025
1 parent aa9f1c3 commit 3e99189
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/bootstrap/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use tracing::instrument;
use super::config::initialize_configuration;
use crate::bootstrap;
use crate::container::AppContainer;
use crate::core::services::{initialize_database, initialize_whitelist, statistics, tracker_factory};
use crate::core::services::{initialize_database, initialize_tracker, initialize_whitelist, statistics};
use crate::servers::udp::server::banning::BanService;
use crate::servers::udp::server::launcher::MAX_CONNECTION_ID_ERRORS_PER_IP;
use crate::shared::crypto::ephemeral_instance_keys;
Expand Down Expand Up @@ -82,7 +82,7 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));
let database = initialize_database(configuration);
let whitelist_manager = initialize_whitelist(database.clone());
let tracker = Arc::new(tracker_factory(configuration, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(configuration, &database, &whitelist_manager));

AppContainer {
tracker,
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/jobs/http_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod tests {

use crate::bootstrap::app::initialize_global_services;
use crate::bootstrap::jobs::http_tracker::start_job;
use crate::core::services::{initialize_database, initialize_whitelist, statistics, tracker_factory};
use crate::core::services::{initialize_database, initialize_whitelist, statistics, initialize_tracker};
use crate::servers::http::Version;
use crate::servers::registar::Registar;

Expand All @@ -105,7 +105,7 @@ mod tests {

let database = initialize_database(&cfg);
let whitelist_manager = initialize_whitelist(database.clone());
let tracker = Arc::new(tracker_factory(&cfg, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&cfg, &database, &whitelist_manager));

let version = Version::V1;

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 @@ -142,7 +142,7 @@ mod tests {

use crate::bootstrap::app::initialize_global_services;
use crate::bootstrap::jobs::tracker_apis::start_job;
use crate::core::services::{initialize_database, initialize_whitelist, statistics, tracker_factory};
use crate::core::services::{initialize_database, initialize_tracker, initialize_whitelist, statistics};
use crate::servers::apis::Version;
use crate::servers::registar::Registar;
use crate::servers::udp::server::banning::BanService;
Expand All @@ -162,7 +162,7 @@ mod tests {

let database = initialize_database(&cfg);
let whitelist_manager = initialize_whitelist(database.clone());
let tracker = Arc::new(tracker_factory(&cfg, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&cfg, &database, &whitelist_manager));

let version = Version::V1;

Expand Down
10 changes: 5 additions & 5 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1082,26 +1082,26 @@ mod tests {

use crate::app_test::initialize_tracker_dependencies;
use crate::core::peer::Peer;
use crate::core::services::tracker_factory;
use crate::core::services::initialize_tracker;
use crate::core::whitelist::WhiteListManager;
use crate::core::{TorrentsMetrics, Tracker};

fn public_tracker() -> Tracker {
let config = configuration::ephemeral_public();
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
tracker_factory(&config, &database, &whitelist_manager)
initialize_tracker(&config, &database, &whitelist_manager)
}

fn private_tracker() -> Tracker {
let config = configuration::ephemeral_private();
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
tracker_factory(&config, &database, &whitelist_manager)
initialize_tracker(&config, &database, &whitelist_manager)
}

fn whitelisted_tracker() -> (Tracker, Arc<WhiteListManager>) {
let config = configuration::ephemeral_listed();
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = tracker_factory(&config, &database, &whitelist_manager);
let tracker = initialize_tracker(&config, &database, &whitelist_manager);

(tracker, whitelist_manager)
}
Expand All @@ -1110,7 +1110,7 @@ mod tests {
let mut config = configuration::ephemeral_listed();
config.core.tracker_policy.persistent_torrent_completed_stat = true;
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
tracker_factory(&config, &database, &whitelist_manager)
initialize_tracker(&config, &database, &whitelist_manager)
}

fn sample_info_hash() -> InfoHash {
Expand Down
2 changes: 1 addition & 1 deletion src/core/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::core::Tracker;
///
/// Will panic if tracker cannot be instantiated.
#[must_use]
pub fn tracker_factory(
pub fn initialize_tracker(
config: &Configuration,
database: &Arc<Box<dyn Database>>,
whitelist_manager: &Arc<WhiteListManager>,
Expand Down
4 changes: 2 additions & 2 deletions src/core/services/statistics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ mod tests {

use crate::app_test::initialize_tracker_dependencies;
use crate::core;
use crate::core::services::initialize_tracker;
use crate::core::services::statistics::{self, get_metrics, TrackerMetrics};
use crate::core::services::tracker_factory;
use crate::servers::udp::server::banning::BanService;
use crate::servers::udp::server::launcher::MAX_CONNECTION_ID_ERRORS_PER_IP;

Expand All @@ -136,7 +136,7 @@ mod tests {
let (_stats_event_sender, stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
let stats_repository = Arc::new(stats_repository);

let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP)));

Expand Down
18 changes: 9 additions & 9 deletions src/core/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {
use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::torrent::tests::sample_peer;
use crate::core::services::torrent::{get_torrent_info, Info};
use crate::core::services::tracker_factory;
use crate::core::services::initialize_tracker;

pub fn tracker_configuration() -> Configuration {
configuration::ephemeral()
Expand All @@ -143,7 +143,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = tracker_factory(&config, &database, &whitelist_manager);
let tracker = initialize_tracker(&config, &database, &whitelist_manager);

let tracker = Arc::new(tracker);

Expand All @@ -161,7 +161,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
let info_hash = InfoHash::from_str(&hash).unwrap();
Expand Down Expand Up @@ -194,7 +194,7 @@ mod tests {
use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::torrent::tests::sample_peer;
use crate::core::services::torrent::{get_torrents_page, BasicInfo, Pagination};
use crate::core::services::tracker_factory;
use crate::core::services::initialize_tracker;

pub fn tracker_configuration() -> Configuration {
configuration::ephemeral()
Expand All @@ -205,7 +205,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let torrents = get_torrents_page(tracker.clone(), Some(&Pagination::default())).await;

Expand All @@ -217,7 +217,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
let info_hash = InfoHash::from_str(&hash).unwrap();
Expand All @@ -242,7 +242,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
let info_hash1 = InfoHash::from_str(&hash1).unwrap();
Expand All @@ -265,7 +265,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
let info_hash1 = InfoHash::from_str(&hash1).unwrap();
Expand Down Expand Up @@ -297,7 +297,7 @@ mod tests {
let config = tracker_configuration();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let tracker = Arc::new(tracker_factory(&config, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&config, &database, &whitelist_manager));

let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned();
let info_hash1 = InfoHash::from_str(&hash1).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/servers/apis/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod tests {

use crate::bootstrap::app::initialize_global_services;
use crate::bootstrap::jobs::make_rust_tls;
use crate::core::services::{initialize_database, initialize_whitelist, statistics, tracker_factory};
use crate::core::services::{initialize_database, initialize_whitelist, statistics, initialize_tracker};
use crate::servers::apis::server::{ApiServer, Launcher};
use crate::servers::registar::Registar;
use crate::servers::udp::server::banning::BanService;
Expand All @@ -355,7 +355,7 @@ mod tests {

let database = initialize_database(&cfg);
let whitelist_manager = initialize_whitelist(database.clone());
let tracker = Arc::new(tracker_factory(&cfg, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&cfg, &database, &whitelist_manager));

let bind_to = config.bind_address;

Expand Down
4 changes: 2 additions & 2 deletions src/servers/http/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ mod tests {

use crate::bootstrap::app::initialize_global_services;
use crate::bootstrap::jobs::make_rust_tls;
use crate::core::services::{initialize_database, initialize_whitelist, statistics, tracker_factory};
use crate::core::services::{initialize_database, initialize_whitelist, statistics, initialize_tracker};
use crate::servers::http::server::{HttpServer, Launcher};
use crate::servers::registar::Registar;

Expand All @@ -259,7 +259,7 @@ mod tests {

let database = initialize_database(&cfg);
let whitelist_manager = initialize_whitelist(database.clone());
let tracker = Arc::new(tracker_factory(&cfg, &database, &whitelist_manager));
let tracker = Arc::new(initialize_tracker(&cfg, &database, &whitelist_manager));

let http_trackers = cfg.http_trackers.clone().expect("missing HTTP trackers configuration");
let config = &http_trackers[0];
Expand Down
10 changes: 5 additions & 5 deletions src/servers/http/v1/handlers/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ mod tests {
use torrust_tracker_test_helpers::configuration;

use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::{statistics, tracker_factory};
use crate::core::services::{statistics, initialize_tracker};
use crate::core::statistics::event::sender::Sender;
use crate::core::Tracker;

Expand All @@ -216,7 +216,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn whitelisted_tracker() -> (Tracker, Option<Box<dyn Sender>>) {
Expand All @@ -225,7 +225,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn tracker_on_reverse_proxy() -> (Tracker, Option<Box<dyn Sender>>) {
Expand All @@ -234,7 +234,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn tracker_not_on_reverse_proxy() -> (Tracker, Option<Box<dyn Sender>>) {
Expand All @@ -243,7 +243,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn sample_announce_request() -> Announce {
Expand Down
10 changes: 5 additions & 5 deletions src/servers/http/v1/handlers/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ mod tests {
use torrust_tracker_test_helpers::configuration;

use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::{statistics, tracker_factory};
use crate::core::services::{statistics, initialize_tracker};
use crate::core::Tracker;

fn private_tracker() -> (Tracker, Option<Box<dyn crate::core::statistics::event::sender::Sender>>) {
Expand All @@ -136,7 +136,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn whitelisted_tracker() -> (Tracker, Option<Box<dyn crate::core::statistics::event::sender::Sender>>) {
Expand All @@ -145,7 +145,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn tracker_on_reverse_proxy() -> (Tracker, Option<Box<dyn crate::core::statistics::event::sender::Sender>>) {
Expand All @@ -154,7 +154,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn tracker_not_on_reverse_proxy() -> (Tracker, Option<Box<dyn crate::core::statistics::event::sender::Sender>>) {
Expand All @@ -163,7 +163,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(&config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(&config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(&config, &database, &whitelist_manager), stats_event_sender)
}

fn sample_scrape_request() -> Scrape {
Expand Down
4 changes: 2 additions & 2 deletions src/servers/http/v1/services/announce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ mod tests {
use torrust_tracker_test_helpers::configuration;

use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::{statistics, tracker_factory};
use crate::core::services::{statistics, initialize_tracker};
use crate::core::statistics::event::sender::Sender;
use crate::core::Tracker;

Expand All @@ -77,7 +77,7 @@ mod tests {
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
let stats_event_sender = Arc::new(stats_event_sender);

let tracker = tracker_factory(&config, &database, &whitelist_manager);
let tracker = initialize_tracker(&config, &database, &whitelist_manager);

(tracker, stats_event_sender)
}
Expand Down
4 changes: 2 additions & 2 deletions src/servers/http/v1/services/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ mod tests {
use torrust_tracker_test_helpers::configuration;

use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::tracker_factory;
use crate::core::services::initialize_tracker;
use crate::core::Tracker;

fn public_tracker() -> Tracker {
let config = configuration::ephemeral_public();

let (database, whitelist_manager) = initialize_tracker_dependencies(&config);

tracker_factory(&config, &database, &whitelist_manager)
initialize_tracker(&config, &database, &whitelist_manager)
}

fn sample_info_hashes() -> Vec<InfoHash> {
Expand Down
4 changes: 2 additions & 2 deletions src/servers/udp/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ mod tests {

use super::gen_remote_fingerprint;
use crate::app_test::initialize_tracker_dependencies;
use crate::core::services::{statistics, tracker_factory};
use crate::core::services::{statistics, initialize_tracker};
use crate::core::statistics::event::sender::Sender;
use crate::core::Tracker;
use crate::CurrentClock;
Expand All @@ -496,7 +496,7 @@ mod tests {
let (database, whitelist_manager) = initialize_tracker_dependencies(config);
let (stats_event_sender, _stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);

(tracker_factory(config, &database, &whitelist_manager), stats_event_sender)
(initialize_tracker(config, &database, &whitelist_manager), stats_event_sender)
}

fn sample_ipv4_remote_addr() -> SocketAddr {
Expand Down
Loading

0 comments on commit 3e99189

Please sign in to comment.