55//! It delegates the `announce` logic to the [`AnnounceHandler`] and it returns
66//! the [`AnnounceData`].
77//!
8- //! It also sends an [`http_tracker_core::statistics:: event::Event`]
8+ //! It also sends an [`http_tracker_core::event::Event`]
99//! because events are specific for the HTTP tracker.
1010use std:: net:: { IpAddr , SocketAddr } ;
1111use std:: panic:: Location ;
@@ -22,7 +22,8 @@ use bittorrent_tracker_core::whitelist;
2222use torrust_tracker_configuration:: Core ;
2323use torrust_tracker_primitives:: core:: AnnounceData ;
2424
25- use crate :: statistics;
25+ use crate :: event;
26+ use crate :: event:: Event ;
2627
2728/// The HTTP tracker `announce` service.
2829///
@@ -35,7 +36,7 @@ pub struct AnnounceService {
3536 announce_handler : Arc < AnnounceHandler > ,
3637 authentication_service : Arc < AuthenticationService > ,
3738 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 > > > ,
3940}
4041
4142impl AnnounceService {
@@ -45,7 +46,7 @@ impl AnnounceService {
4546 announce_handler : Arc < AnnounceHandler > ,
4647 authentication_service : Arc < AuthenticationService > ,
4748 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 > > > ,
4950 ) -> Self {
5051 Self {
5152 core_config,
@@ -86,7 +87,7 @@ impl AnnounceService {
8687 . announce ( & announce_request. info_hash , & mut peer, & remote_client_ip, & peers_wanted)
8788 . await ?;
8889
89- self . send_stats_event ( remote_client_ip, opt_remote_client_port, * server_socket_addr)
90+ self . send_event ( remote_client_ip, opt_remote_client_port, * server_socket_addr)
9091 . await ;
9192
9293 Ok ( announce_data)
@@ -137,11 +138,11 @@ impl AnnounceService {
137138 }
138139 }
139140
140- async fn send_stats_event ( & self , peer_ip : IpAddr , opt_peer_ip_port : Option < u16 > , server_socket_addr : SocketAddr ) {
141+ async fn send_event ( & self , peer_ip : IpAddr , opt_peer_ip_port : Option < u16 > , server_socket_addr : SocketAddr ) {
141142 if let Some ( http_stats_event_sender) = self . opt_http_stats_event_sender . as_deref ( ) {
142143 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) ,
145146 } )
146147 . await ;
147148 }
@@ -227,7 +228,7 @@ mod tests {
227228 }
228229
229230 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 > > > ,
231232 }
232233
233234 fn initialize_core_tracker_services ( ) -> ( CoreTrackerServices , CoreHttpTrackerServices ) {
@@ -317,13 +318,14 @@ mod tests {
317318 use mockall:: mock;
318319 use tokio:: sync:: broadcast:: error:: SendError ;
319320
320- use crate :: statistics ;
321+ use crate :: event :: Event ;
321322 use crate :: tests:: sample_info_hash;
323+ use crate :: { event, statistics} ;
322324
323325 mock ! {
324326 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 > > > > ;
327329 }
328330 }
329331
@@ -340,13 +342,13 @@ mod tests {
340342 use torrust_tracker_test_helpers:: configuration;
341343
342344 use super :: { sample_peer_using_ipv4, sample_peer_using_ipv6} ;
345+ use crate :: event;
346+ use crate :: event:: { ConnectionContext , Event } ;
343347 use crate :: services:: announce:: tests:: {
344348 initialize_core_tracker_services, initialize_core_tracker_services_with_config, sample_announce_request_for_peer,
345349 sample_peer, MockHttpStatsEventSender ,
346350 } ;
347351 use crate :: services:: announce:: AnnounceService ;
348- use crate :: statistics;
349- use crate :: statistics:: event:: ConnectionContext ;
350352
351353 #[ tokio:: test]
352354 async fn it_should_return_the_announce_data ( ) {
@@ -391,12 +393,12 @@ mod tests {
391393 let mut http_stats_event_sender_mock = MockHttpStatsEventSender :: new ( ) ;
392394 http_stats_event_sender_mock
393395 . expect_send_event ( )
394- . with ( eq ( statistics :: event :: Event :: TcpAnnounce {
396+ . with ( eq ( Event :: TcpAnnounce {
395397 connection : ConnectionContext :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 126 , 0 , 0 , 1 ) ) , Some ( 8080 ) , server_socket_addr) ,
396398 } ) )
397399 . times ( 1 )
398400 . 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 > > > =
400402 Arc :: new ( Some ( Box :: new ( http_stats_event_sender_mock) ) ) ;
401403
402404 let ( core_tracker_services, mut core_http_tracker_services) = initialize_core_tracker_services ( ) ;
@@ -447,12 +449,12 @@ mod tests {
447449 let mut http_stats_event_sender_mock = MockHttpStatsEventSender :: new ( ) ;
448450 http_stats_event_sender_mock
449451 . expect_send_event ( )
450- . with ( eq ( statistics :: event :: Event :: TcpAnnounce {
452+ . with ( eq ( Event :: TcpAnnounce {
451453 connection : ConnectionContext :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , Some ( 8080 ) , server_socket_addr) ,
452454 } ) )
453455 . times ( 1 )
454456 . 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 > > > =
456458 Arc :: new ( Some ( Box :: new ( http_stats_event_sender_mock) ) ) ;
457459
458460 let ( core_tracker_services, mut core_http_tracker_services) =
@@ -486,7 +488,7 @@ mod tests {
486488 let mut http_stats_event_sender_mock = MockHttpStatsEventSender :: new ( ) ;
487489 http_stats_event_sender_mock
488490 . expect_send_event ( )
489- . with ( eq ( statistics :: event :: Event :: TcpAnnounce {
491+ . with ( eq ( Event :: TcpAnnounce {
490492 connection : ConnectionContext :: new (
491493 IpAddr :: V6 ( Ipv6Addr :: new ( 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 , 0x6969 ) ) ,
492494 Some ( 8080 ) ,
@@ -495,7 +497,7 @@ mod tests {
495497 } ) )
496498 . times ( 1 )
497499 . 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 > > > =
499501 Arc :: new ( Some ( Box :: new ( http_stats_event_sender_mock) ) ) ;
500502
501503 let ( core_tracker_services, mut core_http_tracker_services) = initialize_core_tracker_services ( ) ;
0 commit comments