@@ -490,7 +490,8 @@ mod tests {
490490        use  std:: net:: Ipv4Addr ; 
491491
492492        use  aquatic_udp_protocol:: { 
493-             AnnounceEvent ,  AnnounceRequest ,  NumberOfBytes ,  NumberOfPeers ,  PeerId  as  AquaticPeerId ,  PeerKey ,  Port ,  TransactionId , 
493+             AnnounceEvent ,  AnnounceRequest ,  ConnectionId ,  NumberOfBytes ,  NumberOfPeers ,  PeerId  as  AquaticPeerId ,  PeerKey ,  Port , 
494+             TransactionId , 
494495        } ; 
495496
496497        use  crate :: udp:: connection_cookie:: { into_connection_id,  make_connection_cookie} ; 
@@ -525,6 +526,11 @@ mod tests {
525526                } 
526527            } 
527528
529+             pub  fn  with_connection_id ( mut  self ,  connection_id :  ConnectionId )  -> Self  { 
530+                 self . request . connection_id  = connection_id; 
531+                 self 
532+             } 
533+ 
528534            pub  fn  with_info_hash ( mut  self ,  info_hash :  aquatic_udp_protocol:: InfoHash )  -> Self  { 
529535                self . request . info_hash  = info_hash; 
530536                self 
@@ -562,6 +568,7 @@ mod tests {
562568
563569            use  crate :: statistics:: TrackerStatisticsEvent ; 
564570            use  crate :: tracker:: tracker:: TorrentTracker ; 
571+             use  crate :: udp:: connection_cookie:: { into_connection_id,  make_connection_cookie} ; 
565572            use  crate :: udp:: handle_announce; 
566573            use  crate :: udp:: handlers:: tests:: announce_request:: AnnounceRequestBuilder ; 
567574            use  crate :: udp:: handlers:: tests:: { 
@@ -579,14 +586,16 @@ mod tests {
579586                let  info_hash = AquaticInfoHash ( [ 0u8 ;  20 ] ) ; 
580587                let  peer_id = AquaticPeerId ( [ 255u8 ;  20 ] ) ; 
581588
589+                 let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( client_ip) ,  client_port) ; 
590+ 
582591                let  request = AnnounceRequestBuilder :: default ( ) 
592+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
583593                    . with_info_hash ( info_hash) 
584594                    . with_peer_id ( peer_id) 
585595                    . with_ip_address ( client_ip) 
586596                    . with_port ( client_port) 
587597                    . into ( ) ; 
588598
589-                 let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( client_ip) ,  client_port) ; 
590599                handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
591600
592601                let  peers = tracker. get_all_torrent_peers ( & info_hash. 0 . into ( ) ) . await ; 
@@ -601,9 +610,12 @@ mod tests {
601610
602611            #[ tokio:: test]  
603612            async  fn  the_announced_peer_should_not_be_included_in_the_response ( )  { 
604-                 let  request = AnnounceRequestBuilder :: default ( ) . into ( ) ; 
605613                let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 126 ,  0 ,  0 ,  1 ) ) ,  8080 ) ; 
606614
615+                 let  request = AnnounceRequestBuilder :: default ( ) 
616+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
617+                     . into ( ) ; 
618+ 
607619                let  response = handle_announce ( remote_addr,  & request,  initialized_public_tracker ( ) ) 
608620                    . await 
609621                    . unwrap ( ) ; 
@@ -637,14 +649,16 @@ mod tests {
637649                let  remote_client_port = 8081 ; 
638650                let  peer_address = Ipv4Addr :: new ( 126 ,  0 ,  0 ,  2 ) ; 
639651
652+                 let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( remote_client_ip) ,  remote_client_port) ; 
653+ 
640654                let  request = AnnounceRequestBuilder :: default ( ) 
655+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
641656                    . with_info_hash ( info_hash) 
642657                    . with_peer_id ( peer_id) 
643658                    . with_ip_address ( peer_address) 
644659                    . with_port ( client_port) 
645660                    . into ( ) ; 
646661
647-                 let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( remote_client_ip) ,  remote_client_port) ; 
648662                handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
649663
650664                let  peers = tracker. get_all_torrent_peers ( & info_hash. 0 . into ( ) ) . await ; 
@@ -671,8 +685,10 @@ mod tests {
671685            } 
672686
673687            async  fn  announce_a_new_peer_using_ipv4 ( tracker :  Arc < TorrentTracker > )  -> Response  { 
674-                 let  request = AnnounceRequestBuilder :: default ( ) . into ( ) ; 
675688                let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 126 ,  0 ,  0 ,  1 ) ) ,  8080 ) ; 
689+                 let  request = AnnounceRequestBuilder :: default ( ) 
690+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
691+                     . into ( ) ; 
676692                let  response = handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
677693                response
678694            } 
@@ -715,6 +731,7 @@ mod tests {
715731
716732                use  aquatic_udp_protocol:: { InfoHash  as  AquaticInfoHash ,  PeerId  as  AquaticPeerId } ; 
717733
734+                 use  crate :: udp:: connection_cookie:: { into_connection_id,  make_connection_cookie} ; 
718735                use  crate :: udp:: handle_announce; 
719736                use  crate :: udp:: handlers:: tests:: announce_request:: AnnounceRequestBuilder ; 
720737                use  crate :: udp:: handlers:: tests:: { initialized_public_tracker,  TorrentPeerBuilder } ; 
@@ -729,14 +746,16 @@ mod tests {
729746                    let  info_hash = AquaticInfoHash ( [ 0u8 ;  20 ] ) ; 
730747                    let  peer_id = AquaticPeerId ( [ 255u8 ;  20 ] ) ; 
731748
749+                     let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( client_ip) ,  client_port) ; 
750+ 
732751                    let  request = AnnounceRequestBuilder :: default ( ) 
752+                         . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
733753                        . with_info_hash ( info_hash) 
734754                        . with_peer_id ( peer_id) 
735755                        . with_ip_address ( client_ip) 
736756                        . with_port ( client_port) 
737757                        . into ( ) ; 
738758
739-                     let  remote_addr = SocketAddr :: new ( IpAddr :: V4 ( client_ip) ,  client_port) ; 
740759                    handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
741760
742761                    let  peers = tracker. get_all_torrent_peers ( & info_hash. 0 . into ( ) ) . await ; 
@@ -766,6 +785,7 @@ mod tests {
766785
767786            use  crate :: statistics:: TrackerStatisticsEvent ; 
768787            use  crate :: tracker:: tracker:: TorrentTracker ; 
788+             use  crate :: udp:: connection_cookie:: { into_connection_id,  make_connection_cookie} ; 
769789            use  crate :: udp:: handle_announce; 
770790            use  crate :: udp:: handlers:: tests:: announce_request:: AnnounceRequestBuilder ; 
771791            use  crate :: udp:: handlers:: tests:: { 
@@ -784,14 +804,16 @@ mod tests {
784804                let  info_hash = AquaticInfoHash ( [ 0u8 ;  20 ] ) ; 
785805                let  peer_id = AquaticPeerId ( [ 255u8 ;  20 ] ) ; 
786806
807+                 let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( client_ip_v6) ,  client_port) ; 
808+ 
787809                let  request = AnnounceRequestBuilder :: default ( ) 
810+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
788811                    . with_info_hash ( info_hash) 
789812                    . with_peer_id ( peer_id) 
790813                    . with_ip_address ( client_ip_v4) 
791814                    . with_port ( client_port) 
792815                    . into ( ) ; 
793816
794-                 let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( client_ip_v6) ,  client_port) ; 
795817                handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
796818
797819                let  peers = tracker. get_all_torrent_peers ( & info_hash. 0 . into ( ) ) . await ; 
@@ -806,11 +828,15 @@ mod tests {
806828
807829            #[ tokio:: test]  
808830            async  fn  the_announced_peer_should_not_be_included_in_the_response ( )  { 
809-                 let  request = AnnounceRequestBuilder :: default ( ) . into ( ) ; 
810831                let  client_ip_v4 = Ipv4Addr :: new ( 126 ,  0 ,  0 ,  1 ) ; 
811832                let  client_ip_v6 = client_ip_v4. to_ipv6_compatible ( ) ; 
833+ 
812834                let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( client_ip_v6) ,  8080 ) ; 
813835
836+                 let  request = AnnounceRequestBuilder :: default ( ) 
837+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
838+                     . into ( ) ; 
839+ 
814840                let  response = handle_announce ( remote_addr,  & request,  initialized_public_tracker ( ) ) 
815841                    . await 
816842                    . unwrap ( ) ; 
@@ -844,14 +870,16 @@ mod tests {
844870                let  remote_client_port = 8081 ; 
845871                let  peer_address = "126.0.0.1" . parse ( ) . unwrap ( ) ; 
846872
873+                 let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( remote_client_ip) ,  remote_client_port) ; 
874+ 
847875                let  request = AnnounceRequestBuilder :: default ( ) 
876+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
848877                    . with_info_hash ( info_hash) 
849878                    . with_peer_id ( peer_id) 
850879                    . with_ip_address ( peer_address) 
851880                    . with_port ( client_port) 
852881                    . into ( ) ; 
853882
854-                 let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( remote_client_ip) ,  remote_client_port) ; 
855883                handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
856884
857885                let  peers = tracker. get_all_torrent_peers ( & info_hash. 0 . into ( ) ) . await ; 
@@ -882,7 +910,9 @@ mod tests {
882910                let  client_ip_v6 = client_ip_v4. to_ipv6_compatible ( ) ; 
883911                let  client_port = 8080 ; 
884912                let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( client_ip_v6) ,  client_port) ; 
885-                 let  request = AnnounceRequestBuilder :: default ( ) . into ( ) ; 
913+                 let  request = AnnounceRequestBuilder :: default ( ) 
914+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
915+                     . into ( ) ; 
886916                let  response = handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
887917                response
888918            } 
@@ -911,13 +941,16 @@ mod tests {
911941                tracker_stats_service. should_throw_event ( TrackerStatisticsEvent :: Udp6Announce ) ; 
912942
913943                let  tracker = Arc :: new ( TorrentTracker :: new ( default_tracker_config ( ) ,  tracker_stats_service) . unwrap ( ) ) ; 
914-                 handle_announce ( 
915-                     sample_ipv6_remote_addr ( ) , 
916-                     & AnnounceRequestBuilder :: default ( ) . into ( ) , 
917-                     tracker. clone ( ) , 
918-                 ) 
919-                 . await 
920-                 . unwrap ( ) ; 
944+ 
945+                 let  remote_addr = sample_ipv6_remote_addr ( ) ; 
946+ 
947+                 let  announce_request = AnnounceRequestBuilder :: default ( ) 
948+                     . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
949+                     . into ( ) ; 
950+ 
951+                 handle_announce ( remote_addr,  & announce_request,  tracker. clone ( ) ) 
952+                     . await 
953+                     . unwrap ( ) ; 
921954            } 
922955
923956            mod  from_a_loopback_ip { 
@@ -928,6 +961,7 @@ mod tests {
928961
929962                use  crate :: statistics:: StatsTracker ; 
930963                use  crate :: tracker:: tracker:: TorrentTracker ; 
964+                 use  crate :: udp:: connection_cookie:: { into_connection_id,  make_connection_cookie} ; 
931965                use  crate :: udp:: handle_announce; 
932966                use  crate :: udp:: handlers:: tests:: announce_request:: AnnounceRequestBuilder ; 
933967                use  crate :: udp:: handlers:: tests:: TrackerConfigurationBuilder ; 
@@ -948,14 +982,16 @@ mod tests {
948982                    let  info_hash = AquaticInfoHash ( [ 0u8 ;  20 ] ) ; 
949983                    let  peer_id = AquaticPeerId ( [ 255u8 ;  20 ] ) ; 
950984
985+                     let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( client_ip_v6) ,  client_port) ; 
986+ 
951987                    let  request = AnnounceRequestBuilder :: default ( ) 
988+                         . with_connection_id ( into_connection_id ( & make_connection_cookie ( & remote_addr) ) ) 
952989                        . with_info_hash ( info_hash) 
953990                        . with_peer_id ( peer_id) 
954991                        . with_ip_address ( client_ip_v4) 
955992                        . with_port ( client_port) 
956993                        . into ( ) ; 
957994
958-                     let  remote_addr = SocketAddr :: new ( IpAddr :: V6 ( client_ip_v6) ,  client_port) ; 
959995                    handle_announce ( remote_addr,  & request,  tracker. clone ( ) ) . await . unwrap ( ) ; 
960996
961997                    let  peers = tracker. get_all_torrent_peers ( & info_hash. 0 . into ( ) ) . await ; 
0 commit comments