@@ -27,12 +27,12 @@ use uuid::Uuid;
2727
2828use crate :: {
2929 errors:: HttpError ,
30- peers:: { FetchReceiver , PeersImpl } ,
30+ peers:: { FetchReceiver , PeerAddress , PeersImpl } ,
3131} ;
3232
3333struct MockPeersUniverse {
3434 artifact : Bytes ,
35- peers : BTreeMap < SocketAddr , MockPeer > ,
35+ peers : BTreeMap < PeerAddress , MockPeer > ,
3636 attempt_bitmaps : Vec < AttemptBitmap > ,
3737}
3838
@@ -49,7 +49,7 @@ impl fmt::Debug for MockPeersUniverse {
4949impl MockPeersUniverse {
5050 fn new (
5151 artifact : Bytes ,
52- peers : BTreeMap < SocketAddr , MockPeer > ,
52+ peers : BTreeMap < PeerAddress , MockPeer > ,
5353 attempt_bitmaps : Vec < AttemptBitmap > ,
5454 ) -> Self {
5555 assert ! ( peers. len( ) <= 32 , "this test only supports up to 32 peers" ) ;
@@ -70,7 +70,7 @@ impl MockPeersUniverse {
7070 // being unique identifiers. This means that this code can use a BTreeMap rather than a
7171 // fancier structure like an IndexMap.
7272 let peers_strategy = prop:: collection:: btree_map (
73- any :: < SocketAddr > ( ) ,
73+ any :: < PeerAddress > ( ) ,
7474 any :: < MockResponse_ > ( ) ,
7575 0 ..max_peer_count,
7676 ) ;
@@ -82,7 +82,7 @@ impl MockPeersUniverse {
8282 ( artifact_strategy, peers_strategy, attempt_bitmaps_strategy) . prop_map (
8383 |( artifact, peers, attempt_bitmaps) : (
8484 Vec < u8 > ,
85- BTreeMap < SocketAddr , MockResponse_ > ,
85+ BTreeMap < PeerAddress , MockResponse_ > ,
8686 Vec < AttemptBitmap > ,
8787 ) | {
8888 let artifact = Bytes :: from ( artifact) ;
@@ -107,7 +107,7 @@ impl MockPeersUniverse {
107107 fn expected_result (
108108 & self ,
109109 timeout : Duration ,
110- ) -> Result < ( usize , SocketAddr ) , usize > {
110+ ) -> Result < ( usize , PeerAddress ) , usize > {
111111 self . attempts ( )
112112 . enumerate ( )
113113 . filter_map ( |( attempt, peers) | {
@@ -174,20 +174,20 @@ enum AttemptBitmap {
174174struct MockPeers {
175175 artifact : Bytes ,
176176 // Peers within the universe that have been selected
177- selected_peers : BTreeMap < SocketAddr , MockPeer > ,
177+ selected_peers : BTreeMap < PeerAddress , MockPeer > ,
178178}
179179
180180impl MockPeers {
181- fn get ( & self , addr : SocketAddr ) -> Option < & MockPeer > {
182- self . selected_peers . get ( & addr )
181+ fn get ( & self , peer : PeerAddress ) -> Option < & MockPeer > {
182+ self . selected_peers . get ( & peer )
183183 }
184184
185- fn peers ( & self ) -> impl Iterator < Item = ( & SocketAddr , & MockPeer ) > + ' _ {
185+ fn peers ( & self ) -> impl Iterator < Item = ( & PeerAddress , & MockPeer ) > + ' _ {
186186 self . selected_peers . iter ( )
187187 }
188188
189189 /// Returns the peer that can return the entire dataset within the timeout.
190- fn successful_peer ( & self , timeout : Duration ) -> Option < SocketAddr > {
190+ fn successful_peer ( & self , timeout : Duration ) -> Option < PeerAddress > {
191191 self . peers ( )
192192 . filter_map ( |( addr, peer) | {
193193 if peer. artifact != self . artifact {
@@ -233,7 +233,7 @@ impl MockPeers {
233233
234234#[ async_trait]
235235impl PeersImpl for MockPeers {
236- fn peers ( & self ) -> Box < dyn Iterator < Item = SocketAddr > + Send + ' _ > {
236+ fn peers ( & self ) -> Box < dyn Iterator < Item = PeerAddress > + Send + ' _ > {
237237 Box :: new ( self . selected_peers . keys ( ) . copied ( ) )
238238 }
239239
@@ -243,7 +243,7 @@ impl PeersImpl for MockPeers {
243243
244244 async fn fetch_from_peer_impl (
245245 & self ,
246- peer : SocketAddr ,
246+ peer : PeerAddress ,
247247 // We don't (yet) use the artifact ID in MockPeers
248248 _artifact_hash_id : ArtifactHashId ,
249249 ) -> Result < ( u64 , FetchReceiver ) , HttpError > {
@@ -261,7 +261,7 @@ impl PeersImpl for MockPeers {
261261
262262 async fn report_progress_impl (
263263 & self ,
264- _peer : SocketAddr ,
264+ _peer : PeerAddress ,
265265 _update_id : Uuid ,
266266 _report : EventReport ,
267267 ) -> Result < ( ) , ClientError > {
@@ -469,26 +469,31 @@ struct MockReportPeers {
469469
470470impl MockReportPeers {
471471 // SocketAddr::new is not a const fn in stable Rust as of this writing
472- fn valid_peer ( ) -> SocketAddr {
473- SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ) , 2000 )
472+ fn valid_peer ( ) -> PeerAddress {
473+ PeerAddress :: new ( SocketAddr :: new (
474+ IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ) ) ,
475+ 2000 ,
476+ ) )
474477 }
475478
476- fn invalid_peer ( ) -> SocketAddr {
477- SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ) ) , 2000 )
479+ fn invalid_peer ( ) -> PeerAddress {
480+ PeerAddress :: new ( SocketAddr :: new (
481+ IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ) ) ,
482+ 2000 ,
483+ ) )
478484 }
479485
480- fn unresponsive_peer ( ) -> SocketAddr {
481- SocketAddr :: new ( IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 ) ) , 2000 )
482- }
483-
484- fn new ( update_id : Uuid , report_sender : mpsc:: Sender < EventReport > ) -> Self {
485- Self { update_id, report_sender }
486+ fn unresponsive_peer ( ) -> PeerAddress {
487+ PeerAddress :: new ( SocketAddr :: new (
488+ IpAddr :: V6 ( Ipv6Addr :: new ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 3 ) ) ,
489+ 2000 ,
490+ ) )
486491 }
487492}
488493
489494#[ async_trait]
490495impl PeersImpl for MockReportPeers {
491- fn peers ( & self ) -> Box < dyn Iterator < Item = SocketAddr > + Send + ' _ > {
496+ fn peers ( & self ) -> Box < dyn Iterator < Item = PeerAddress > + Send + ' _ > {
492497 Box :: new (
493498 [
494499 Self :: valid_peer ( ) ,
@@ -505,7 +510,7 @@ impl PeersImpl for MockReportPeers {
505510
506511 async fn fetch_from_peer_impl (
507512 & self ,
508- _peer : SocketAddr ,
513+ _peer : PeerAddress ,
509514 _artifact_hash_id : ArtifactHashId ,
510515 ) -> Result < ( u64 , FetchReceiver ) , HttpError > {
511516 unimplemented ! (
@@ -516,7 +521,7 @@ impl PeersImpl for MockReportPeers {
516521
517522 async fn report_progress_impl (
518523 & self ,
519- peer : SocketAddr ,
524+ peer : PeerAddress ,
520525 update_id : Uuid ,
521526 report : EventReport ,
522527 ) -> Result < ( ) , ClientError > {
@@ -598,10 +603,10 @@ mod tests {
598603 async move {
599604 Ok ( Peers :: new (
600605 & reporter_log,
601- Box :: new ( MockReportPeers :: new (
606+ Box :: new ( MockReportPeers {
602607 update_id,
603608 report_sender,
604- ) ) ,
609+ } ) ,
605610 // The timeout is currently unused by broadcast_report.
606611 Duration :: from_secs ( 10 ) ,
607612 ) )
@@ -620,7 +625,7 @@ mod tests {
620625 let artifact =
621626 fetch_artifact ( & cx, & log, attempts, timeout)
622627 . await ?;
623- let address = artifact. addr ;
628+ let address = artifact. peer . address ( ) ;
624629 StepSuccess :: new ( artifact)
625630 . with_metadata (
626631 InstallinatorCompletionMetadata :: Download {
@@ -652,21 +657,21 @@ mod tests {
652657 match ( expected_result, fetched_artifact) {
653658 (
654659 Ok ( ( expected_attempt, expected_addr) ) ,
655- Ok ( FetchedArtifact { attempt, addr , mut artifact } ) ,
660+ Ok ( FetchedArtifact { attempt, peer , mut artifact } ) ,
656661 ) => {
657662 assert_eq ! (
658663 expected_attempt, attempt,
659664 "expected successful attempt is the same as actual attempt"
660665 ) ;
661666 assert_eq ! (
662- expected_addr, addr ,
667+ expected_addr, peer ,
663668 "expected successful peer is the same as actual peer"
664669 ) ;
665670 let artifact = artifact. copy_to_bytes ( artifact. num_bytes ( ) ) ;
666671 assert_eq ! (
667672 expected_artifact, artifact,
668673 "correct artifact fetched from peer {}" ,
669- addr ,
674+ peer ,
670675 ) ;
671676 }
672677 ( Err ( _) , Err ( _) ) => { }
@@ -716,7 +721,7 @@ mod tests {
716721
717722 fn assert_reports (
718723 reports : & [ EventReport ] ,
719- expected_result : Result < ( usize , SocketAddr ) , usize > ,
724+ expected_result : Result < ( usize , PeerAddress ) , usize > ,
720725 ) {
721726 let all_step_events: Vec < _ > =
722727 reports. iter ( ) . flat_map ( |report| & report. step_events ) . collect ( ) ;
@@ -740,7 +745,7 @@ mod tests {
740745 fn assert_success_events (
741746 all_step_events : Vec < & StepEvent > ,
742747 expected_attempt : usize ,
743- expected_addr : SocketAddr ,
748+ expected_peer : PeerAddress ,
744749 ) {
745750 let mut saw_success = false ;
746751
@@ -753,7 +758,8 @@ mod tests {
753758 peer,
754759 } => {
755760 assert_ne ! (
756- * peer, expected_addr,
761+ * peer,
762+ expected_peer. address( ) ,
757763 "peer cannot match since this is the last attempt"
758764 ) ;
759765 }
@@ -795,7 +801,8 @@ mod tests {
795801 ..
796802 } => {
797803 assert_eq ! (
798- * address, expected_addr,
804+ * address,
805+ expected_peer. address( ) ,
799806 "address matches expected"
800807 ) ;
801808 }
0 commit comments