Skip to content

Commit 6e47314

Browse files
committed
Merge #1206: Overhaul core Tracker: extract scrape handler
3867bbb refactor: [#1205] extract ScrapeHandler (Jose Celano) Pull request description: Overhaul core Tracker: extract scrape handler. ACKs for top commit: josecelano: ACK 3867bbb Tree-SHA512: a5a8b1b82832e7acf59a7a5d5a9b47e6da2774cc992a24443415cf359d0ed0000e9372583772409a2d495ba07f4add4c9d3654bf934bf69ec221c656e33dc130
2 parents 731fd01 + 3867bbb commit 6e47314

24 files changed

+442
-275
lines changed

src/app.rs

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
8080
udp_tracker::start_job(
8181
udp_tracker_config,
8282
app_container.tracker.clone(),
83+
app_container.scrape_handler.clone(),
8384
app_container.whitelist_authorization.clone(),
8485
app_container.stats_event_sender.clone(),
8586
app_container.ban_service.clone(),
@@ -99,6 +100,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
99100
if let Some(job) = http_tracker::start_job(
100101
http_tracker_config,
101102
app_container.tracker.clone(),
103+
app_container.scrape_handler.clone(),
102104
app_container.authentication_service.clone(),
103105
app_container.whitelist_authorization.clone(),
104106
app_container.stats_event_sender.clone(),

src/bootstrap/app.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::core::authentication::handler::KeysHandler;
2626
use crate::core::authentication::key::repository::in_memory::InMemoryKeyRepository;
2727
use crate::core::authentication::key::repository::persisted::DatabaseKeyRepository;
2828
use crate::core::authentication::service;
29+
use crate::core::scrape_handler::ScrapeHandler;
2930
use crate::core::services::{initialize_database, initialize_tracker, initialize_whitelist_manager, statistics};
3031
use crate::core::torrent::manager::TorrentsManager;
3132
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
@@ -116,14 +117,16 @@ pub fn initialize_app_container(configuration: &Configuration) -> AppContainer {
116117

117118
let tracker = Arc::new(initialize_tracker(
118119
configuration,
119-
&whitelist_authorization,
120120
&in_memory_torrent_repository,
121121
&db_torrent_repository,
122122
));
123123

124+
let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository));
125+
124126
AppContainer {
125127
database,
126128
tracker,
129+
scrape_handler,
127130
keys_handler,
128131
authentication_service,
129132
whitelist_authorization,

src/bootstrap/jobs/http_tracker.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use tracing::instrument;
2020

2121
use super::make_rust_tls;
2222
use crate::core::authentication::service::AuthenticationService;
23+
use crate::core::scrape_handler::ScrapeHandler;
2324
use crate::core::statistics::event::sender::Sender;
2425
use crate::core::{self, statistics, whitelist};
2526
use crate::servers::http::server::{HttpServer, Launcher};
@@ -34,11 +35,20 @@ use crate::servers::registar::ServiceRegistrationForm;
3435
/// # Panics
3536
///
3637
/// It would panic if the `config::HttpTracker` struct would contain inappropriate values.
37-
///
38-
#[instrument(skip(config, tracker, authentication_service, whitelist_authorization, stats_event_sender, form))]
38+
#[allow(clippy::too_many_arguments)]
39+
#[instrument(skip(
40+
config,
41+
tracker,
42+
scrape_handler,
43+
authentication_service,
44+
whitelist_authorization,
45+
stats_event_sender,
46+
form
47+
))]
3948
pub async fn start_job(
4049
config: &HttpTracker,
4150
tracker: Arc<core::Tracker>,
51+
scrape_handler: Arc<ScrapeHandler>,
4252
authentication_service: Arc<AuthenticationService>,
4353
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
4454
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
@@ -57,6 +67,7 @@ pub async fn start_job(
5767
socket,
5868
tls,
5969
tracker.clone(),
70+
scrape_handler.clone(),
6071
authentication_service.clone(),
6172
whitelist_authorization.clone(),
6273
stats_event_sender.clone(),
@@ -67,12 +78,14 @@ pub async fn start_job(
6778
}
6879
}
6980

81+
#[allow(clippy::too_many_arguments)]
7082
#[allow(clippy::async_yields_async)]
71-
#[instrument(skip(socket, tls, tracker, whitelist_authorization, stats_event_sender, form))]
83+
#[instrument(skip(socket, tls, tracker, scrape_handler, whitelist_authorization, stats_event_sender, form))]
7284
async fn start_v1(
7385
socket: SocketAddr,
7486
tls: Option<RustlsConfig>,
7587
tracker: Arc<core::Tracker>,
88+
scrape_handler: Arc<ScrapeHandler>,
7689
authentication_service: Arc<AuthenticationService>,
7790
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
7891
stats_event_sender: Arc<Option<Box<dyn statistics::event::sender::Sender>>>,
@@ -81,6 +94,7 @@ async fn start_v1(
8194
let server = HttpServer::new(Launcher::new(socket, tls))
8295
.start(
8396
tracker,
97+
scrape_handler,
8498
authentication_service,
8599
whitelist_authorization,
86100
stats_event_sender,
@@ -128,6 +142,7 @@ mod tests {
128142
start_job(
129143
config,
130144
app_container.tracker,
145+
app_container.scrape_handler,
131146
app_container.authentication_service,
132147
app_container.whitelist_authorization,
133148
app_container.stats_event_sender,

src/bootstrap/jobs/udp_tracker.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tokio::task::JoinHandle;
1313
use torrust_tracker_configuration::UdpTracker;
1414
use tracing::instrument;
1515

16+
use crate::core::scrape_handler::ScrapeHandler;
1617
use crate::core::statistics::event::sender::Sender;
1718
use crate::core::{self, whitelist};
1819
use crate::servers::registar::ServiceRegistrationForm;
@@ -32,10 +33,19 @@ use crate::servers::udp::UDP_TRACKER_LOG_TARGET;
3233
/// It will panic if the task did not finish successfully.
3334
#[must_use]
3435
#[allow(clippy::async_yields_async)]
35-
#[instrument(skip(config, tracker, whitelist_authorization, stats_event_sender, ban_service, form))]
36+
#[instrument(skip(
37+
config,
38+
tracker,
39+
scrape_handler,
40+
whitelist_authorization,
41+
stats_event_sender,
42+
ban_service,
43+
form
44+
))]
3645
pub async fn start_job(
3746
config: &UdpTracker,
3847
tracker: Arc<core::Tracker>,
48+
scrape_handler: Arc<ScrapeHandler>,
3949
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
4050
stats_event_sender: Arc<Option<Box<dyn Sender>>>,
4151
ban_service: Arc<RwLock<BanService>>,
@@ -47,6 +57,7 @@ pub async fn start_job(
4757
let server = Server::new(Spawner::new(bind_to))
4858
.start(
4959
tracker,
60+
scrape_handler,
5061
whitelist_authorization,
5162
stats_event_sender,
5263
ban_service,

src/container.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use tokio::sync::RwLock;
55
use crate::core::authentication::handler::KeysHandler;
66
use crate::core::authentication::service::AuthenticationService;
77
use crate::core::databases::Database;
8+
use crate::core::scrape_handler::ScrapeHandler;
89
use crate::core::statistics::event::sender::Sender;
910
use crate::core::statistics::repository::Repository;
1011
use crate::core::torrent::manager::TorrentsManager;
@@ -17,6 +18,7 @@ use crate::servers::udp::server::banning::BanService;
1718
pub struct AppContainer {
1819
pub database: Arc<Box<dyn Database>>,
1920
pub tracker: Arc<Tracker>,
21+
pub scrape_handler: Arc<ScrapeHandler>,
2022
pub keys_handler: Arc<KeysHandler>,
2123
pub authentication_service: Arc<AuthenticationService>,
2224
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,

0 commit comments

Comments
 (0)