5
5
//! It delegates the `announce` logic to the [`AnnounceHandler`] and it returns
6
6
//! the [`AnnounceData`].
7
7
//!
8
- //! It also sends an [`http_tracker_core::statistics:: event::Event`]
8
+ //! It also sends an [`http_tracker_core::event::Event`]
9
9
//! because events are specific for the HTTP tracker.
10
10
use std:: net:: { IpAddr , SocketAddr } ;
11
11
use std:: panic:: Location ;
@@ -22,7 +22,8 @@ use bittorrent_tracker_core::whitelist;
22
22
use torrust_tracker_configuration:: Core ;
23
23
use torrust_tracker_primitives:: core:: AnnounceData ;
24
24
25
- use crate :: statistics;
25
+ use crate :: event;
26
+ use crate :: event:: Event ;
26
27
27
28
/// The HTTP tracker `announce` service.
28
29
///
@@ -35,7 +36,7 @@ pub struct AnnounceService {
35
36
announce_handler : Arc < AnnounceHandler > ,
36
37
authentication_service : Arc < AuthenticationService > ,
37
38
whitelist_authorization : Arc < whitelist:: authorization:: WhitelistAuthorization > ,
38
- opt_http_stats_event_sender : Arc < Option < Box < dyn statistics :: event:: sender:: Sender > > > ,
39
+ opt_http_stats_event_sender : Arc < Option < Box < dyn event:: sender:: Sender > > > ,
39
40
}
40
41
41
42
impl AnnounceService {
@@ -45,7 +46,7 @@ impl AnnounceService {
45
46
announce_handler : Arc < AnnounceHandler > ,
46
47
authentication_service : Arc < AuthenticationService > ,
47
48
whitelist_authorization : Arc < whitelist:: authorization:: WhitelistAuthorization > ,
48
- opt_http_stats_event_sender : Arc < Option < Box < dyn statistics :: event:: sender:: Sender > > > ,
49
+ opt_http_stats_event_sender : Arc < Option < Box < dyn event:: sender:: Sender > > > ,
49
50
) -> Self {
50
51
Self {
51
52
core_config,
@@ -140,8 +141,8 @@ impl AnnounceService {
140
141
async fn send_stats_event ( & self , peer_ip : IpAddr , opt_peer_ip_port : Option < u16 > , server_socket_addr : SocketAddr ) {
141
142
if let Some ( http_stats_event_sender) = self . opt_http_stats_event_sender . as_deref ( ) {
142
143
http_stats_event_sender
143
- . send_event ( statistics :: event :: Event :: TcpAnnounce {
144
- connection : statistics :: event:: ConnectionContext :: new ( peer_ip, opt_peer_ip_port, server_socket_addr) ,
144
+ . send_event ( Event :: TcpAnnounce {
145
+ connection : event:: ConnectionContext :: new ( peer_ip, opt_peer_ip_port, server_socket_addr) ,
145
146
} )
146
147
. await ;
147
148
}
@@ -227,7 +228,7 @@ mod tests {
227
228
}
228
229
229
230
struct CoreHttpTrackerServices {
230
- pub http_stats_event_sender : Arc < Option < Box < dyn statistics :: event:: sender:: Sender > > > ,
231
+ pub http_stats_event_sender : Arc < Option < Box < dyn event:: sender:: Sender > > > ,
231
232
}
232
233
233
234
fn initialize_core_tracker_services ( ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
@@ -317,13 +318,14 @@ mod tests {
317
318
use mockall:: mock;
318
319
use tokio:: sync:: broadcast:: error:: SendError ;
319
320
320
- use crate :: statistics ;
321
+ use crate :: event :: Event ;
321
322
use crate :: tests:: sample_info_hash;
323
+ use crate :: { event, statistics} ;
322
324
323
325
mock ! {
324
326
HttpStatsEventSender { }
325
- impl statistics :: event:: sender:: Sender for HttpStatsEventSender {
326
- fn send_event( & self , event: statistics :: event :: Event ) -> BoxFuture <' static , Option <Result <usize , SendError <statistics :: event :: Event > > > > ;
327
+ impl event:: sender:: Sender for HttpStatsEventSender {
328
+ fn send_event( & self , event: Event ) -> BoxFuture <' static , Option <Result <usize , SendError <Event > > > > ;
327
329
}
328
330
}
329
331
@@ -340,13 +342,13 @@ mod tests {
340
342
use torrust_tracker_test_helpers:: configuration;
341
343
342
344
use super :: { sample_peer_using_ipv4, sample_peer_using_ipv6} ;
345
+ use crate :: event;
346
+ use crate :: event:: { ConnectionContext , Event } ;
343
347
use crate :: services:: announce:: tests:: {
344
348
initialize_core_tracker_services, initialize_core_tracker_services_with_config, sample_announce_request_for_peer,
345
349
sample_peer, MockHttpStatsEventSender ,
346
350
} ;
347
351
use crate :: services:: announce:: AnnounceService ;
348
- use crate :: statistics;
349
- use crate :: statistics:: event:: ConnectionContext ;
350
352
351
353
#[ tokio:: test]
352
354
async fn it_should_return_the_announce_data ( ) {
@@ -391,12 +393,12 @@ mod tests {
391
393
let mut http_stats_event_sender_mock = MockHttpStatsEventSender :: new ( ) ;
392
394
http_stats_event_sender_mock
393
395
. expect_send_event ( )
394
- . with ( eq ( statistics :: event :: Event :: TcpAnnounce {
396
+ . with ( eq ( Event :: TcpAnnounce {
395
397
connection : ConnectionContext :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 126 , 0 , 0 , 1 ) ) , Some ( 8080 ) , server_socket_addr) ,
396
398
} ) )
397
399
. times ( 1 )
398
400
. returning ( |_| Box :: pin ( future:: ready ( Some ( Ok ( 1 ) ) ) ) ) ;
399
- let http_stats_event_sender: Arc < Option < Box < dyn statistics :: event:: sender:: Sender > > > =
401
+ let http_stats_event_sender: Arc < Option < Box < dyn event:: sender:: Sender > > > =
400
402
Arc :: new ( Some ( Box :: new ( http_stats_event_sender_mock) ) ) ;
401
403
402
404
let ( core_tracker_services, mut core_http_tracker_services) = initialize_core_tracker_services ( ) ;
@@ -447,12 +449,12 @@ mod tests {
447
449
let mut http_stats_event_sender_mock = MockHttpStatsEventSender :: new ( ) ;
448
450
http_stats_event_sender_mock
449
451
. expect_send_event ( )
450
- . with ( eq ( statistics :: event :: Event :: TcpAnnounce {
452
+ . with ( eq ( Event :: TcpAnnounce {
451
453
connection : ConnectionContext :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , Some ( 8080 ) , server_socket_addr) ,
452
454
} ) )
453
455
. times ( 1 )
454
456
. returning ( |_| Box :: pin ( future:: ready ( Some ( Ok ( 1 ) ) ) ) ) ;
455
- let http_stats_event_sender: Arc < Option < Box < dyn statistics :: event:: sender:: Sender > > > =
457
+ let http_stats_event_sender: Arc < Option < Box < dyn event:: sender:: Sender > > > =
456
458
Arc :: new ( Some ( Box :: new ( http_stats_event_sender_mock) ) ) ;
457
459
458
460
let ( core_tracker_services, mut core_http_tracker_services) =
@@ -486,7 +488,7 @@ mod tests {
486
488
let mut http_stats_event_sender_mock = MockHttpStatsEventSender :: new ( ) ;
487
489
http_stats_event_sender_mock
488
490
. expect_send_event ( )
489
- . with ( eq ( statistics :: event :: Event :: TcpAnnounce {
491
+ . with ( eq ( Event :: TcpAnnounce {
490
492
connection : ConnectionContext :: new (
491
493
IpAddr :: V6 ( Ipv6Addr :: new ( 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 ) ) ,
492
494
Some ( 8080 ) ,
@@ -495,7 +497,7 @@ mod tests {
495
497
} ) )
496
498
. times ( 1 )
497
499
. returning ( |_| Box :: pin ( future:: ready ( Some ( Ok ( 1 ) ) ) ) ) ;
498
- let http_stats_event_sender: Arc < Option < Box < dyn statistics :: event:: sender:: Sender > > > =
500
+ let http_stats_event_sender: Arc < Option < Box < dyn event:: sender:: Sender > > > =
499
501
Arc :: new ( Some ( Box :: new ( http_stats_event_sender_mock) ) ) ;
500
502
501
503
let ( core_tracker_services, mut core_http_tracker_services) = initialize_core_tracker_services ( ) ;
0 commit comments