@@ -28,6 +28,7 @@ use torrust_tracker_primitives::core::AnnounceData;
28
28
use torrust_tracker_primitives:: peer;
29
29
30
30
use super :: common:: auth:: map_auth_error_to_error_response;
31
+ use crate :: packages:: http_tracker_core;
31
32
use crate :: servers:: http:: v1:: extractors:: announce_request:: ExtractRequest ;
32
33
use crate :: servers:: http:: v1:: extractors:: authentication_key:: Extract as ExtractKey ;
33
34
use crate :: servers:: http:: v1:: extractors:: client_ip_sources:: Extract as ExtractClientIpSources ;
@@ -46,6 +47,7 @@ pub async fn handle_without_key(
46
47
Arc < AuthenticationService > ,
47
48
Arc < whitelist:: authorization:: WhitelistAuthorization > ,
48
49
Arc < Option < Box < dyn Sender > > > ,
50
+ Arc < Option < Box < dyn http_tracker_core:: statistics:: event:: sender:: Sender > > > ,
49
51
) > ,
50
52
ExtractRequest ( announce_request) : ExtractRequest ,
51
53
ExtractClientIpSources ( client_ip_sources) : ExtractClientIpSources ,
@@ -58,6 +60,7 @@ pub async fn handle_without_key(
58
60
& state. 2 ,
59
61
& state. 3 ,
60
62
& state. 4 ,
63
+ & state. 5 ,
61
64
& announce_request,
62
65
& client_ip_sources,
63
66
None ,
@@ -76,6 +79,7 @@ pub async fn handle_with_key(
76
79
Arc < AuthenticationService > ,
77
80
Arc < whitelist:: authorization:: WhitelistAuthorization > ,
78
81
Arc < Option < Box < dyn Sender > > > ,
82
+ Arc < Option < Box < dyn http_tracker_core:: statistics:: event:: sender:: Sender > > > ,
79
83
) > ,
80
84
ExtractRequest ( announce_request) : ExtractRequest ,
81
85
ExtractClientIpSources ( client_ip_sources) : ExtractClientIpSources ,
@@ -89,6 +93,7 @@ pub async fn handle_with_key(
89
93
& state. 2 ,
90
94
& state. 3 ,
91
95
& state. 4 ,
96
+ & state. 5 ,
92
97
& announce_request,
93
98
& client_ip_sources,
94
99
Some ( key) ,
@@ -107,6 +112,7 @@ async fn handle(
107
112
authentication_service : & Arc < AuthenticationService > ,
108
113
whitelist_authorization : & Arc < whitelist:: authorization:: WhitelistAuthorization > ,
109
114
opt_stats_event_sender : & Arc < Option < Box < dyn Sender > > > ,
115
+ opt_http_stats_event_sender : & Arc < Option < Box < dyn http_tracker_core:: statistics:: event:: sender:: Sender > > > ,
110
116
announce_request : & Announce ,
111
117
client_ip_sources : & ClientIpSources ,
112
118
maybe_key : Option < Key > ,
@@ -117,6 +123,7 @@ async fn handle(
117
123
authentication_service,
118
124
whitelist_authorization,
119
125
opt_stats_event_sender,
126
+ opt_http_stats_event_sender,
120
127
announce_request,
121
128
client_ip_sources,
122
129
maybe_key,
@@ -142,6 +149,7 @@ async fn handle_announce(
142
149
authentication_service : & Arc < AuthenticationService > ,
143
150
whitelist_authorization : & Arc < whitelist:: authorization:: WhitelistAuthorization > ,
144
151
opt_stats_event_sender : & Arc < Option < Box < dyn Sender > > > ,
152
+ opt_http_stats_event_sender : & Arc < Option < Box < dyn http_tracker_core:: statistics:: event:: sender:: Sender > > > ,
145
153
announce_request : & Announce ,
146
154
client_ip_sources : & ClientIpSources ,
147
155
maybe_key : Option < Key > ,
@@ -181,6 +189,7 @@ async fn handle_announce(
181
189
let announce_data = services:: announce:: invoke (
182
190
announce_handler. clone ( ) ,
183
191
opt_stats_event_sender. clone ( ) ,
192
+ opt_http_stats_event_sender. clone ( ) ,
184
193
announce_request. info_hash ,
185
194
& mut peer,
186
195
& peers_wanted,
@@ -265,7 +274,7 @@ mod tests {
265
274
use torrust_tracker_configuration:: { Configuration , Core } ;
266
275
use torrust_tracker_test_helpers:: configuration;
267
276
268
- use crate :: packages;
277
+ use crate :: packages:: { self , http_tracker_core } ;
269
278
270
279
struct CoreTrackerServices {
271
280
pub core_config : Arc < Core > ,
@@ -275,23 +284,27 @@ mod tests {
275
284
pub authentication_service : Arc < AuthenticationService > ,
276
285
}
277
286
278
- fn initialize_private_tracker ( ) -> CoreTrackerServices {
287
+ struct CoreHttpTrackerServices {
288
+ pub http_stats_event_sender : Arc < Option < Box < dyn http_tracker_core:: statistics:: event:: sender:: Sender > > > ,
289
+ }
290
+
291
+ fn initialize_private_tracker ( ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
279
292
initialize_core_tracker_services ( & configuration:: ephemeral_private ( ) )
280
293
}
281
294
282
- fn initialize_listed_tracker ( ) -> CoreTrackerServices {
295
+ fn initialize_listed_tracker ( ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
283
296
initialize_core_tracker_services ( & configuration:: ephemeral_listed ( ) )
284
297
}
285
298
286
- fn initialize_tracker_on_reverse_proxy ( ) -> CoreTrackerServices {
299
+ fn initialize_tracker_on_reverse_proxy ( ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
287
300
initialize_core_tracker_services ( & configuration:: ephemeral_with_reverse_proxy ( ) )
288
301
}
289
302
290
- fn initialize_tracker_not_on_reverse_proxy ( ) -> CoreTrackerServices {
303
+ fn initialize_tracker_not_on_reverse_proxy ( ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
291
304
initialize_core_tracker_services ( & configuration:: ephemeral_without_reverse_proxy ( ) )
292
305
}
293
306
294
- fn initialize_core_tracker_services ( config : & Configuration ) -> CoreTrackerServices {
307
+ fn initialize_core_tracker_services ( config : & Configuration ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
295
308
let core_config = Arc :: new ( config. core . clone ( ) ) ;
296
309
let database = initialize_database ( config) ;
297
310
let in_memory_whitelist = Arc :: new ( InMemoryWhitelist :: default ( ) ) ;
@@ -300,21 +313,31 @@ mod tests {
300
313
let authentication_service = Arc :: new ( AuthenticationService :: new ( & config. core , & in_memory_key_repository) ) ;
301
314
let in_memory_torrent_repository = Arc :: new ( InMemoryTorrentRepository :: default ( ) ) ;
302
315
let db_torrent_repository = Arc :: new ( DatabasePersistentTorrentRepository :: new ( & database) ) ;
303
- let ( stats_event_sender, _stats_repository) = statistics:: setup:: factory ( config. core . tracker_usage_statistics ) ;
304
- let stats_event_sender = Arc :: new ( stats_event_sender) ;
305
316
let announce_handler = Arc :: new ( AnnounceHandler :: new (
306
317
& config. core ,
307
318
& in_memory_torrent_repository,
308
319
& db_torrent_repository,
309
320
) ) ;
310
321
311
- CoreTrackerServices {
312
- core_config,
313
- announce_handler,
314
- stats_event_sender,
315
- whitelist_authorization,
316
- authentication_service,
317
- }
322
+ let ( stats_event_sender, _stats_repository) = statistics:: setup:: factory ( config. core . tracker_usage_statistics ) ;
323
+ let stats_event_sender = Arc :: new ( stats_event_sender) ;
324
+
325
+ // HTTP stats
326
+ let ( http_stats_event_sender, http_stats_repository) =
327
+ http_tracker_core:: statistics:: setup:: factory ( config. core . tracker_usage_statistics ) ;
328
+ let http_stats_event_sender = Arc :: new ( http_stats_event_sender) ;
329
+ let _http_stats_repository = Arc :: new ( http_stats_repository) ;
330
+
331
+ (
332
+ CoreTrackerServices {
333
+ core_config,
334
+ announce_handler,
335
+ stats_event_sender,
336
+ whitelist_authorization,
337
+ authentication_service,
338
+ } ,
339
+ CoreHttpTrackerServices { http_stats_event_sender } ,
340
+ )
318
341
}
319
342
320
343
fn sample_announce_request ( ) -> Announce {
@@ -357,7 +380,7 @@ mod tests {
357
380
358
381
#[ tokio:: test]
359
382
async fn it_should_fail_when_the_authentication_key_is_missing ( ) {
360
- let core_tracker_services = initialize_private_tracker ( ) ;
383
+ let ( core_tracker_services, http_core_tracker_services ) = initialize_private_tracker ( ) ;
361
384
362
385
let maybe_key = None ;
363
386
@@ -367,6 +390,7 @@ mod tests {
367
390
& core_tracker_services. authentication_service ,
368
391
& core_tracker_services. whitelist_authorization ,
369
392
& core_tracker_services. stats_event_sender ,
393
+ & http_core_tracker_services. http_stats_event_sender ,
370
394
& sample_announce_request ( ) ,
371
395
& sample_client_ip_sources ( ) ,
372
396
maybe_key,
@@ -382,7 +406,7 @@ mod tests {
382
406
383
407
#[ tokio:: test]
384
408
async fn it_should_fail_when_the_authentication_key_is_invalid ( ) {
385
- let core_tracker_services = initialize_private_tracker ( ) ;
409
+ let ( core_tracker_services, http_core_tracker_services ) = initialize_private_tracker ( ) ;
386
410
387
411
let unregistered_key = authentication:: Key :: from_str ( "YZSl4lMZupRuOpSRC3krIKR5BPB14nrJ" ) . unwrap ( ) ;
388
412
@@ -394,6 +418,7 @@ mod tests {
394
418
& core_tracker_services. authentication_service ,
395
419
& core_tracker_services. whitelist_authorization ,
396
420
& core_tracker_services. stats_event_sender ,
421
+ & http_core_tracker_services. http_stats_event_sender ,
397
422
& sample_announce_request ( ) ,
398
423
& sample_client_ip_sources ( ) ,
399
424
maybe_key,
@@ -413,7 +438,7 @@ mod tests {
413
438
414
439
#[ tokio:: test]
415
440
async fn it_should_fail_when_the_announced_torrent_is_not_whitelisted ( ) {
416
- let core_tracker_services = initialize_listed_tracker ( ) ;
441
+ let ( core_tracker_services, http_core_tracker_services ) = initialize_listed_tracker ( ) ;
417
442
418
443
let announce_request = sample_announce_request ( ) ;
419
444
@@ -423,6 +448,7 @@ mod tests {
423
448
& core_tracker_services. authentication_service ,
424
449
& core_tracker_services. whitelist_authorization ,
425
450
& core_tracker_services. stats_event_sender ,
451
+ & http_core_tracker_services. http_stats_event_sender ,
426
452
& announce_request,
427
453
& sample_client_ip_sources ( ) ,
428
454
None ,
@@ -450,7 +476,7 @@ mod tests {
450
476
451
477
#[ tokio:: test]
452
478
async fn it_should_fail_when_the_right_most_x_forwarded_for_header_ip_is_not_available ( ) {
453
- let core_tracker_services = initialize_tracker_on_reverse_proxy ( ) ;
479
+ let ( core_tracker_services, http_core_tracker_services ) = initialize_tracker_on_reverse_proxy ( ) ;
454
480
455
481
let client_ip_sources = ClientIpSources {
456
482
right_most_x_forwarded_for : None ,
@@ -463,6 +489,7 @@ mod tests {
463
489
& core_tracker_services. authentication_service ,
464
490
& core_tracker_services. whitelist_authorization ,
465
491
& core_tracker_services. stats_event_sender ,
492
+ & http_core_tracker_services. http_stats_event_sender ,
466
493
& sample_announce_request ( ) ,
467
494
& client_ip_sources,
468
495
None ,
@@ -487,7 +514,7 @@ mod tests {
487
514
488
515
#[ tokio:: test]
489
516
async fn it_should_fail_when_the_client_ip_from_the_connection_info_is_not_available ( ) {
490
- let core_tracker_services = initialize_tracker_not_on_reverse_proxy ( ) ;
517
+ let ( core_tracker_services, http_core_tracker_services ) = initialize_tracker_not_on_reverse_proxy ( ) ;
491
518
492
519
let client_ip_sources = ClientIpSources {
493
520
right_most_x_forwarded_for : None ,
@@ -500,6 +527,7 @@ mod tests {
500
527
& core_tracker_services. authentication_service ,
501
528
& core_tracker_services. whitelist_authorization ,
502
529
& core_tracker_services. stats_event_sender ,
530
+ & http_core_tracker_services. http_stats_event_sender ,
503
531
& sample_announce_request ( ) ,
504
532
& client_ip_sources,
505
533
None ,
0 commit comments