@@ -18,6 +18,7 @@ use bittorrent_http_protocol::v1::services::peer_ip_resolver;
18
18
use bittorrent_http_protocol:: v1:: services:: peer_ip_resolver:: ClientIpSources ;
19
19
use hyper:: StatusCode ;
20
20
use torrust_tracker_clock:: clock:: Time ;
21
+ use torrust_tracker_configuration:: Core ;
21
22
use torrust_tracker_primitives:: core:: AnnounceData ;
22
23
use torrust_tracker_primitives:: peer;
23
24
@@ -39,6 +40,7 @@ use crate::CurrentClock;
39
40
#[ allow( clippy:: type_complexity) ]
40
41
pub async fn handle_without_key (
41
42
State ( state) : State < (
43
+ Arc < Core > ,
42
44
Arc < Tracker > ,
43
45
Arc < AnnounceHandler > ,
44
46
Arc < AuthenticationService > ,
@@ -56,6 +58,7 @@ pub async fn handle_without_key(
56
58
& state. 2 ,
57
59
& state. 3 ,
58
60
& state. 4 ,
61
+ & state. 5 ,
59
62
& announce_request,
60
63
& client_ip_sources,
61
64
None ,
@@ -69,6 +72,7 @@ pub async fn handle_without_key(
69
72
#[ allow( clippy:: type_complexity) ]
70
73
pub async fn handle_with_key (
71
74
State ( state) : State < (
75
+ Arc < Core > ,
72
76
Arc < Tracker > ,
73
77
Arc < AnnounceHandler > ,
74
78
Arc < AuthenticationService > ,
@@ -87,6 +91,7 @@ pub async fn handle_with_key(
87
91
& state. 2 ,
88
92
& state. 3 ,
89
93
& state. 4 ,
94
+ & state. 5 ,
90
95
& announce_request,
91
96
& client_ip_sources,
92
97
Some ( key) ,
@@ -100,6 +105,7 @@ pub async fn handle_with_key(
100
105
/// `unauthenticated` modes.
101
106
#[ allow( clippy:: too_many_arguments) ]
102
107
async fn handle (
108
+ config : & Arc < Core > ,
103
109
tracker : & Arc < Tracker > ,
104
110
announce_handler : & Arc < AnnounceHandler > ,
105
111
authentication_service : & Arc < AuthenticationService > ,
@@ -110,6 +116,7 @@ async fn handle(
110
116
maybe_key : Option < Key > ,
111
117
) -> Response {
112
118
let announce_data = match handle_announce (
119
+ config,
113
120
tracker,
114
121
announce_handler,
115
122
authentication_service,
@@ -135,6 +142,7 @@ async fn handle(
135
142
136
143
#[ allow( clippy:: too_many_arguments) ]
137
144
async fn handle_announce (
145
+ config : & Arc < Core > ,
138
146
tracker : & Arc < Tracker > ,
139
147
announce_handler : & Arc < AnnounceHandler > ,
140
148
authentication_service : & Arc < AuthenticationService > ,
@@ -145,7 +153,7 @@ async fn handle_announce(
145
153
maybe_key : Option < Key > ,
146
154
) -> Result < AnnounceData , responses:: error:: Error > {
147
155
// Authentication
148
- if tracker . requires_authentication ( ) {
156
+ if config . private {
149
157
match maybe_key {
150
158
Some ( key) => match authentication_service. authenticate ( & key) . await {
151
159
Ok ( ( ) ) => ( ) ,
@@ -251,7 +259,7 @@ mod tests {
251
259
use bittorrent_http_protocol:: v1:: responses;
252
260
use bittorrent_http_protocol:: v1:: services:: peer_ip_resolver:: ClientIpSources ;
253
261
use bittorrent_primitives:: info_hash:: InfoHash ;
254
- use torrust_tracker_configuration:: Configuration ;
262
+ use torrust_tracker_configuration:: { Configuration , Core } ;
255
263
use torrust_tracker_test_helpers:: configuration;
256
264
257
265
use crate :: app_test:: initialize_tracker_dependencies;
@@ -262,6 +270,7 @@ mod tests {
262
270
use crate :: core:: { whitelist, Tracker } ;
263
271
264
272
type TrackerAndDeps = (
273
+ Arc < Core > ,
265
274
Arc < Tracker > ,
266
275
Arc < AnnounceHandler > ,
267
276
Arc < Option < Box < dyn Sender > > > ,
@@ -270,23 +279,23 @@ mod tests {
270
279
) ;
271
280
272
281
fn private_tracker ( ) -> TrackerAndDeps {
273
- initialize_tracker_and_deps ( & configuration:: ephemeral_private ( ) )
282
+ initialize_tracker_and_deps ( configuration:: ephemeral_private ( ) )
274
283
}
275
284
276
285
fn whitelisted_tracker ( ) -> TrackerAndDeps {
277
- initialize_tracker_and_deps ( & configuration:: ephemeral_listed ( ) )
286
+ initialize_tracker_and_deps ( configuration:: ephemeral_listed ( ) )
278
287
}
279
288
280
289
fn tracker_on_reverse_proxy ( ) -> TrackerAndDeps {
281
- initialize_tracker_and_deps ( & configuration:: ephemeral_with_reverse_proxy ( ) )
290
+ initialize_tracker_and_deps ( configuration:: ephemeral_with_reverse_proxy ( ) )
282
291
}
283
292
284
293
fn tracker_not_on_reverse_proxy ( ) -> TrackerAndDeps {
285
- initialize_tracker_and_deps ( & configuration:: ephemeral_without_reverse_proxy ( ) )
294
+ initialize_tracker_and_deps ( configuration:: ephemeral_without_reverse_proxy ( ) )
286
295
}
287
296
288
297
/// Initialize tracker's dependencies and tracker.
289
- fn initialize_tracker_and_deps ( config : & Configuration ) -> TrackerAndDeps {
298
+ fn initialize_tracker_and_deps ( config : Configuration ) -> TrackerAndDeps {
290
299
let (
291
300
_database,
292
301
_in_memory_whitelist,
@@ -295,13 +304,13 @@ mod tests {
295
304
in_memory_torrent_repository,
296
305
db_torrent_repository,
297
306
_torrents_manager,
298
- ) = initialize_tracker_dependencies ( config) ;
307
+ ) = initialize_tracker_dependencies ( & config) ;
299
308
300
309
let ( stats_event_sender, _stats_repository) = statistics:: setup:: factory ( config. core . tracker_usage_statistics ) ;
301
310
let stats_event_sender = Arc :: new ( stats_event_sender) ;
302
311
303
312
let tracker = Arc :: new ( initialize_tracker (
304
- config,
313
+ & config,
305
314
& in_memory_torrent_repository,
306
315
& db_torrent_repository,
307
316
) ) ;
@@ -312,7 +321,10 @@ mod tests {
312
321
& db_torrent_repository,
313
322
) ) ;
314
323
324
+ let config = Arc :: new ( config. core ) ;
325
+
315
326
(
327
+ config,
316
328
tracker,
317
329
announce_handler,
318
330
stats_event_sender,
@@ -361,7 +373,7 @@ mod tests {
361
373
362
374
#[ tokio:: test]
363
375
async fn it_should_fail_when_the_authentication_key_is_missing ( ) {
364
- let ( tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
376
+ let ( config , tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
365
377
private_tracker ( ) ;
366
378
367
379
let tracker = Arc :: new ( tracker) ;
@@ -370,6 +382,7 @@ mod tests {
370
382
let maybe_key = None ;
371
383
372
384
let response = handle_announce (
385
+ & config,
373
386
& tracker,
374
387
& announce_handler,
375
388
& authentication_service,
@@ -390,7 +403,7 @@ mod tests {
390
403
391
404
#[ tokio:: test]
392
405
async fn it_should_fail_when_the_authentication_key_is_invalid ( ) {
393
- let ( tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
406
+ let ( config , tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
394
407
private_tracker ( ) ;
395
408
396
409
let tracker = Arc :: new ( tracker) ;
@@ -401,6 +414,7 @@ mod tests {
401
414
let maybe_key = Some ( unregistered_key) ;
402
415
403
416
let response = handle_announce (
417
+ & config,
404
418
& tracker,
405
419
& announce_handler,
406
420
& authentication_service,
@@ -427,7 +441,7 @@ mod tests {
427
441
428
442
#[ tokio:: test]
429
443
async fn it_should_fail_when_the_announced_torrent_is_not_whitelisted ( ) {
430
- let ( tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
444
+ let ( config , tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
431
445
whitelisted_tracker ( ) ;
432
446
433
447
let tracker = Arc :: new ( tracker) ;
@@ -436,6 +450,7 @@ mod tests {
436
450
let announce_request = sample_announce_request ( ) ;
437
451
438
452
let response = handle_announce (
453
+ & config,
439
454
& tracker,
440
455
& announce_handler,
441
456
& authentication_service,
@@ -470,7 +485,7 @@ mod tests {
470
485
471
486
#[ tokio:: test]
472
487
async fn it_should_fail_when_the_right_most_x_forwarded_for_header_ip_is_not_available ( ) {
473
- let ( tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
488
+ let ( config , tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
474
489
tracker_on_reverse_proxy ( ) ;
475
490
476
491
let tracker = Arc :: new ( tracker) ;
@@ -482,6 +497,7 @@ mod tests {
482
497
} ;
483
498
484
499
let response = handle_announce (
500
+ & config,
485
501
& tracker,
486
502
& announce_handler,
487
503
& authentication_service,
@@ -513,7 +529,7 @@ mod tests {
513
529
514
530
#[ tokio:: test]
515
531
async fn it_should_fail_when_the_client_ip_from_the_connection_info_is_not_available ( ) {
516
- let ( tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
532
+ let ( config , tracker, announce_handler, stats_event_sender, whitelist_authorization, authentication_service) =
517
533
tracker_not_on_reverse_proxy ( ) ;
518
534
519
535
let tracker = Arc :: new ( tracker) ;
@@ -525,6 +541,7 @@ mod tests {
525
541
} ;
526
542
527
543
let response = handle_announce (
544
+ & config,
528
545
& tracker,
529
546
& announce_handler,
530
547
& authentication_service,
0 commit comments