From 73560a5612ed5a468c1d61bc910dd0eda166d022 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 27 Jan 2025 17:52:10 +0000 Subject: [PATCH] refactor: [#1209] remove core::Tracker --- src/app.rs | 2 - src/bootstrap/app.rs | 9 +- src/bootstrap/jobs/http_tracker.rs | 9 +- src/bootstrap/jobs/udp_tracker.rs | 5 +- src/container.rs | 3 +- src/core/mod.rs | 151 +++++------------------ src/core/services/mod.rs | 22 ---- src/core/services/statistics/mod.rs | 9 +- src/core/services/torrent.rs | 28 ++--- src/servers/http/server.rs | 8 +- src/servers/http/v1/handlers/announce.rs | 42 ++----- src/servers/http/v1/handlers/scrape.rs | 95 +++----------- src/servers/http/v1/routes.rs | 8 +- src/servers/http/v1/services/announce.rs | 43 ++----- src/servers/http/v1/services/scrape.rs | 34 ++--- src/servers/udp/handlers.rs | 100 +++------------ src/servers/udp/mod.rs | 3 +- src/servers/udp/server/launcher.rs | 8 +- src/servers/udp/server/mod.rs | 2 - src/servers/udp/server/processor.rs | 6 +- src/servers/udp/server/spawner.rs | 4 +- src/servers/udp/server/states.rs | 6 +- tests/servers/api/environment.rs | 5 - tests/servers/http/environment.rs | 7 +- tests/servers/udp/environment.rs | 7 +- 25 files changed, 119 insertions(+), 497 deletions(-) diff --git a/src/app.rs b/src/app.rs index 54ccbc60c..75c2e13bc 100644 --- a/src/app.rs +++ b/src/app.rs @@ -82,7 +82,6 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec< udp_tracker::start_job( Arc::new(config.core.clone()), udp_tracker_config, - app_container.tracker.clone(), app_container.announce_handler.clone(), app_container.scrape_handler.clone(), app_container.whitelist_authorization.clone(), @@ -104,7 +103,6 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec< if let Some(job) = http_tracker::start_job( http_tracker_config, Arc::new(config.core.clone()), - app_container.tracker.clone(), app_container.announce_handler.clone(), app_container.scrape_handler.clone(), app_container.authentication_service.clone(), diff --git a/src/bootstrap/app.rs b/src/bootstrap/app.rs index fa45998bb..da63048e0 100644 --- a/src/bootstrap/app.rs +++ b/src/bootstrap/app.rs @@ -28,7 +28,7 @@ use crate::core::authentication::key::repository::in_memory::InMemoryKeyReposito use crate::core::authentication::key::repository::persisted::DatabaseKeyRepository; use crate::core::authentication::service; use crate::core::scrape_handler::ScrapeHandler; -use crate::core::services::{initialize_database, initialize_tracker, initialize_whitelist_manager, statistics}; +use crate::core::services::{initialize_database, initialize_whitelist_manager, statistics}; use crate::core::torrent::manager::TorrentsManager; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; use crate::core::torrent::repository::persisted::DatabasePersistentTorrentRepository; @@ -116,12 +116,6 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer { &db_torrent_repository, )); - let tracker = Arc::new(initialize_tracker( - configuration, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &configuration.core, &in_memory_torrent_repository, @@ -132,7 +126,6 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer { AppContainer { database, - tracker, announce_handler, scrape_handler, keys_handler, diff --git a/src/bootstrap/jobs/http_tracker.rs b/src/bootstrap/jobs/http_tracker.rs index 5767f30ce..4a3aa7a9f 100644 --- a/src/bootstrap/jobs/http_tracker.rs +++ b/src/bootstrap/jobs/http_tracker.rs @@ -23,7 +23,7 @@ use crate::core::announce_handler::AnnounceHandler; use crate::core::authentication::service::AuthenticationService; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{self, statistics, whitelist}; +use crate::core::{statistics, whitelist}; use crate::servers::http::server::{HttpServer, Launcher}; use crate::servers::http::Version; use crate::servers::registar::ServiceRegistrationForm; @@ -39,7 +39,6 @@ use crate::servers::registar::ServiceRegistrationForm; #[allow(clippy::too_many_arguments)] #[instrument(skip( config, - tracker, announce_handler, scrape_handler, authentication_service, @@ -50,7 +49,6 @@ use crate::servers::registar::ServiceRegistrationForm; pub async fn start_job( config: &HttpTracker, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, authentication_service: Arc, @@ -71,7 +69,6 @@ pub async fn start_job( socket, tls, core_config.clone(), - tracker.clone(), announce_handler.clone(), scrape_handler.clone(), authentication_service.clone(), @@ -89,7 +86,6 @@ pub async fn start_job( #[instrument(skip( socket, tls, - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -100,7 +96,6 @@ async fn start_v1( socket: SocketAddr, tls: Option, config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, authentication_service: Arc, @@ -111,7 +106,6 @@ async fn start_v1( let server = HttpServer::new(Launcher::new(socket, tls)) .start( config, - tracker, announce_handler, scrape_handler, authentication_service, @@ -161,7 +155,6 @@ mod tests { start_job( config, Arc::new(cfg.core.clone()), - app_container.tracker, app_container.announce_handler, app_container.scrape_handler, app_container.authentication_service, diff --git a/src/bootstrap/jobs/udp_tracker.rs b/src/bootstrap/jobs/udp_tracker.rs index 36f3cd7b0..3679c3195 100644 --- a/src/bootstrap/jobs/udp_tracker.rs +++ b/src/bootstrap/jobs/udp_tracker.rs @@ -16,7 +16,7 @@ use tracing::instrument; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{self, whitelist}; +use crate::core::whitelist; use crate::servers::registar::ServiceRegistrationForm; use crate::servers::udp::server::banning::BanService; use crate::servers::udp::server::spawner::Spawner; @@ -37,7 +37,6 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET; #[allow(clippy::async_yields_async)] #[instrument(skip( config, - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -48,7 +47,6 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET; pub async fn start_job( core_config: Arc, config: &UdpTracker, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -62,7 +60,6 @@ pub async fn start_job( let server = Server::new(Spawner::new(bind_to)) .start( core_config, - tracker, announce_handler, scrape_handler, whitelist_authorization, diff --git a/src/container.rs b/src/container.rs index 4e958b6ed..544abd02e 100644 --- a/src/container.rs +++ b/src/container.rs @@ -12,13 +12,12 @@ use crate::core::statistics::repository::Repository; use crate::core::torrent::manager::TorrentsManager; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; use crate::core::torrent::repository::persisted::DatabasePersistentTorrentRepository; +use crate::core::whitelist; use crate::core::whitelist::manager::WhiteListManager; -use crate::core::{whitelist, Tracker}; use crate::servers::udp::server::banning::BanService; pub struct AppContainer { pub database: Arc>, - pub tracker: Arc, pub announce_handler: Arc, pub scrape_handler: Arc, pub keys_handler: Arc, diff --git a/src/core/mod.rs b/src/core/mod.rs index 43a2aa11d..f09e7d417 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -451,53 +451,9 @@ pub mod whitelist; pub mod peer_tests; -use std::sync::Arc; - -use torrent::repository::in_memory::InMemoryTorrentRepository; -use torrent::repository::persisted::DatabasePersistentTorrentRepository; -use torrust_tracker_configuration::Core; - -/// The domain layer tracker service. -/// -/// Its main responsibility is to handle the `announce` and `scrape` requests. -/// But it's also a container for the `Tracker` configuration, persistence, -/// authentication and other services. -/// -/// > **NOTICE**: the `Tracker` is not responsible for handling the network layer. -/// > Typically, the `Tracker` is used by a higher application service that handles -/// > the network layer. -pub struct Tracker { - /// The tracker configuration. - _core_config: Core, - - /// The in-memory torrents repository. - _in_memory_torrent_repository: Arc, - - /// The persistent torrents repository. - _db_torrent_repository: Arc, -} - -impl Tracker { - /// `Tracker` constructor. - /// - /// # Errors - /// - /// Will return a `databases::error::Error` if unable to connect to database. The `Tracker` is responsible for the persistence. - pub fn new( - core_config: &Core, - in_memory_torrent_repository: &Arc, - db_torrent_repository: &Arc, - ) -> Result { - Ok(Tracker { - _core_config: core_config.clone(), - _in_memory_torrent_repository: in_memory_torrent_repository.clone(), - _db_torrent_repository: db_torrent_repository.clone(), - }) - } -} - #[cfg(test)] mod tests { + // Integration tests for the core module. mod the_tracker { @@ -517,18 +473,13 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; - use crate::core::services::{initialize_tracker, initialize_whitelist_manager}; + use crate::core::services::initialize_whitelist_manager; use crate::core::torrent::manager::TorrentsManager; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; + use crate::core::whitelist; use crate::core::whitelist::manager::WhiteListManager; - use crate::core::{whitelist, Tracker}; - fn public_tracker() -> ( - Arc, - Arc, - Arc, - Arc, - ) { + fn public_tracker() -> (Arc, Arc, Arc) { let config = configuration::ephemeral_public(); let ( @@ -541,12 +492,6 @@ mod tests { _torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -555,10 +500,10 @@ mod tests { let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - (tracker, announce_handler, in_memory_torrent_repository, scrape_handler) + (announce_handler, in_memory_torrent_repository, scrape_handler) } - fn public_tracker_and_in_memory_torrents_repository() -> (Arc, Arc) { + fn initialize_in_memory_torrents_repository() -> Arc { let config = configuration::ephemeral_public(); let ( @@ -567,22 +512,15 @@ mod tests { _whitelist_authorization, _authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - - (tracker, in_memory_torrent_repository) + in_memory_torrent_repository } #[allow(clippy::type_complexity)] fn whitelisted_tracker() -> ( - Arc, Arc, Arc, Arc, @@ -602,12 +540,6 @@ mod tests { let whitelist_manager = initialize_whitelist_manager(database.clone(), in_memory_whitelist.clone()); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -616,21 +548,11 @@ mod tests { let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - ( - tracker, - announce_handler, - whitelist_authorization, - whitelist_manager, - scrape_handler, - ) + (announce_handler, whitelist_authorization, whitelist_manager, scrape_handler) } - pub fn tracker_persisting_torrents_in_database() -> ( - Arc, - Arc, - Arc, - Arc, - ) { + pub fn tracker_persisting_torrents_in_database( + ) -> (Arc, Arc, Arc) { let mut config = configuration::ephemeral_listed(); config.core.tracker_policy.persistent_torrent_completed_stat = true; @@ -644,19 +566,13 @@ mod tests { torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, &db_torrent_repository, )); - (tracker, announce_handler, torrents_manager, in_memory_torrent_repository) + (announce_handler, torrents_manager, in_memory_torrent_repository) } fn sample_info_hash() -> InfoHash { @@ -745,7 +661,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_peers_for_a_given_torrent() { - let (_tracker, in_memory_torrent_repository) = public_tracker_and_in_memory_torrents_repository(); + let in_memory_torrent_repository = initialize_in_memory_torrents_repository(); let info_hash = sample_info_hash(); let peer = sample_peer(); @@ -777,7 +693,7 @@ mod tests { #[tokio::test] async fn it_should_return_74_peers_at_the_most_for_a_given_torrent() { - let (_tracker, in_memory_torrent_repository) = public_tracker_and_in_memory_torrents_repository(); + let in_memory_torrent_repository = initialize_in_memory_torrents_repository(); let info_hash = sample_info_hash(); @@ -802,7 +718,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_peers_for_a_given_torrent_excluding_a_given_peer() { - let (_tracker, _announce_handler, in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (_announce_handler, in_memory_torrent_repository, _scrape_handler) = public_tracker(); let info_hash = sample_info_hash(); let peer = sample_peer(); @@ -816,7 +732,7 @@ mod tests { #[tokio::test] async fn it_should_return_74_peers_at_the_most_for_a_given_torrent_when_it_filters_out_a_given_peer() { - let (_tracker, _announce_handler, in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (_announce_handler, in_memory_torrent_repository, _scrape_handler) = public_tracker(); let info_hash = sample_info_hash(); @@ -846,7 +762,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_torrent_metrics() { - let (_tracker, in_memory_torrent_repository) = public_tracker_and_in_memory_torrents_repository(); + let in_memory_torrent_repository = initialize_in_memory_torrents_repository(); let () = in_memory_torrent_repository.upsert_peer(&sample_info_hash(), &leecher()); @@ -865,7 +781,7 @@ mod tests { #[tokio::test] async fn it_should_get_many_the_torrent_metrics() { - let (_tracker, in_memory_torrent_repository) = public_tracker_and_in_memory_torrents_repository(); + let in_memory_torrent_repository = initialize_in_memory_torrents_repository(); let start_time = std::time::Instant::now(); for i in 0..1_000_000 { @@ -1000,7 +916,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_announce_data_with_an_empty_peer_list_when_it_is_the_first_announced_peer() { - let (_tracker, announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); let mut peer = sample_peer(); @@ -1011,7 +927,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_announce_data_with_the_previously_announced_peers() { - let (_tracker, announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); let mut previously_announced_peer = sample_peer_1(); announce_handler.announce( @@ -1036,7 +952,7 @@ mod tests { #[tokio::test] async fn when_the_peer_is_a_seeder() { - let (_tracker, announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); let mut peer = seeder(); @@ -1048,7 +964,7 @@ mod tests { #[tokio::test] async fn when_the_peer_is_a_leecher() { - let (_tracker, announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); let mut peer = leecher(); @@ -1060,7 +976,7 @@ mod tests { #[tokio::test] async fn when_a_previously_announced_started_peer_has_completed_downloading() { - let (_tracker, announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); + let (announce_handler, _in_memory_torrent_repository, _scrape_handler) = public_tracker(); // We have to announce with "started" event because peer does not count if peer was not previously known let mut started_peer = started_peer(); @@ -1088,7 +1004,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_swarm_metadata_for_the_requested_file_if_the_tracker_has_that_torrent() { - let (_tracker, announce_handler, _in_memory_torrent_repository, scrape_handler) = public_tracker(); + let (announce_handler, _in_memory_torrent_repository, scrape_handler) = public_tracker(); let info_hash = "3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0".parse::().unwrap(); // # DevSkim: ignore DS173237 @@ -1136,8 +1052,7 @@ mod tests { #[tokio::test] async fn it_should_authorize_the_announce_and_scrape_actions_on_whitelisted_torrents() { - let (_tracker, _announce_handler, whitelist_authorization, whitelist_manager, _scrape_handler) = - whitelisted_tracker(); + let (_announce_handler, whitelist_authorization, whitelist_manager, _scrape_handler) = whitelisted_tracker(); let info_hash = sample_info_hash(); @@ -1150,8 +1065,7 @@ mod tests { #[tokio::test] async fn it_should_not_authorize_the_announce_and_scrape_actions_on_not_whitelisted_torrents() { - let (_tracker, _announce_handler, whitelist_authorization, _whitelist_manager, _scrape_handler) = - whitelisted_tracker(); + let (_announce_handler, whitelist_authorization, _whitelist_manager, _scrape_handler) = whitelisted_tracker(); let info_hash = sample_info_hash(); @@ -1170,8 +1084,7 @@ mod tests { #[tokio::test] async fn it_should_add_a_torrent_to_the_whitelist() { - let (_tracker, _announce_handler, _whitelist_authorization, whitelist_manager, _scrape_handler) = - whitelisted_tracker(); + let (_announce_handler, _whitelist_authorization, whitelist_manager, _scrape_handler) = whitelisted_tracker(); let info_hash = sample_info_hash(); @@ -1182,8 +1095,7 @@ mod tests { #[tokio::test] async fn it_should_remove_a_torrent_from_the_whitelist() { - let (_tracker, _announce_handler, _whitelist_authorization, whitelist_manager, _scrape_handler) = - whitelisted_tracker(); + let (_announce_handler, _whitelist_authorization, whitelist_manager, _scrape_handler) = whitelisted_tracker(); let info_hash = sample_info_hash(); @@ -1199,7 +1111,7 @@ mod tests { #[tokio::test] async fn it_should_load_the_whitelist_from_the_database() { - let (_tracker, _announce_handler, _whitelist_authorization, whitelist_manager, _scrape_handler) = + let (_announce_handler, _whitelist_authorization, whitelist_manager, _scrape_handler) = whitelisted_tracker(); let info_hash = sample_info_hash(); @@ -1244,8 +1156,7 @@ mod tests { #[tokio::test] async fn it_should_return_the_zeroed_swarm_metadata_for_the_requested_file_if_it_is_not_whitelisted() { - let (_tracker, announce_handler, _whitelist_authorization, _whitelist_manager, scrape_handler) = - whitelisted_tracker(); + let (announce_handler, _whitelist_authorization, _whitelist_manager, scrape_handler) = whitelisted_tracker(); let info_hash = "3b245504cf5f11bbdbe1201cea6a6bf45aee1bc0".parse::().unwrap(); // # DevSkim: ignore DS173237 @@ -1279,7 +1190,7 @@ mod tests { #[tokio::test] async fn it_should_persist_the_number_of_completed_peers_for_all_torrents_into_the_database() { - let (_tracker, announce_handler, torrents_manager, in_memory_torrent_repository) = + let (announce_handler, torrents_manager, in_memory_torrent_repository) = tracker_persisting_torrents_in_database(); let info_hash = sample_info_hash(); diff --git a/src/core/services/mod.rs b/src/core/services/mod.rs index a6cf54d60..73328aaeb 100644 --- a/src/core/services/mod.rs +++ b/src/core/services/mod.rs @@ -14,31 +14,9 @@ use torrust_tracker_configuration::v2_0_0::database; use torrust_tracker_configuration::Configuration; use super::databases::{self, Database}; -use super::torrent::repository::in_memory::InMemoryTorrentRepository; -use super::torrent::repository::persisted::DatabasePersistentTorrentRepository; use super::whitelist::manager::WhiteListManager; use super::whitelist::repository::in_memory::InMemoryWhitelist; use super::whitelist::repository::persisted::DatabaseWhitelist; -use crate::core::Tracker; - -/// It returns a new tracker building its dependencies. -/// -/// # Panics -/// -/// Will panic if tracker cannot be instantiated. -#[must_use] -pub fn initialize_tracker( - config: &Configuration, - in_memory_torrent_repository: &Arc, - db_torrent_repository: &Arc, -) -> Tracker { - match Tracker::new(&Arc::new(config).core, in_memory_torrent_repository, db_torrent_repository) { - Ok(tracker) => tracker, - Err(error) => { - panic!("{}", error) - } - } -} /// # Panics /// diff --git a/src/core/services/statistics/mod.rs b/src/core/services/statistics/mod.rs index 680504607..18d96605e 100644 --- a/src/core/services/statistics/mod.rs +++ b/src/core/services/statistics/mod.rs @@ -118,7 +118,6 @@ mod tests { use torrust_tracker_test_helpers::configuration; use crate::app_test::initialize_tracker_dependencies; - use crate::core::services::initialize_tracker; use crate::core::services::statistics::{self, get_metrics, TrackerMetrics}; use crate::core::{self}; use crate::servers::udp::server::banning::BanService; @@ -138,19 +137,13 @@ mod tests { _whitelist_authorization, _authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); 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(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let ban_service = Arc::new(RwLock::new(BanService::new(MAX_CONNECTION_ID_ERRORS_PER_IP))); let tracker_metrics = get_metrics( diff --git a/src/core/services/torrent.rs b/src/core/services/torrent.rs index 5faaef1d1..6ae2c26a4 100644 --- a/src/core/services/torrent.rs +++ b/src/core/services/torrent.rs @@ -119,28 +119,20 @@ mod tests { use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch}; use crate::app_test::initialize_tracker_dependencies; - use crate::core::services::initialize_tracker; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; - use crate::core::Tracker; - fn initialize_tracker_and_deps(config: &Configuration) -> (Arc, Arc) { + fn initialize_in_memory_torrent_repository(config: &Configuration) -> Arc { let ( _database, _in_memory_whitelist, _whitelist_authorization, _authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(config); - let tracker = Arc::new(initialize_tracker( - config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - - (tracker, in_memory_torrent_repository) + in_memory_torrent_repository } fn sample_peer() -> peer::Peer { @@ -164,7 +156,7 @@ mod tests { use torrust_tracker_configuration::Configuration; use torrust_tracker_test_helpers::configuration; - use crate::core::services::torrent::tests::{initialize_tracker_and_deps, sample_peer}; + use crate::core::services::torrent::tests::{initialize_in_memory_torrent_repository, sample_peer}; use crate::core::services::torrent::{get_torrent_info, Info}; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; @@ -189,7 +181,7 @@ mod tests { async fn should_return_the_torrent_info_if_the_tracker_has_the_torrent() { let config = tracker_configuration(); - let (_tracker, in_memory_torrent_repository) = initialize_tracker_and_deps(&config); + let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config); let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); let info_hash = InfoHash::from_str(&hash).unwrap(); @@ -221,7 +213,7 @@ mod tests { use torrust_tracker_configuration::Configuration; use torrust_tracker_test_helpers::configuration; - use crate::core::services::torrent::tests::{initialize_tracker_and_deps, sample_peer}; + use crate::core::services::torrent::tests::{initialize_in_memory_torrent_repository, sample_peer}; use crate::core::services::torrent::{get_torrents_page, BasicInfo, Pagination}; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; @@ -242,7 +234,7 @@ mod tests { async fn should_return_a_summarized_info_for_all_torrents() { let config = tracker_configuration(); - let (_tracker, in_memory_torrent_repository) = initialize_tracker_and_deps(&config); + let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config); let hash = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); let info_hash = InfoHash::from_str(&hash).unwrap(); @@ -266,7 +258,7 @@ mod tests { async fn should_allow_limiting_the_number_of_torrents_in_the_result() { let config = tracker_configuration(); - let (_tracker, in_memory_torrent_repository) = initialize_tracker_and_deps(&config); + let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config); let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); let info_hash1 = InfoHash::from_str(&hash1).unwrap(); @@ -289,7 +281,7 @@ mod tests { async fn should_allow_using_pagination_in_the_result() { let config = tracker_configuration(); - let (_tracker, in_memory_torrent_repository) = initialize_tracker_and_deps(&config); + let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config); let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); let info_hash1 = InfoHash::from_str(&hash1).unwrap(); @@ -321,7 +313,7 @@ mod tests { async fn should_return_torrents_ordered_by_info_hash() { let config = tracker_configuration(); - let (_tracker, in_memory_torrent_repository) = initialize_tracker_and_deps(&config); + let in_memory_torrent_repository = initialize_in_memory_torrent_repository(&config); let hash1 = "9e0217d0fa71c87332cd8bf9dbeabcb2c2cf3c4d".to_owned(); let info_hash1 = InfoHash::from_str(&hash1).unwrap(); diff --git a/src/servers/http/server.rs b/src/servers/http/server.rs index 3817882df..28f407ad3 100644 --- a/src/servers/http/server.rs +++ b/src/servers/http/server.rs @@ -15,7 +15,7 @@ use crate::bootstrap::jobs::Started; use crate::core::announce_handler::AnnounceHandler; use crate::core::authentication::service::AuthenticationService; use crate::core::scrape_handler::ScrapeHandler; -use crate::core::{statistics, whitelist, Tracker}; +use crate::core::{statistics, whitelist}; use crate::servers::custom_axum_server::{self, TimeoutAcceptor}; use crate::servers::http::HTTP_TRACKER_LOG_TARGET; use crate::servers::logging::STARTED_ON; @@ -49,7 +49,6 @@ impl Launcher { #[allow(clippy::too_many_arguments)] #[instrument(skip( self, - tracker, announce_handler, scrape_handler, authentication_service, @@ -61,7 +60,6 @@ impl Launcher { fn start( &self, config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, authentication_service: Arc, @@ -88,7 +86,6 @@ impl Launcher { let app = router( config, - tracker, announce_handler, scrape_handler, authentication_service, @@ -192,7 +189,6 @@ impl HttpServer { pub async fn start( self, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, authentication_service: Arc, @@ -208,7 +204,6 @@ impl HttpServer { let task = tokio::spawn(async move { let server = launcher.start( core_config, - tracker, announce_handler, scrape_handler, authentication_service, @@ -315,7 +310,6 @@ mod tests { let started = stopped .start( Arc::new(cfg.core.clone()), - app_container.tracker, app_container.announce_handler, app_container.scrape_handler, app_container.authentication_service, diff --git a/src/servers/http/v1/handlers/announce.rs b/src/servers/http/v1/handlers/announce.rs index ebdb717c3..632688763 100644 --- a/src/servers/http/v1/handlers/announce.rs +++ b/src/servers/http/v1/handlers/announce.rs @@ -26,7 +26,7 @@ use crate::core::announce_handler::{AnnounceHandler, PeersWanted}; use crate::core::authentication::service::AuthenticationService; use crate::core::authentication::Key; use crate::core::statistics::event::sender::Sender; -use crate::core::{whitelist, Tracker}; +use crate::core::whitelist; use crate::servers::http::v1::extractors::announce_request::ExtractRequest; use crate::servers::http::v1::extractors::authentication_key::Extract as ExtractKey; use crate::servers::http::v1::extractors::client_ip_sources::Extract as ExtractClientIpSources; @@ -41,7 +41,6 @@ use crate::CurrentClock; pub async fn handle_without_key( State(state): State<( Arc, - Arc, Arc, Arc, Arc, @@ -58,7 +57,6 @@ pub async fn handle_without_key( &state.2, &state.3, &state.4, - &state.5, &announce_request, &client_ip_sources, None, @@ -73,7 +71,6 @@ pub async fn handle_without_key( pub async fn handle_with_key( State(state): State<( Arc, - Arc, Arc, Arc, Arc, @@ -91,7 +88,6 @@ pub async fn handle_with_key( &state.2, &state.3, &state.4, - &state.5, &announce_request, &client_ip_sources, Some(key), @@ -106,7 +102,6 @@ pub async fn handle_with_key( #[allow(clippy::too_many_arguments)] async fn handle( config: &Arc, - tracker: &Arc, announce_handler: &Arc, authentication_service: &Arc, whitelist_authorization: &Arc, @@ -117,7 +112,6 @@ async fn handle( ) -> Response { let announce_data = match handle_announce( config, - tracker, announce_handler, authentication_service, whitelist_authorization, @@ -143,7 +137,6 @@ async fn handle( #[allow(clippy::too_many_arguments)] async fn handle_announce( core_config: &Arc, - tracker: &Arc, announce_handler: &Arc, authentication_service: &Arc, whitelist_authorization: &Arc, @@ -185,7 +178,6 @@ async fn handle_announce( }; let announce_data = services::announce::invoke( - tracker.clone(), announce_handler.clone(), opt_stats_event_sender.clone(), announce_request.info_hash, @@ -265,13 +257,12 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::AnnounceHandler; use crate::core::authentication::service::AuthenticationService; - use crate::core::services::{initialize_tracker, statistics}; + use crate::core::services::statistics; use crate::core::statistics::event::sender::Sender; - use crate::core::{whitelist, Tracker}; + use crate::core::whitelist; type TrackerAndDeps = ( Arc, - Arc, Arc, Arc>>, Arc, @@ -309,12 +300,6 @@ 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 = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -325,7 +310,6 @@ mod tests { ( config, - tracker, announce_handler, stats_event_sender, whitelist_authorization, @@ -373,17 +357,15 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_authentication_key_is_missing() { - let (config, tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = + let (config, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = private_tracker(); - let tracker = Arc::new(tracker); let stats_event_sender = Arc::new(stats_event_sender); let maybe_key = None; let response = handle_announce( &config, - &tracker, &announce_handler, &authentication_service, &whitelist_authorization, @@ -403,10 +385,9 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_authentication_key_is_invalid() { - let (config, tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = + let (config, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = private_tracker(); - let tracker = Arc::new(tracker); let stats_event_sender = Arc::new(stats_event_sender); let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); @@ -415,7 +396,6 @@ mod tests { let response = handle_announce( &config, - &tracker, &announce_handler, &authentication_service, &whitelist_authorization, @@ -441,17 +421,15 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_announced_torrent_is_not_whitelisted() { - let (config, tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = + let (config, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = whitelisted_tracker(); - let tracker = Arc::new(tracker); let stats_event_sender = Arc::new(stats_event_sender); let announce_request = sample_announce_request(); let response = handle_announce( &config, - &tracker, &announce_handler, &authentication_service, &whitelist_authorization, @@ -485,10 +463,9 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_right_most_x_forwarded_for_header_ip_is_not_available() { - let (config, tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = + let (config, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = tracker_on_reverse_proxy(); - let tracker = Arc::new(tracker); let stats_event_sender = Arc::new(stats_event_sender); let client_ip_sources = ClientIpSources { @@ -498,7 +475,6 @@ mod tests { let response = handle_announce( &config, - &tracker, &announce_handler, &authentication_service, &whitelist_authorization, @@ -529,10 +505,9 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_client_ip_from_the_connection_info_is_not_available() { - let (config, tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = + let (config, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) = tracker_not_on_reverse_proxy(); - let tracker = Arc::new(tracker); let stats_event_sender = Arc::new(stats_event_sender); let client_ip_sources = ClientIpSources { @@ -542,7 +517,6 @@ mod tests { let response = handle_announce( &config, - &tracker, &announce_handler, &authentication_service, &whitelist_authorization, diff --git a/src/servers/http/v1/handlers/scrape.rs b/src/servers/http/v1/handlers/scrape.rs index 4f47a066f..c4013d8e9 100644 --- a/src/servers/http/v1/handlers/scrape.rs +++ b/src/servers/http/v1/handlers/scrape.rs @@ -20,7 +20,6 @@ use crate::core::authentication::service::AuthenticationService; use crate::core::authentication::Key; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::Tracker; use crate::servers::http::v1::extractors::authentication_key::Extract as ExtractKey; use crate::servers::http::v1::extractors::client_ip_sources::Extract as ExtractClientIpSources; use crate::servers::http::v1::extractors::scrape_request::ExtractRequest; @@ -33,7 +32,6 @@ use crate::servers::http::v1::services; pub async fn handle_without_key( State(state): State<( Arc, - Arc, Arc, Arc, Arc>>, @@ -48,7 +46,6 @@ pub async fn handle_without_key( &state.1, &state.2, &state.3, - &state.4, &scrape_request, &client_ip_sources, None, @@ -65,7 +62,6 @@ pub async fn handle_without_key( pub async fn handle_with_key( State(state): State<( Arc, - Arc, Arc, Arc, Arc>>, @@ -81,7 +77,6 @@ pub async fn handle_with_key( &state.1, &state.2, &state.3, - &state.4, &scrape_request, &client_ip_sources, Some(key), @@ -92,7 +87,6 @@ pub async fn handle_with_key( #[allow(clippy::too_many_arguments)] async fn handle( core_config: &Arc, - tracker: &Arc, scrape_handler: &Arc, authentication_service: &Arc, stats_event_sender: &Arc>>, @@ -102,7 +96,6 @@ async fn handle( ) -> Response { let scrape_data = match handle_scrape( core_config, - tracker, scrape_handler, authentication_service, stats_event_sender, @@ -127,7 +120,6 @@ async fn handle( #[allow(clippy::too_many_arguments)] async fn handle_scrape( core_config: &Arc, - _tracker: &Arc, scrape_handler: &Arc, authentication_service: &Arc, opt_stats_event_sender: &Arc>>, @@ -185,13 +177,11 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::authentication::service::AuthenticationService; use crate::core::scrape_handler::ScrapeHandler; - use crate::core::services::{initialize_tracker, statistics}; - use crate::core::Tracker; + use crate::core::services::statistics; #[allow(clippy::type_complexity)] fn private_tracker() -> ( Arc, - Arc, Arc, Arc>>, Arc, @@ -204,7 +194,7 @@ mod tests { whitelist_authorization, authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); @@ -214,27 +204,14 @@ mod tests { let core_config = Arc::new(config.core.clone()); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - ( - core_config, - tracker, - scrape_handler, - stats_event_sender, - authentication_service, - ) + (core_config, scrape_handler, stats_event_sender, authentication_service) } #[allow(clippy::type_complexity)] fn whitelisted_tracker() -> ( Arc, - Arc, Arc, Arc>>, Arc, @@ -247,7 +224,7 @@ mod tests { whitelist_authorization, authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); @@ -257,27 +234,14 @@ mod tests { let core_config = Arc::new(config.core.clone()); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - ( - core_config, - tracker, - scrape_handler, - stats_event_sender, - authentication_service, - ) + (core_config, scrape_handler, stats_event_sender, authentication_service) } #[allow(clippy::type_complexity)] fn tracker_on_reverse_proxy() -> ( Arc, - Arc, Arc, Arc>>, Arc, @@ -290,7 +254,7 @@ mod tests { whitelist_authorization, authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); @@ -300,27 +264,14 @@ mod tests { let core_config = Arc::new(config.core.clone()); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - ( - core_config, - tracker, - scrape_handler, - stats_event_sender, - authentication_service, - ) + (core_config, scrape_handler, stats_event_sender, authentication_service) } #[allow(clippy::type_complexity)] fn tracker_not_on_reverse_proxy() -> ( Arc, - Arc, Arc, Arc>>, Arc, @@ -333,7 +284,7 @@ mod tests { whitelist_authorization, authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); @@ -343,21 +294,9 @@ mod tests { let core_config = Arc::new(config.core.clone()); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - ( - core_config, - tracker, - scrape_handler, - stats_event_sender, - authentication_service, - ) + (core_config, scrape_handler, stats_event_sender, authentication_service) } fn sample_scrape_request() -> Scrape { @@ -391,14 +330,13 @@ mod tests { #[tokio::test] async fn it_should_return_zeroed_swarm_metadata_when_the_authentication_key_is_missing() { - let (core_config, tracker, scrape_handler, stats_event_sender, authentication_service) = private_tracker(); + let (core_config, scrape_handler, stats_event_sender, authentication_service) = private_tracker(); let scrape_request = sample_scrape_request(); let maybe_key = None; let scrape_data = handle_scrape( &core_config, - &tracker, &scrape_handler, &authentication_service, &stats_event_sender, @@ -416,7 +354,7 @@ mod tests { #[tokio::test] async fn it_should_return_zeroed_swarm_metadata_when_the_authentication_key_is_invalid() { - let (core_config, tracker, scrape_handler, stats_event_sender, authentication_service) = private_tracker(); + let (core_config, scrape_handler, stats_event_sender, authentication_service) = private_tracker(); let scrape_request = sample_scrape_request(); let unregistered_key = authentication::Key::from_str("YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ").unwrap(); @@ -424,7 +362,6 @@ mod tests { let scrape_data = handle_scrape( &core_config, - &tracker, &scrape_handler, &authentication_service, &stats_event_sender, @@ -450,13 +387,12 @@ mod tests { #[tokio::test] async fn it_should_return_zeroed_swarm_metadata_when_the_torrent_is_not_whitelisted() { - let (core_config, tracker, scrape_handler, stats_event_sender, authentication_service) = whitelisted_tracker(); + let (core_config, scrape_handler, stats_event_sender, authentication_service) = whitelisted_tracker(); let scrape_request = sample_scrape_request(); let scrape_data = handle_scrape( &core_config, - &tracker, &scrape_handler, &authentication_service, &stats_event_sender, @@ -483,7 +419,7 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_right_most_x_forwarded_for_header_ip_is_not_available() { - let (core_config, tracker, scrape_handler, stats_event_sender, authentication_service) = tracker_on_reverse_proxy(); + let (core_config, scrape_handler, stats_event_sender, authentication_service) = tracker_on_reverse_proxy(); let client_ip_sources = ClientIpSources { right_most_x_forwarded_for: None, @@ -492,7 +428,6 @@ mod tests { let response = handle_scrape( &core_config, - &tracker, &scrape_handler, &authentication_service, &stats_event_sender, @@ -520,8 +455,7 @@ mod tests { #[tokio::test] async fn it_should_fail_when_the_client_ip_from_the_connection_info_is_not_available() { - let (core_config, tracker, scrape_handler, stats_event_sender, authentication_service) = - tracker_not_on_reverse_proxy(); + let (core_config, scrape_handler, stats_event_sender, authentication_service) = tracker_not_on_reverse_proxy(); let client_ip_sources = ClientIpSources { right_most_x_forwarded_for: None, @@ -530,7 +464,6 @@ mod tests { let response = handle_scrape( &core_config, - &tracker, &scrape_handler, &authentication_service, &stats_event_sender, diff --git a/src/servers/http/v1/routes.rs b/src/servers/http/v1/routes.rs index 85564ca8c..757a7d1bd 100644 --- a/src/servers/http/v1/routes.rs +++ b/src/servers/http/v1/routes.rs @@ -26,7 +26,7 @@ use crate::core::announce_handler::AnnounceHandler; use crate::core::authentication::service::AuthenticationService; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{whitelist, Tracker}; +use crate::core::whitelist; use crate::servers::http::HTTP_TRACKER_LOG_TARGET; use crate::servers::logging::Latency; @@ -37,7 +37,6 @@ use crate::servers::logging::Latency; #[allow(clippy::too_many_arguments)] #[allow(clippy::needless_pass_by_value)] #[instrument(skip( - tracker, announce_handler, scrape_handler, authentication_service, @@ -47,7 +46,6 @@ use crate::servers::logging::Latency; ))] pub fn router( core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, authentication_service: Arc, @@ -63,7 +61,6 @@ pub fn router( "/announce", get(announce::handle_without_key).with_state(( core_config.clone(), - tracker.clone(), announce_handler.clone(), authentication_service.clone(), whitelist_authorization.clone(), @@ -74,7 +71,6 @@ pub fn router( "/announce/{key}", get(announce::handle_with_key).with_state(( core_config.clone(), - tracker.clone(), announce_handler.clone(), authentication_service.clone(), whitelist_authorization.clone(), @@ -86,7 +82,6 @@ pub fn router( "/scrape", get(scrape::handle_without_key).with_state(( core_config.clone(), - tracker.clone(), scrape_handler.clone(), authentication_service.clone(), stats_event_sender.clone(), @@ -96,7 +91,6 @@ pub fn router( "/scrape/{key}", get(scrape::handle_with_key).with_state(( core_config.clone(), - tracker.clone(), scrape_handler.clone(), authentication_service.clone(), stats_event_sender.clone(), diff --git a/src/servers/http/v1/services/announce.rs b/src/servers/http/v1/services/announce.rs index 5e2e8f716..e70377fd6 100644 --- a/src/servers/http/v1/services/announce.rs +++ b/src/servers/http/v1/services/announce.rs @@ -17,7 +17,6 @@ use torrust_tracker_primitives::peer; use crate::core::announce_handler::{AnnounceHandler, PeersWanted}; use crate::core::statistics::event::sender::Sender; use crate::core::statistics::{self}; -use crate::core::Tracker; /// The HTTP tracker `announce` service. /// @@ -30,7 +29,6 @@ use crate::core::Tracker; /// > like the UDP tracker, the number of TCP connections is incremented for /// > each `announce` request. pub async fn invoke( - _tracker: Arc, announce_handler: Arc, opt_stats_event_sender: Arc>>, info_hash: InfoHash, @@ -69,12 +67,11 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::AnnounceHandler; - use crate::core::services::{initialize_tracker, statistics}; + use crate::core::services::statistics; use crate::core::statistics::event::sender::Sender; - use crate::core::Tracker; #[allow(clippy::type_complexity)] - fn public_tracker() -> (Arc, Arc, Arc, Arc>>) { + fn public_tracker() -> (Arc, Arc, Arc>>) { let config = configuration::ephemeral_public(); let ( @@ -89,12 +86,6 @@ 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 = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -103,7 +94,7 @@ mod tests { let core_config = Arc::new(config.core.clone()); - (core_config, tracker, announce_handler, stats_event_sender) + (core_config, announce_handler, stats_event_sender) } fn sample_info_hash() -> InfoHash { @@ -149,11 +140,11 @@ mod tests { use super::{sample_peer_using_ipv4, sample_peer_using_ipv6}; use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::{AnnounceHandler, PeersWanted}; - use crate::core::{statistics, Tracker}; + use crate::core::statistics; use crate::servers::http::v1::services::announce::invoke; use crate::servers::http::v1::services::announce::tests::{public_tracker, sample_info_hash, sample_peer}; - fn initialize_tracker_and_announce_handler() -> (Arc, Arc) { + fn initialize_announce_handler() -> Arc { let config = configuration::ephemeral(); let ( @@ -166,25 +157,20 @@ mod tests { _torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(Tracker::new(&config.core, &in_memory_torrent_repository, &db_torrent_repository).unwrap()); - - let announce_handler = Arc::new(AnnounceHandler::new( + Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, &db_torrent_repository, - )); - - (tracker, announce_handler) + )) } #[tokio::test] async fn it_should_return_the_announce_data() { - let (core_config, tracker, announce_handler, stats_event_sender) = public_tracker(); + let (core_config, announce_handler, stats_event_sender) = public_tracker(); let mut peer = sample_peer(); let announce_data = invoke( - tracker.clone(), announce_handler.clone(), stats_event_sender.clone(), sample_info_hash(), @@ -217,12 +203,11 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let (tracker, announce_handler) = initialize_tracker_and_announce_handler(); + let announce_handler = initialize_announce_handler(); let mut peer = sample_peer_using_ipv4(); let _announce_data = invoke( - tracker, announce_handler, stats_event_sender, sample_info_hash(), @@ -232,13 +217,13 @@ mod tests { .await; } - fn tracker_with_an_ipv6_external_ip() -> (Arc, Arc) { + fn tracker_with_an_ipv6_external_ip() -> Arc { let mut configuration = configuration::ephemeral(); configuration.core.net.external_ip = Some(IpAddr::V6(Ipv6Addr::new( 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, ))); - initialize_tracker_and_announce_handler() + initialize_announce_handler() } fn peer_with_the_ipv4_loopback_ip() -> peer::Peer { @@ -265,10 +250,9 @@ mod tests { let mut peer = peer_with_the_ipv4_loopback_ip(); - let (tracker, announce_handler) = tracker_with_an_ipv6_external_ip(); + let announce_handler = tracker_with_an_ipv6_external_ip(); let _announce_data = invoke( - tracker, announce_handler, stats_event_sender, sample_info_hash(), @@ -290,12 +274,11 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let (tracker, announce_handler) = initialize_tracker_and_announce_handler(); + let announce_handler = initialize_announce_handler(); let mut peer = sample_peer_using_ipv6(); let _announce_data = invoke( - tracker, announce_handler, stats_event_sender, sample_info_hash(), diff --git a/src/servers/http/v1/services/scrape.rs b/src/servers/http/v1/services/scrape.rs index 6df267d3a..06c21d945 100644 --- a/src/servers/http/v1/services/scrape.rs +++ b/src/servers/http/v1/services/scrape.rs @@ -83,10 +83,8 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; - use crate::core::services::initialize_tracker; - use crate::core::Tracker; - fn public_tracker_and_announce_and_scrape_handlers() -> (Arc, Arc, Arc) { + fn public_tracker_and_announce_and_scrape_handlers() -> (Arc, Arc) { let config = configuration::ephemeral_public(); let ( @@ -99,12 +97,6 @@ mod tests { _torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(initialize_tracker( - &config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -113,7 +105,7 @@ mod tests { let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - (tracker, announce_handler, scrape_handler) + (announce_handler, scrape_handler) } fn sample_info_hashes() -> Vec { @@ -136,7 +128,7 @@ mod tests { } } - fn test_tracker_factory() -> (Arc, Arc) { + fn initialize_scrape_handler() -> Arc { let config = configuration::ephemeral(); let ( @@ -145,15 +137,11 @@ mod tests { whitelist_authorization, _authentication_service, in_memory_torrent_repository, - db_torrent_repository, + _db_torrent_repository, _torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(Tracker::new(&config.core, &in_memory_torrent_repository, &db_torrent_repository).unwrap()); - - let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - - (tracker, scrape_handler) + Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)) } mod with_real_data { @@ -170,8 +158,8 @@ mod tests { use crate::core::statistics; use crate::servers::http::v1::services::scrape::invoke; use crate::servers::http::v1::services::scrape::tests::{ - public_tracker_and_announce_and_scrape_handlers, sample_info_hash, sample_info_hashes, sample_peer, - test_tracker_factory, + initialize_scrape_handler, public_tracker_and_announce_and_scrape_handlers, sample_info_hash, sample_info_hashes, + sample_peer, }; #[tokio::test] @@ -179,7 +167,7 @@ mod tests { let (stats_event_sender, _stats_repository) = crate::core::services::statistics::setup::factory(false); let stats_event_sender = Arc::new(stats_event_sender); - let (_tracker, announce_handler, scrape_handler) = public_tracker_and_announce_and_scrape_handlers(); + let (announce_handler, scrape_handler) = public_tracker_and_announce_and_scrape_handlers(); let info_hash = sample_info_hash(); let info_hashes = vec![info_hash]; @@ -215,7 +203,7 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let (_tracker, scrape_handler) = test_tracker_factory(); + let scrape_handler = initialize_scrape_handler(); let peer_ip = IpAddr::V4(Ipv4Addr::new(126, 0, 0, 1)); @@ -233,7 +221,7 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let (_tracker, scrape_handler) = test_tracker_factory(); + let scrape_handler = initialize_scrape_handler(); let peer_ip = IpAddr::V6(Ipv6Addr::new(0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969, 0x6969)); @@ -262,7 +250,7 @@ mod tests { let (stats_event_sender, _stats_repository) = crate::core::services::statistics::setup::factory(false); let stats_event_sender = Arc::new(stats_event_sender); - let (_tracker, announce_handler, _scrape_handler) = public_tracker_and_announce_and_scrape_handlers(); + let (announce_handler, _scrape_handler) = public_tracker_and_announce_and_scrape_handlers(); let info_hash = sample_info_hash(); let info_hashes = vec![info_hash]; diff --git a/src/servers/udp/handlers.rs b/src/servers/udp/handlers.rs index b3ec1cb06..5589331a7 100644 --- a/src/servers/udp/handlers.rs +++ b/src/servers/udp/handlers.rs @@ -24,7 +24,7 @@ use super::RawRequest; use crate::core::announce_handler::{AnnounceHandler, PeersWanted}; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{statistics, whitelist, Tracker}; +use crate::core::{statistics, whitelist}; use crate::servers::udp::error::Error; use crate::servers::udp::{peer_builder, UDP_TRACKER_LOG_TARGET}; use crate::shared::bit_torrent::common::MAX_SCRAPE_TORRENTS; @@ -58,11 +58,10 @@ impl CookieTimeValues { /// /// It will return an `Error` response if the request is invalid. #[allow(clippy::too_many_arguments)] -#[instrument(fields(request_id), skip(udp_request, tracker, announce_handler, scrape_handler, whitelist_authorization, opt_stats_event_sender, cookie_time_values, ban_service), ret(level = Level::TRACE))] +#[instrument(fields(request_id), skip(udp_request, announce_handler, scrape_handler, whitelist_authorization, opt_stats_event_sender, cookie_time_values, ban_service), ret(level = Level::TRACE))] pub(crate) async fn handle_packet( udp_request: RawRequest, core_config: &Arc, - tracker: &Tracker, announce_handler: &Arc, scrape_handler: &Arc, whitelist_authorization: &Arc, @@ -84,7 +83,6 @@ pub(crate) async fn handle_packet( request, udp_request.from, core_config, - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -147,7 +145,6 @@ pub(crate) async fn handle_packet( #[instrument(skip( request, remote_addr, - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -158,7 +155,6 @@ pub async fn handle_request( request: Request, remote_addr: SocketAddr, core_config: &Arc, - tracker: &Tracker, announce_handler: &Arc, scrape_handler: &Arc, whitelist_authorization: &Arc, @@ -180,7 +176,6 @@ pub async fn handle_request( remote_addr, &announce_request, core_config, - tracker, announce_handler, whitelist_authorization, opt_stats_event_sender, @@ -246,12 +241,11 @@ pub async fn handle_connect( /// /// If a error happens in the `handle_announce` function, it will just return the `ServerError`. #[allow(clippy::too_many_arguments)] -#[instrument(fields(transaction_id, connection_id, info_hash), skip(_tracker, announce_handler, whitelist_authorization, opt_stats_event_sender), ret(level = Level::TRACE))] +#[instrument(fields(transaction_id, connection_id, info_hash), skip(announce_handler, whitelist_authorization, opt_stats_event_sender), ret(level = Level::TRACE))] pub async fn handle_announce( remote_addr: SocketAddr, request: &AnnounceRequest, core_config: &Arc, - _tracker: &Tracker, announce_handler: &Arc, whitelist_authorization: &Arc, opt_stats_event_sender: &Arc>>, @@ -507,17 +501,16 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; - use crate::core::services::{initialize_tracker, initialize_whitelist_manager, statistics}; + use crate::core::services::{initialize_whitelist_manager, statistics}; use crate::core::statistics::event::sender::Sender; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; + use crate::core::whitelist; use crate::core::whitelist::manager::WhiteListManager; use crate::core::whitelist::repository::in_memory::InMemoryWhitelist; - use crate::core::{whitelist, Tracker}; use crate::CurrentClock; type TrackerAndDeps = ( Arc, - Arc, Arc, Arc, Arc, @@ -560,12 +553,6 @@ mod tests { let stats_event_sender = Arc::new(stats_event_sender); let whitelist_manager = initialize_whitelist_manager(database.clone(), in_memory_whitelist.clone()); - let tracker = Arc::new(initialize_tracker( - config, - &in_memory_torrent_repository, - &db_torrent_repository, - )); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -576,7 +563,6 @@ mod tests { ( core_config, - tracker, announce_handler, scrape_handler, in_memory_torrent_repository, @@ -684,7 +670,6 @@ mod tests { #[allow(clippy::type_complexity)] fn test_tracker_factory() -> ( Arc, - Arc, Arc, Arc, Arc, @@ -703,8 +688,6 @@ mod tests { _torrents_manager, ) = initialize_tracker_dependencies(&config); - let tracker = Arc::new(Tracker::new(&config.core, &in_memory_torrent_repository, &db_torrent_repository).unwrap()); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -713,13 +696,7 @@ mod tests { let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository)); - ( - core_config, - tracker, - announce_handler, - scrape_handler, - whitelist_authorization, - ) + (core_config, announce_handler, scrape_handler, whitelist_authorization) } mod connect_request { @@ -935,7 +912,7 @@ mod tests { use crate::core::announce_handler::AnnounceHandler; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; - use crate::core::{self, statistics, whitelist}; + use crate::core::{statistics, whitelist}; use crate::servers::udp::connection_cookie::make; use crate::servers::udp::handlers::tests::announce_request::AnnounceRequestBuilder; use crate::servers::udp::handlers::tests::{ @@ -948,7 +925,6 @@ mod tests { async fn an_announced_peer_should_be_added_to_the_tracker() { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -977,7 +953,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1000,7 +975,6 @@ mod tests { async fn the_announced_peer_should_not_be_included_in_the_response() { let ( core_config, - tracker, announce_handler, _scrape_handler, _in_memory_torrent_repository, @@ -1020,7 +994,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1052,7 +1025,6 @@ mod tests { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -1084,7 +1056,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1116,7 +1087,6 @@ mod tests { async fn announce_a_new_peer_using_ipv4( core_config: Arc, - tracker: Arc, announce_handler: Arc, whitelist_authorization: Arc, ) -> Response { @@ -1132,7 +1102,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1146,7 +1115,6 @@ mod tests { async fn when_the_announce_request_comes_from_a_client_using_ipv4_the_response_should_not_include_peers_using_ipv6() { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -1158,13 +1126,8 @@ mod tests { add_a_torrent_peer_using_ipv6(&in_memory_torrent_repository); - let response = announce_a_new_peer_using_ipv4( - core_config.clone(), - tracker.clone(), - announce_handler.clone(), - whitelist_authorization, - ) - .await; + let response = + announce_a_new_peer_using_ipv4(core_config.clone(), announce_handler.clone(), whitelist_authorization).await; // The response should not contain the peer using IPV6 let peers: Option>> = match response { @@ -1186,13 +1149,12 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let (core_config, tracker, announce_handler, _scrape_handler, whitelist_authorization) = test_tracker_factory(); + let (core_config, announce_handler, _scrape_handler, whitelist_authorization) = test_tracker_factory(); handle_announce( sample_ipv4_socket_address(), &AnnounceRequestBuilder::default().into(), &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1219,7 +1181,6 @@ mod tests { async fn the_peer_ip_should_be_changed_to_the_external_ip_in_the_tracker_configuration_if_defined() { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -1248,7 +1209,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1286,7 +1246,7 @@ mod tests { use crate::core::announce_handler::AnnounceHandler; use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository; - use crate::core::{self, statistics, whitelist}; + use crate::core::{statistics, whitelist}; use crate::servers::udp::connection_cookie::make; use crate::servers::udp::handlers::tests::announce_request::AnnounceRequestBuilder; use crate::servers::udp::handlers::tests::{ @@ -1299,7 +1259,6 @@ mod tests { async fn an_announced_peer_should_be_added_to_the_tracker() { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -1329,7 +1288,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1352,7 +1310,6 @@ mod tests { async fn the_announced_peer_should_not_be_included_in_the_response() { let ( core_config, - tracker, announce_handler, _scrape_handler, _in_memory_torrent_repository, @@ -1375,7 +1332,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1407,7 +1363,6 @@ mod tests { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -1439,7 +1394,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1471,7 +1425,6 @@ mod tests { async fn announce_a_new_peer_using_ipv6( core_config: Arc, - tracker: Arc, announce_handler: Arc, whitelist_authorization: Arc, ) -> Response { @@ -1490,7 +1443,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1504,7 +1456,6 @@ mod tests { async fn when_the_announce_request_comes_from_a_client_using_ipv6_the_response_should_not_include_peers_using_ipv4() { let ( core_config, - tracker, announce_handler, _scrape_handler, in_memory_torrent_repository, @@ -1516,13 +1467,8 @@ mod tests { add_a_torrent_peer_using_ipv4(&in_memory_torrent_repository); - let response = announce_a_new_peer_using_ipv6( - core_config.clone(), - tracker.clone(), - announce_handler.clone(), - whitelist_authorization, - ) - .await; + let response = + announce_a_new_peer_using_ipv6(core_config.clone(), announce_handler.clone(), whitelist_authorization).await; // The response should not contain the peer using IPV4 let peers: Option>> = match response { @@ -1544,7 +1490,7 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let (core_config, tracker, announce_handler, _scrape_handler, whitelist_authorization) = test_tracker_factory(); + let (core_config, announce_handler, _scrape_handler, whitelist_authorization) = test_tracker_factory(); let remote_addr = sample_ipv6_remote_addr(); @@ -1556,7 +1502,6 @@ mod tests { remote_addr, &announce_request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1576,7 +1521,7 @@ mod tests { use crate::app_test::initialize_tracker_dependencies; use crate::core::announce_handler::AnnounceHandler; - use crate::core::{self, statistics}; + use crate::core::statistics; use crate::servers::udp::connection_cookie::make; use crate::servers::udp::handlers::handle_announce; use crate::servers::udp::handlers::tests::announce_request::AnnounceRequestBuilder; @@ -1607,10 +1552,6 @@ mod tests { let stats_event_sender: Arc>> = Arc::new(Some(Box::new(stats_event_sender_mock))); - let tracker = Arc::new( - core::Tracker::new(&config.core, &in_memory_torrent_repository, &db_torrent_repository).unwrap(), - ); - let announce_handler = Arc::new(AnnounceHandler::new( &config.core, &in_memory_torrent_repository, @@ -1643,7 +1584,6 @@ mod tests { remote_addr, &request, &core_config, - &tracker, &announce_handler, &whitelist_authorization, &stats_event_sender, @@ -1700,7 +1640,6 @@ mod tests { async fn should_return_no_stats_when_the_tracker_does_not_have_any_torrent() { let ( _core_config, - _tracker, _announce_handler, scrape_handler, _in_memory_torrent_repository, @@ -1810,7 +1749,6 @@ mod tests { async fn should_return_torrent_statistics_when_the_tracker_has_the_requested_torrent() { let ( _core_config, - _tracker, _announce_handler, scrape_handler, in_memory_torrent_repository, @@ -1847,7 +1785,6 @@ mod tests { async fn should_return_the_torrent_statistics_when_the_requested_torrent_is_whitelisted() { let ( _core_config, - _tracker, _announce_handler, scrape_handler, in_memory_torrent_repository, @@ -1892,7 +1829,6 @@ mod tests { async fn should_return_zeroed_statistics_when_the_requested_torrent_is_not_whitelisted() { let ( _core_config, - _tracker, _announce_handler, scrape_handler, in_memory_torrent_repository, @@ -1965,8 +1901,7 @@ mod tests { let remote_addr = sample_ipv4_remote_addr(); - let (_core_config, _tracker, _announce_handler, scrape_handler, _whitelist_authorization) = - test_tracker_factory(); + let (_core_config, _announce_handler, scrape_handler, _whitelist_authorization) = test_tracker_factory(); handle_scrape( remote_addr, @@ -2006,8 +1941,7 @@ mod tests { let remote_addr = sample_ipv6_remote_addr(); - let (_core_config, _tracker, _announce_handler, scrape_handler, _whitelist_authorization) = - test_tracker_factory(); + let (_core_config, _announce_handler, scrape_handler, _whitelist_authorization) = test_tracker_factory(); handle_scrape( remote_addr, diff --git a/src/servers/udp/mod.rs b/src/servers/udp/mod.rs index 9b4d90c89..b141cc322 100644 --- a/src/servers/udp/mod.rs +++ b/src/servers/udp/mod.rs @@ -52,8 +52,7 @@ //! is designed to be as simple as possible. It uses a single UDP port and //! supports only three types of requests: `Connect`, `Announce` and `Scrape`. //! -//! Request are parsed from UDP packets using the [`aquatic_udp_protocol`](https://crates.io/crates/aquatic_udp_protocol) -//! crate and then handled by the [`Tracker`](crate::core::Tracker) struct. +//! Request are parsed from UDP packets using the [`aquatic_udp_protocol`](https://crates.io/crates/aquatic_udp_protocol). //! And then the response is also build using the [`aquatic_udp_protocol`](https://crates.io/crates/aquatic_udp_protocol) //! and converted to a UDP packet. //! diff --git a/src/servers/udp/server/launcher.rs b/src/servers/udp/server/launcher.rs index d0ae14029..f1b14860d 100644 --- a/src/servers/udp/server/launcher.rs +++ b/src/servers/udp/server/launcher.rs @@ -17,7 +17,7 @@ use crate::bootstrap::jobs::Started; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{statistics, whitelist, Tracker}; +use crate::core::{statistics, whitelist}; use crate::servers::logging::STARTED_ON; use crate::servers::registar::ServiceHealthCheckJob; use crate::servers::signals::{shutdown_signal_with_message, Halted}; @@ -45,7 +45,6 @@ impl Launcher { /// It panics if the udp server is loaded when the tracker is private. #[allow(clippy::too_many_arguments)] #[instrument(skip( - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -57,7 +56,6 @@ impl Launcher { ))] pub async fn run_with_graceful_shutdown( core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -103,7 +101,6 @@ impl Launcher { let () = Self::run_udp_server_main( receiver, core_config.clone(), - tracker.clone(), announce_handler.clone(), scrape_handler.clone(), whitelist_authorization.clone(), @@ -151,7 +148,6 @@ impl Launcher { #[allow(clippy::too_many_arguments)] #[instrument(skip( receiver, - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -161,7 +157,6 @@ impl Launcher { async fn run_udp_server_main( mut receiver: Receiver, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -235,7 +230,6 @@ impl Launcher { let processor = Processor::new( receiver.socket.clone(), core_config.clone(), - tracker.clone(), announce_handler.clone(), scrape_handler.clone(), whitelist_authorization.clone(), diff --git a/src/servers/udp/server/mod.rs b/src/servers/udp/server/mod.rs index f93d84a65..c87728361 100644 --- a/src/servers/udp/server/mod.rs +++ b/src/servers/udp/server/mod.rs @@ -83,7 +83,6 @@ mod tests { let started = stopped .start( Arc::new(cfg.core.clone()), - app_container.tracker, app_container.announce_handler, app_container.scrape_handler, app_container.whitelist_authorization, @@ -119,7 +118,6 @@ mod tests { let started = stopped .start( Arc::new(cfg.core.clone()), - app_container.tracker, app_container.announce_handler, app_container.scrape_handler, app_container.whitelist_authorization, diff --git a/src/servers/udp/server/processor.rs b/src/servers/udp/server/processor.rs index 0bb7c92c4..475a36b74 100644 --- a/src/servers/udp/server/processor.rs +++ b/src/servers/udp/server/processor.rs @@ -15,14 +15,13 @@ use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; use crate::core::statistics::event::UdpResponseKind; -use crate::core::{statistics, whitelist, Tracker}; +use crate::core::{statistics, whitelist}; use crate::servers::udp::handlers::CookieTimeValues; use crate::servers::udp::{handlers, RawRequest}; pub struct Processor { socket: Arc, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -35,7 +34,6 @@ impl Processor { pub fn new( socket: Arc, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -45,7 +43,6 @@ impl Processor { Self { socket, core_config, - tracker, announce_handler, scrape_handler, whitelist_authorization, @@ -63,7 +60,6 @@ impl Processor { let response = handlers::handle_packet( request, &self.core_config, - &self.tracker, &self.announce_handler, &self.scrape_handler, &self.whitelist_authorization, diff --git a/src/servers/udp/server/spawner.rs b/src/servers/udp/server/spawner.rs index ced5fbf4a..2415b2631 100644 --- a/src/servers/udp/server/spawner.rs +++ b/src/servers/udp/server/spawner.rs @@ -15,7 +15,7 @@ use crate::bootstrap::jobs::Started; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{whitelist, Tracker}; +use crate::core::whitelist; use crate::servers::signals::Halted; #[derive(Constructor, Copy, Clone, Debug, Display)] @@ -34,7 +34,6 @@ impl Spawner { pub fn spawn_launcher( &self, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -49,7 +48,6 @@ impl Spawner { tokio::spawn(async move { Launcher::run_with_graceful_shutdown( core_config, - tracker, announce_handler, scrape_handler, whitelist_authorization, diff --git a/src/servers/udp/server/states.rs b/src/servers/udp/server/states.rs index 4d63dc0a8..4d18593fe 100644 --- a/src/servers/udp/server/states.rs +++ b/src/servers/udp/server/states.rs @@ -17,7 +17,7 @@ use crate::bootstrap::jobs::Started; use crate::core::announce_handler::AnnounceHandler; use crate::core::scrape_handler::ScrapeHandler; use crate::core::statistics::event::sender::Sender; -use crate::core::{whitelist, Tracker}; +use crate::core::whitelist; use crate::servers::registar::{ServiceRegistration, ServiceRegistrationForm}; use crate::servers::signals::Halted; use crate::servers::udp::server::launcher::Launcher; @@ -68,11 +68,10 @@ impl Server { /// /// It panics if unable to receive the bound socket address from service. #[allow(clippy::too_many_arguments)] - #[instrument(skip(self, tracker, announce_handler, scrape_handler, whitelist_authorization, opt_stats_event_sender, ban_service, form), err, ret(Display, level = Level::INFO))] + #[instrument(skip(self, announce_handler, scrape_handler, whitelist_authorization, opt_stats_event_sender, ban_service, form), err, ret(Display, level = Level::INFO))] pub async fn start( self, core_config: Arc, - tracker: Arc, announce_handler: Arc, scrape_handler: Arc, whitelist_authorization: Arc, @@ -89,7 +88,6 @@ impl Server { // May need to wrap in a task to about a tokio bug. let task = self.state.spawner.spawn_launcher( core_config, - tracker, announce_handler, scrape_handler, whitelist_authorization, diff --git a/tests/servers/api/environment.rs b/tests/servers/api/environment.rs index 927f76efe..3488456e7 100644 --- a/tests/servers/api/environment.rs +++ b/tests/servers/api/environment.rs @@ -15,7 +15,6 @@ use torrust_tracker_lib::core::statistics::event::sender::Sender; use torrust_tracker_lib::core::statistics::repository::Repository; use torrust_tracker_lib::core::torrent::repository::in_memory::InMemoryTorrentRepository; use torrust_tracker_lib::core::whitelist::manager::WhiteListManager; -use torrust_tracker_lib::core::Tracker; use torrust_tracker_lib::servers::apis::server::{ApiServer, Launcher, Running, Stopped}; use torrust_tracker_lib::servers::registar::Registar; use torrust_tracker_lib::servers::udp::server::banning::BanService; @@ -27,7 +26,6 @@ where { pub config: Arc, pub database: Arc>, - pub tracker: Arc, pub in_memory_torrent_repository: Arc, pub keys_handler: Arc, pub authentication_service: Arc, @@ -66,7 +64,6 @@ impl Environment { Self { config, database: app_container.database.clone(), - tracker: app_container.tracker.clone(), in_memory_torrent_repository: app_container.in_memory_torrent_repository.clone(), keys_handler: app_container.keys_handler.clone(), authentication_service: app_container.authentication_service.clone(), @@ -85,7 +82,6 @@ impl Environment { Environment { config: self.config, database: self.database.clone(), - tracker: self.tracker.clone(), in_memory_torrent_repository: self.in_memory_torrent_repository.clone(), keys_handler: self.keys_handler.clone(), authentication_service: self.authentication_service.clone(), @@ -121,7 +117,6 @@ impl Environment { Environment { config: self.config, database: self.database, - tracker: self.tracker, in_memory_torrent_repository: self.in_memory_torrent_repository, keys_handler: self.keys_handler, authentication_service: self.authentication_service, diff --git a/tests/servers/http/environment.rs b/tests/servers/http/environment.rs index 203dc880e..589430848 100644 --- a/tests/servers/http/environment.rs +++ b/tests/servers/http/environment.rs @@ -13,8 +13,8 @@ use torrust_tracker_lib::core::scrape_handler::ScrapeHandler; use torrust_tracker_lib::core::statistics::event::sender::Sender; use torrust_tracker_lib::core::statistics::repository::Repository; use torrust_tracker_lib::core::torrent::repository::in_memory::InMemoryTorrentRepository; +use torrust_tracker_lib::core::whitelist; use torrust_tracker_lib::core::whitelist::manager::WhiteListManager; -use torrust_tracker_lib::core::{whitelist, Tracker}; use torrust_tracker_lib::servers::http::server::{HttpServer, Launcher, Running, Stopped}; use torrust_tracker_lib::servers::registar::Registar; use torrust_tracker_primitives::peer; @@ -23,7 +23,6 @@ pub struct Environment { pub core_config: Arc, pub http_tracker_config: Arc, pub database: Arc>, - pub tracker: Arc, pub announce_handler: Arc, pub scrape_handler: Arc, pub in_memory_torrent_repository: Arc, @@ -68,7 +67,6 @@ impl Environment { http_tracker_config: config, core_config: Arc::new(configuration.core.clone()), database: app_container.database.clone(), - tracker: app_container.tracker.clone(), announce_handler: app_container.announce_handler.clone(), scrape_handler: app_container.scrape_handler.clone(), in_memory_torrent_repository: app_container.in_memory_torrent_repository.clone(), @@ -89,7 +87,6 @@ impl Environment { http_tracker_config: self.http_tracker_config, core_config: self.core_config.clone(), database: self.database.clone(), - tracker: self.tracker.clone(), announce_handler: self.announce_handler.clone(), scrape_handler: self.scrape_handler.clone(), in_memory_torrent_repository: self.in_memory_torrent_repository.clone(), @@ -104,7 +101,6 @@ impl Environment { .server .start( self.core_config, - self.tracker, self.announce_handler, self.scrape_handler, self.authentication_service, @@ -128,7 +124,6 @@ impl Environment { http_tracker_config: self.http_tracker_config, core_config: self.core_config, database: self.database, - tracker: self.tracker, announce_handler: self.announce_handler, scrape_handler: self.scrape_handler, in_memory_torrent_repository: self.in_memory_torrent_repository, diff --git a/tests/servers/udp/environment.rs b/tests/servers/udp/environment.rs index 11967aeed..a6ddd7a83 100644 --- a/tests/servers/udp/environment.rs +++ b/tests/servers/udp/environment.rs @@ -11,7 +11,7 @@ use torrust_tracker_lib::core::scrape_handler::ScrapeHandler; use torrust_tracker_lib::core::statistics::event::sender::Sender; use torrust_tracker_lib::core::statistics::repository::Repository; use torrust_tracker_lib::core::torrent::repository::in_memory::InMemoryTorrentRepository; -use torrust_tracker_lib::core::{whitelist, Tracker}; +use torrust_tracker_lib::core::whitelist; use torrust_tracker_lib::servers::registar::Registar; use torrust_tracker_lib::servers::udp::server::banning::BanService; use torrust_tracker_lib::servers::udp::server::spawner::Spawner; @@ -26,7 +26,6 @@ where pub core_config: Arc, pub config: Arc, pub database: Arc>, - pub tracker: Arc, pub in_memory_torrent_repository: Arc, pub announce_handler: Arc, pub scrape_handler: Arc, @@ -68,7 +67,6 @@ impl Environment { core_config: Arc::new(configuration.core.clone()), config, database: app_container.database.clone(), - tracker: app_container.tracker.clone(), in_memory_torrent_repository: app_container.in_memory_torrent_repository.clone(), announce_handler: app_container.announce_handler.clone(), scrape_handler: app_container.scrape_handler.clone(), @@ -88,7 +86,6 @@ impl Environment { core_config: self.core_config.clone(), config: self.config, database: self.database.clone(), - tracker: self.tracker.clone(), in_memory_torrent_repository: self.in_memory_torrent_repository.clone(), announce_handler: self.announce_handler.clone(), scrape_handler: self.scrape_handler.clone(), @@ -101,7 +98,6 @@ impl Environment { .server .start( self.core_config, - self.tracker, self.announce_handler, self.scrape_handler, self.whitelist_authorization, @@ -133,7 +129,6 @@ impl Environment { core_config: self.core_config, config: self.config, database: self.database, - tracker: self.tracker, in_memory_torrent_repository: self.in_memory_torrent_repository, announce_handler: self.announce_handler, scrape_handler: self.scrape_handler,