Skip to content

Commit 046578d

Browse files
committed
refactor: [#1203] use directly the InMemoryTorrentRepository
1 parent 0f1b2fb commit 046578d

File tree

16 files changed

+233
-139
lines changed

16 files changed

+233
-139
lines changed

src/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub async fn start(config: &Configuration, app_container: &AppContainer) -> Vec<
118118
if let Some(http_api_config) = &config.http_api {
119119
if let Some(job) = tracker_apis::start_job(
120120
http_api_config,
121-
app_container.tracker.clone(),
121+
app_container.in_memory_torrent_repository.clone(),
122122
app_container.keys_handler.clone(),
123123
app_container.whitelist_manager.clone(),
124124
app_container.ban_service.clone(),

src/bootstrap/jobs/tracker_apis.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use super::make_rust_tls;
3333
use crate::core::authentication::handler::KeysHandler;
3434
use crate::core::statistics::event::sender::Sender;
3535
use crate::core::statistics::repository::Repository;
36+
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
3637
use crate::core::whitelist::manager::WhiteListManager;
37-
use crate::core::{self};
3838
use crate::servers::apis::server::{ApiServer, Launcher};
3939
use crate::servers::apis::Version;
4040
use crate::servers::registar::ServiceRegistrationForm;
@@ -63,7 +63,6 @@ pub struct ApiServerJobStarted();
6363
#[allow(clippy::too_many_arguments)]
6464
#[instrument(skip(
6565
config,
66-
tracker,
6766
keys_handler,
6867
whitelist_manager,
6968
ban_service,
@@ -73,7 +72,7 @@ pub struct ApiServerJobStarted();
7372
))]
7473
pub async fn start_job(
7574
config: &HttpApi,
76-
tracker: Arc<core::Tracker>,
75+
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
7776
keys_handler: Arc<KeysHandler>,
7877
whitelist_manager: Arc<WhiteListManager>,
7978
ban_service: Arc<RwLock<BanService>>,
@@ -95,7 +94,7 @@ pub async fn start_job(
9594
start_v1(
9695
bind_to,
9796
tls,
98-
tracker.clone(),
97+
in_memory_torrent_repository.clone(),
9998
keys_handler.clone(),
10099
whitelist_manager.clone(),
101100
ban_service.clone(),
@@ -114,7 +113,6 @@ pub async fn start_job(
114113
#[instrument(skip(
115114
socket,
116115
tls,
117-
tracker,
118116
keys_handler,
119117
whitelist_manager,
120118
ban_service,
@@ -126,7 +124,7 @@ pub async fn start_job(
126124
async fn start_v1(
127125
socket: SocketAddr,
128126
tls: Option<RustlsConfig>,
129-
tracker: Arc<core::Tracker>,
127+
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
130128
keys_handler: Arc<KeysHandler>,
131129
whitelist_manager: Arc<WhiteListManager>,
132130
ban_service: Arc<RwLock<BanService>>,
@@ -137,7 +135,7 @@ async fn start_v1(
137135
) -> JoinHandle<()> {
138136
let server = ApiServer::new(Launcher::new(socket, tls))
139137
.start(
140-
tracker,
138+
in_memory_torrent_repository,
141139
keys_handler,
142140
whitelist_manager,
143141
stats_event_sender,
@@ -179,7 +177,7 @@ mod tests {
179177

180178
start_job(
181179
config,
182-
app_container.tracker,
180+
app_container.in_memory_torrent_repository,
183181
app_container.keys_handler,
184182
app_container.whitelist_manager,
185183
app_container.ban_service,

src/core/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,10 @@ pub struct Tracker {
474474
config: Core,
475475

476476
/// The service to check is a torrent is whitelisted.
477-
pub whitelist_authorization: Arc<whitelist::authorization::Authorization>,
477+
whitelist_authorization: Arc<whitelist::authorization::Authorization>,
478478

479479
/// The in-memory torrents repository.
480-
pub in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
480+
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
481481

482482
/// The persistent torrents repository.
483483
db_torrent_repository: Arc<DatabasePersistentTorrentRepository>,
@@ -1325,24 +1325,24 @@ mod tests {
13251325

13261326
#[tokio::test]
13271327
async fn it_should_authorize_the_announce_and_scrape_actions_on_whitelisted_torrents() {
1328-
let (tracker, _whitelist_authorization, whitelist_manager) = whitelisted_tracker();
1328+
let (_tracker, whitelist_authorization, whitelist_manager) = whitelisted_tracker();
13291329

13301330
let info_hash = sample_info_hash();
13311331

13321332
let result = whitelist_manager.add_torrent_to_whitelist(&info_hash).await;
13331333
assert!(result.is_ok());
13341334

1335-
let result = tracker.whitelist_authorization.authorize(&info_hash).await;
1335+
let result = whitelist_authorization.authorize(&info_hash).await;
13361336
assert!(result.is_ok());
13371337
}
13381338

13391339
#[tokio::test]
13401340
async fn it_should_not_authorize_the_announce_and_scrape_actions_on_not_whitelisted_torrents() {
1341-
let (tracker, _whitelist_authorization, _whitelist_manager) = whitelisted_tracker();
1341+
let (_tracker, whitelist_authorization, _whitelist_manager) = whitelisted_tracker();
13421342

13431343
let info_hash = sample_info_hash();
13441344

1345-
let result = tracker.whitelist_authorization.authorize(&info_hash).await;
1345+
let result = whitelist_authorization.authorize(&info_hash).await;
13461346
assert!(result.is_err());
13471347
}
13481348
}

src/core/services/statistics/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use torrust_tracker_primitives::torrent_metrics::TorrentsMetrics;
4545

4646
use crate::core::statistics::metrics::Metrics;
4747
use crate::core::statistics::repository::Repository;
48-
use crate::core::Tracker;
48+
use crate::core::torrent::repository::in_memory::InMemoryTorrentRepository;
4949
use crate::servers::udp::server::banning::BanService;
5050

5151
/// All the metrics collected by the tracker.
@@ -64,11 +64,11 @@ pub struct TrackerMetrics {
6464

6565
/// It returns all the [`TrackerMetrics`]
6666
pub async fn get_metrics(
67-
tracker: Arc<Tracker>,
67+
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
6868
ban_service: Arc<RwLock<BanService>>,
6969
stats_repository: Arc<Repository>,
7070
) -> TrackerMetrics {
71-
let torrents_metrics = tracker.in_memory_torrent_repository.get_torrents_metrics();
71+
let torrents_metrics = in_memory_torrent_repository.get_torrents_metrics();
7272
let stats = stats_repository.get_stats().await;
7373
let udp_banned_ips_total = ban_service.read().await.get_banned_ips_total();
7474

@@ -145,7 +145,7 @@ mod tests {
145145
let (_stats_event_sender, stats_repository) = statistics::setup::factory(config.core.tracker_usage_statistics);
146146
let stats_repository = Arc::new(stats_repository);
147147

148-
let tracker = Arc::new(initialize_tracker(
148+
let _tracker = Arc::new(initialize_tracker(
149149
&config,
150150
&whitelist_authorization,
151151
&in_memory_torrent_repository,
@@ -154,7 +154,12 @@ mod tests {
154154

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

157-
let tracker_metrics = get_metrics(tracker.clone(), ban_service.clone(), stats_repository.clone()).await;
157+
let tracker_metrics = get_metrics(
158+
in_memory_torrent_repository.clone(),
159+
ban_service.clone(),
160+
stats_repository.clone(),
161+
)
162+
.await;
158163

159164
assert_eq!(
160165
tracker_metrics,

0 commit comments

Comments
 (0)