forked from torrust/torrust-tracker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontainer.rs
75 lines (65 loc) · 3.31 KB
/
container.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use std::sync::Arc;
use bittorrent_tracker_core::announce_handler::AnnounceHandler;
use bittorrent_tracker_core::authentication::service::AuthenticationService;
use bittorrent_tracker_core::container::TrackerCoreContainer;
use bittorrent_tracker_core::scrape_handler::ScrapeHandler;
use bittorrent_tracker_core::whitelist;
use torrust_tracker_configuration::{Core, HttpTracker};
use crate::services::announce::AnnounceService;
use crate::services::scrape::ScrapeService;
use crate::{event, statistics};
pub struct HttpTrackerCoreContainer {
// todo: replace with TrackerCoreContainer
pub core_config: Arc<Core>,
pub announce_handler: Arc<AnnounceHandler>,
pub scrape_handler: Arc<ScrapeHandler>,
pub whitelist_authorization: Arc<whitelist::authorization::WhitelistAuthorization>,
pub authentication_service: Arc<AuthenticationService>,
pub http_tracker_config: Arc<HttpTracker>,
pub http_stats_event_sender: Arc<Option<Box<dyn event::sender::Sender>>>,
pub http_stats_repository: Arc<statistics::repository::Repository>,
pub announce_service: Arc<AnnounceService>,
pub scrape_service: Arc<ScrapeService>,
}
impl HttpTrackerCoreContainer {
#[must_use]
pub fn initialize(core_config: &Arc<Core>, http_tracker_config: &Arc<HttpTracker>) -> Arc<Self> {
let tracker_core_container = Arc::new(TrackerCoreContainer::initialize(core_config));
Self::initialize_from(&tracker_core_container, http_tracker_config)
}
#[must_use]
pub fn initialize_from(
tracker_core_container: &Arc<TrackerCoreContainer>,
http_tracker_config: &Arc<HttpTracker>,
) -> Arc<Self> {
let (http_stats_event_sender, http_stats_repository) =
statistics::setup::factory(tracker_core_container.core_config.tracker_usage_statistics);
let http_stats_event_sender = Arc::new(http_stats_event_sender);
let http_stats_repository = Arc::new(http_stats_repository);
let announce_service = Arc::new(AnnounceService::new(
tracker_core_container.core_config.clone(),
tracker_core_container.announce_handler.clone(),
tracker_core_container.authentication_service.clone(),
tracker_core_container.whitelist_authorization.clone(),
http_stats_event_sender.clone(),
));
let scrape_service = Arc::new(ScrapeService::new(
tracker_core_container.core_config.clone(),
tracker_core_container.scrape_handler.clone(),
tracker_core_container.authentication_service.clone(),
http_stats_event_sender.clone(),
));
Arc::new(Self {
core_config: tracker_core_container.core_config.clone(),
announce_handler: tracker_core_container.announce_handler.clone(),
scrape_handler: tracker_core_container.scrape_handler.clone(),
whitelist_authorization: tracker_core_container.whitelist_authorization.clone(),
authentication_service: tracker_core_container.authentication_service.clone(),
http_tracker_config: http_tracker_config.clone(),
http_stats_event_sender: http_stats_event_sender.clone(),
http_stats_repository: http_stats_repository.clone(),
announce_service: announce_service.clone(),
scrape_service: scrape_service.clone(),
})
}
}