@@ -2,12 +2,11 @@ use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
22use std:: sync:: Arc ;
33
44use aquatic_udp_protocol:: {
5- AnnounceInterval , AnnounceRequest , AnnounceResponse , ConnectRequest , ConnectResponse , ConnectionId , ErrorResponse ,
6- NumberOfDownloads , NumberOfPeers , Port , Request , Response , ResponsePeer , ScrapeRequest , ScrapeResponse ,
7- TorrentScrapeStatistics , TransactionId ,
5+ AnnounceInterval , AnnounceRequest , AnnounceResponse , ConnectRequest , ConnectResponse , ErrorResponse , NumberOfDownloads ,
6+ NumberOfPeers , Port , Request , Response , ResponsePeer , ScrapeRequest , ScrapeResponse , TorrentScrapeStatistics , TransactionId ,
87} ;
98
10- use super :: connection_cookie:: { check_connection_cookie, make_connection_cookie} ;
9+ use super :: connection_cookie:: { check_connection_cookie, from_connection_id , into_connection_id , make_connection_cookie} ;
1110use crate :: peer:: TorrentPeer ;
1211use crate :: tracker:: statistics:: TrackerStatisticsEvent ;
1312use crate :: tracker:: torrent:: TorrentError ;
@@ -71,7 +70,7 @@ pub async fn handle_connect(
7170 tracker : Arc < TorrentTracker > ,
7271) -> Result < Response , ServerError > {
7372 let connection_cookie = make_connection_cookie ( & remote_addr) ;
74- let connection_id = ConnectionId ( i64 :: from_le_bytes ( connection_cookie) ) ;
73+ let connection_id = into_connection_id ( & connection_cookie) ;
7574
7675 let response = Response :: from ( ConnectResponse {
7776 transaction_id : request. transaction_id ,
@@ -96,7 +95,7 @@ pub async fn handle_announce(
9695 announce_request : & AnnounceRequest ,
9796 tracker : Arc < TorrentTracker > ,
9897) -> Result < Response , ServerError > {
99- match check_connection_cookie ( & remote_addr, & announce_request. connection_id . 0 . to_be_bytes ( ) ) {
98+ match check_connection_cookie ( & remote_addr, & from_connection_id ( & announce_request. connection_id ) ) {
10099 Ok ( _) => { }
101100 Err ( e) => {
102101 return Err ( e) ;
@@ -410,9 +409,9 @@ mod tests {
410409 use aquatic_udp_protocol:: { ConnectRequest , ConnectResponse , Response , TransactionId } ;
411410
412411 use super :: { default_tracker_config, sample_ipv4_socket_address, sample_ipv6_remote_addr, TrackerStatsServiceMock } ;
413- use crate :: protocol:: utils:: get_connection_id;
414412 use crate :: statistics:: TrackerStatisticsEvent ;
415413 use crate :: tracker:: tracker:: TorrentTracker ;
414+ use crate :: udp:: connection_cookie:: { into_connection_id, make_connection_cookie} ;
416415 use crate :: udp:: handle_connect;
417416 use crate :: udp:: handlers:: tests:: { initialized_public_tracker, sample_ipv4_remote_addr} ;
418417
@@ -435,7 +434,7 @@ mod tests {
435434 assert_eq ! (
436435 response,
437436 Response :: Connect ( ConnectResponse {
438- connection_id: get_connection_id ( & sample_ipv4_remote_addr( ) ) ,
437+ connection_id: into_connection_id ( & make_connection_cookie ( & sample_ipv4_remote_addr( ) ) ) ,
439438 transaction_id: request. transaction_id
440439 } )
441440 ) ;
@@ -454,7 +453,7 @@ mod tests {
454453 assert_eq ! (
455454 response,
456455 Response :: Connect ( ConnectResponse {
457- connection_id: get_connection_id ( & sample_ipv4_remote_addr( ) ) ,
456+ connection_id: into_connection_id ( & make_connection_cookie ( & sample_ipv4_remote_addr( ) ) ) ,
458457 transaction_id: request. transaction_id
459458 } )
460459 ) ;
@@ -494,7 +493,7 @@ mod tests {
494493 AnnounceEvent , AnnounceRequest , NumberOfBytes , NumberOfPeers , PeerId as AquaticPeerId , PeerKey , Port , TransactionId ,
495494 } ;
496495
497- use crate :: protocol :: utils :: get_connection_id ;
496+ use crate :: udp :: connection_cookie :: { into_connection_id , make_connection_cookie } ;
498497 use crate :: udp:: handlers:: tests:: sample_ipv4_remote_addr;
499498
500499 struct AnnounceRequestBuilder {
@@ -508,7 +507,7 @@ mod tests {
508507 let info_hash_aquatic = aquatic_udp_protocol:: InfoHash ( [ 0u8 ; 20 ] ) ;
509508
510509 let default_request = AnnounceRequest {
511- connection_id : get_connection_id ( & sample_ipv4_remote_addr ( ) ) ,
510+ connection_id : into_connection_id ( & make_connection_cookie ( & sample_ipv4_remote_addr ( ) ) ) ,
512511 transaction_id : TransactionId ( 0i32 ) ,
513512 info_hash : info_hash_aquatic,
514513 peer_id : AquaticPeerId ( [ 255u8 ; 20 ] ) ,
@@ -985,8 +984,8 @@ mod tests {
985984 } ;
986985
987986 use super :: TorrentPeerBuilder ;
988- use crate :: protocol:: utils:: get_connection_id;
989987 use crate :: tracker:: tracker:: TorrentTracker ;
988+ use crate :: udp:: connection_cookie:: { into_connection_id, make_connection_cookie} ;
990989 use crate :: udp:: handle_scrape;
991990 use crate :: udp:: handlers:: tests:: { initialized_public_tracker, sample_ipv4_remote_addr} ;
992991 use crate :: PeerId ;
@@ -1007,7 +1006,7 @@ mod tests {
10071006 let info_hashes = vec ! [ info_hash] ;
10081007
10091008 let request = ScrapeRequest {
1010- connection_id : get_connection_id ( & remote_addr) ,
1009+ connection_id : into_connection_id ( & make_connection_cookie ( & remote_addr) ) ,
10111010 transaction_id : TransactionId ( 0i32 ) ,
10121011 info_hashes,
10131012 } ;
@@ -1045,7 +1044,7 @@ mod tests {
10451044 let info_hashes = vec ! [ * info_hash] ;
10461045
10471046 ScrapeRequest {
1048- connection_id : get_connection_id ( remote_addr) ,
1047+ connection_id : into_connection_id ( & make_connection_cookie ( & remote_addr) ) ,
10491048 transaction_id : TransactionId ( 0i32 ) ,
10501049 info_hashes,
10511050 }
@@ -1190,7 +1189,7 @@ mod tests {
11901189 let info_hashes = vec ! [ info_hash] ;
11911190
11921191 ScrapeRequest {
1193- connection_id : get_connection_id ( remote_addr) ,
1192+ connection_id : into_connection_id ( & make_connection_cookie ( & remote_addr) ) ,
11941193 transaction_id : TransactionId ( 0i32 ) ,
11951194 info_hashes,
11961195 }
0 commit comments