Skip to content

Commit 0d42586

Browse files
committed
refactor: encapsule field TrackerCoreContainer in HttpTrackerCoreContainer
1 parent 9cee15e commit 0d42586

File tree

3 files changed

+15
-66
lines changed

3 files changed

+15
-66
lines changed

packages/axum-http-tracker-server/src/server.rs

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,7 @@ mod tests {
241241
use bittorrent_http_tracker_core::container::HttpTrackerCoreContainer;
242242
use bittorrent_http_tracker_core::services::announce::AnnounceService;
243243
use bittorrent_http_tracker_core::services::scrape::ScrapeService;
244-
use bittorrent_tracker_core::announce_handler::AnnounceHandler;
245-
use bittorrent_tracker_core::authentication::key::repository::in_memory::InMemoryKeyRepository;
246-
use bittorrent_tracker_core::authentication::service;
247-
use bittorrent_tracker_core::databases::setup::initialize_database;
248-
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
249-
use bittorrent_tracker_core::torrent::repository::in_memory::InMemoryTorrentRepository;
250-
use bittorrent_tracker_core::torrent::repository::persisted::DatabasePersistentTorrentRepository;
251-
use bittorrent_tracker_core::whitelist::authorization::WhitelistAuthorization;
252-
use bittorrent_tracker_core::whitelist::repository::in_memory::InMemoryWhitelist;
244+
use bittorrent_tracker_core::container::TrackerCoreContainer;
253245
use torrust_axum_server::tsl::make_rust_tls;
254246
use torrust_server_lib::registar::Registar;
255247
use torrust_tracker_configuration::{logging, Configuration};
@@ -275,48 +267,25 @@ mod tests {
275267
let http_stats_event_sender = Arc::new(http_stats_event_sender);
276268
let http_stats_repository = Arc::new(http_stats_repository);
277269

278-
let database = initialize_database(&configuration.core);
279-
let in_memory_whitelist = Arc::new(InMemoryWhitelist::default());
280-
let whitelist_authorization = Arc::new(WhitelistAuthorization::new(&configuration.core, &in_memory_whitelist.clone()));
281-
let in_memory_key_repository = Arc::new(InMemoryKeyRepository::default());
282-
let authentication_service = Arc::new(service::AuthenticationService::new(
283-
&configuration.core,
284-
&in_memory_key_repository,
285-
));
286-
let in_memory_torrent_repository = Arc::new(InMemoryTorrentRepository::default());
287-
let db_torrent_repository = Arc::new(DatabasePersistentTorrentRepository::new(&database));
288-
289-
let announce_handler = Arc::new(AnnounceHandler::new(
290-
&configuration.core,
291-
&whitelist_authorization,
292-
&in_memory_torrent_repository,
293-
&db_torrent_repository,
294-
));
295-
296-
let scrape_handler = Arc::new(ScrapeHandler::new(&whitelist_authorization, &in_memory_torrent_repository));
270+
let tracker_core_container = Arc::new(TrackerCoreContainer::initialize(&core_config));
297271

298272
let announce_service = Arc::new(AnnounceService::new(
299-
core_config.clone(),
300-
announce_handler.clone(),
301-
authentication_service.clone(),
302-
whitelist_authorization.clone(),
273+
tracker_core_container.core_config.clone(),
274+
tracker_core_container.announce_handler.clone(),
275+
tracker_core_container.authentication_service.clone(),
276+
tracker_core_container.whitelist_authorization.clone(),
303277
http_stats_event_sender.clone(),
304278
));
305279

306280
let scrape_service = Arc::new(ScrapeService::new(
307-
core_config.clone(),
308-
scrape_handler.clone(),
309-
authentication_service.clone(),
281+
tracker_core_container.core_config.clone(),
282+
tracker_core_container.scrape_handler.clone(),
283+
tracker_core_container.authentication_service.clone(),
310284
http_stats_event_sender.clone(),
311285
));
312286

313287
HttpTrackerCoreContainer {
314-
core_config,
315-
announce_handler,
316-
scrape_handler,
317-
whitelist_authorization,
318-
authentication_service,
319-
288+
tracker_core_container,
320289
http_tracker_config,
321290
http_stats_event_sender,
322291
http_stats_repository,

packages/http-tracker-core/src/container.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
use std::sync::Arc;
22

3-
use bittorrent_tracker_core::announce_handler::AnnounceHandler;
4-
use bittorrent_tracker_core::authentication::service::AuthenticationService;
53
use bittorrent_tracker_core::container::TrackerCoreContainer;
6-
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
7-
use bittorrent_tracker_core::whitelist;
84
use torrust_tracker_configuration::{Core, HttpTracker};
95

106
use crate::services::announce::AnnounceService;
117
use crate::services::scrape::ScrapeService;
128
use crate::{event, statistics};
139

1410
pub struct HttpTrackerCoreContainer {
15-
// todo: replace with TrackerCoreContainer
16-
pub core_config: Arc<Core>,
17-
pub announce_handler: Arc<AnnounceHandler>,
18-
pub scrape_handler: Arc<ScrapeHandler>,
19-
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
20-
pub authentication_service: Arc<AuthenticationService>,
21-
11+
pub tracker_core_container: Arc<TrackerCoreContainer>,
2212
pub http_tracker_config: Arc<HttpTracker>,
2313
pub http_stats_event_sender: Arc<Option<Box<dyn event::sender::Sender>>>,
2414
pub http_stats_repository: Arc<statistics::repository::Repository>,
@@ -59,12 +49,7 @@ impl HttpTrackerCoreContainer {
5949
));
6050

6151
Arc::new(Self {
62-
core_config: tracker_core_container.core_config.clone(),
63-
announce_handler: tracker_core_container.announce_handler.clone(),
64-
scrape_handler: tracker_core_container.scrape_handler.clone(),
65-
whitelist_authorization: tracker_core_container.whitelist_authorization.clone(),
66-
authentication_service: tracker_core_container.authentication_service.clone(),
67-
52+
tracker_core_container: tracker_core_container.clone(),
6853
http_tracker_config: http_tracker_config.clone(),
6954
http_stats_event_sender: http_stats_event_sender.clone(),
7055
http_stats_repository: http_stats_repository.clone(),

src/container.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use tracing::instrument;
2525
*/
2626

2727
pub struct AppContainer {
28-
pub tracker_core_container: TrackerCoreContainer,
28+
pub tracker_core_container: Arc<TrackerCoreContainer>,
2929

3030
// UDP Tracker Core Services
3131
pub udp_core_stats_event_sender: Arc<Option<Box<dyn bittorrent_udp_tracker_core::event::sender::Sender>>>,
@@ -51,7 +51,7 @@ impl AppContainer {
5151
pub fn initialize(configuration: &Configuration) -> AppContainer {
5252
let core_config = Arc::new(configuration.core.clone());
5353

54-
let tracker_core_container = TrackerCoreContainer::initialize(&core_config);
54+
let tracker_core_container = Arc::new(TrackerCoreContainer::initialize(&core_config));
5555

5656
// HTTP Tracker Core Services
5757
let (http_stats_event_sender, http_stats_repository) =
@@ -123,12 +123,7 @@ impl AppContainer {
123123
#[must_use]
124124
pub fn http_tracker_container(&self, http_tracker_config: &Arc<HttpTracker>) -> HttpTrackerCoreContainer {
125125
HttpTrackerCoreContainer {
126-
core_config: self.tracker_core_container.core_config.clone(),
127-
announce_handler: self.tracker_core_container.announce_handler.clone(),
128-
scrape_handler: self.tracker_core_container.scrape_handler.clone(),
129-
whitelist_authorization: self.tracker_core_container.whitelist_authorization.clone(),
130-
authentication_service: self.tracker_core_container.authentication_service.clone(),
131-
126+
tracker_core_container: self.tracker_core_container.clone(),
132127
http_tracker_config: http_tracker_config.clone(),
133128
http_stats_event_sender: self.http_stats_event_sender.clone(),
134129
http_stats_repository: self.http_stats_repository.clone(),

0 commit comments

Comments
 (0)