@@ -39,7 +39,6 @@ use walkdir::WalkDir;
3939use crate :: blobs:: Collection ;
4040use crate :: hp:: cfg:: Endpoint ;
4141use crate :: hp:: derp:: DerpMap ;
42- use crate :: net:: ip:: find_local_addresses;
4342use crate :: protocol:: {
4443 read_lp, write_lp, Closed , GetRequest , Handshake , RangeSpec , Request , VERSION ,
4544} ;
@@ -524,7 +523,7 @@ impl Provider {
524523 /// The address on which the provider socket is bound.
525524 ///
526525 /// Note that this could be an unspecified address, if you need an address on which you
527- /// can contact the provider consider using [`Provider::listen_addresses `]. However the
526+ /// can contact the provider consider using [`Provider::local_endpoint_addresses `]. However the
528527 /// port will always be the concrete port.
529528 pub fn local_address ( & self ) -> Result < Vec < SocketAddr > > {
530529 self . inner . local_address ( )
@@ -535,11 +534,9 @@ impl Provider {
535534 self . inner . local_endpoints ( ) . await
536535 }
537536
538- /// Returns all addresses on which the provider is reachable.
539- ///
540- /// This will never be empty.
541- pub fn listen_addresses ( & self ) -> Result < Vec < SocketAddr > > {
542- self . inner . listen_addresses ( )
537+ /// Convenience method to get just the addr part of [`Provider::local_endpoints`].
538+ pub async fn local_endpoint_addresses ( & self ) -> Result < Vec < SocketAddr > > {
539+ self . inner . local_endpoint_addresses ( ) . await
543540 }
544541
545542 /// Returns the [`PeerId`] of the provider.
@@ -563,9 +560,9 @@ impl Provider {
563560 /// Return a single token containing everything needed to get a hash.
564561 ///
565562 /// See [`Ticket`] for more details of how it can be used.
566- pub fn ticket ( & self , hash : Hash ) -> Result < Ticket > {
563+ pub async fn ticket ( & self , hash : Hash ) -> Result < Ticket > {
567564 // TODO: Verify that the hash exists in the db?
568- let addrs = self . listen_addresses ( ) ?;
565+ let addrs = self . local_endpoint_addresses ( ) . await ?;
569566 Ticket :: new ( hash, self . peer_id ( ) , addrs)
570567 }
571568
@@ -591,6 +588,11 @@ impl ProviderInner {
591588 self . conn . local_endpoints ( ) . await
592589 }
593590
591+ async fn local_endpoint_addresses ( & self ) -> Result < Vec < SocketAddr > > {
592+ let endpoints = self . local_endpoints ( ) . await ?;
593+ Ok ( endpoints. into_iter ( ) . map ( |x| x. addr ) . collect ( ) )
594+ }
595+
594596 fn local_address ( & self ) -> Result < Vec < SocketAddr > > {
595597 let ( v4, v6) = self . conn . local_addr ( ) ?;
596598 let mut addrs = vec ! [ v4] ;
@@ -599,9 +601,6 @@ impl ProviderInner {
599601 }
600602 Ok ( addrs)
601603 }
602- fn listen_addresses ( & self ) -> Result < Vec < SocketAddr > > {
603- find_local_addresses ( & self . local_address ( ) ?)
604- }
605604}
606605
607606/// The future completes when the spawned tokio task finishes.
@@ -680,13 +679,21 @@ impl RpcHandler {
680679 async fn id ( self , _: IdRequest ) -> IdResponse {
681680 IdResponse {
682681 peer_id : Box :: new ( self . inner . keypair . public ( ) . into ( ) ) ,
683- listen_addrs : self . inner . listen_addresses ( ) . unwrap_or_default ( ) ,
682+ listen_addrs : self
683+ . inner
684+ . local_endpoint_addresses ( )
685+ . await
686+ . unwrap_or_default ( ) ,
684687 version : env ! ( "CARGO_PKG_VERSION" ) . to_string ( ) ,
685688 }
686689 }
687690 async fn addrs ( self , _: AddrsRequest ) -> AddrsResponse {
688691 AddrsResponse {
689- addrs : self . inner . listen_addresses ( ) . unwrap_or_default ( ) ,
692+ addrs : self
693+ . inner
694+ . local_endpoint_addresses ( )
695+ . await
696+ . unwrap_or_default ( ) ,
690697 }
691698 }
692699 async fn shutdown ( self , request : ShutdownRequest ) {
@@ -1358,7 +1365,7 @@ mod tests {
13581365 . await
13591366 . unwrap ( ) ;
13601367 let _drop_guard = provider. cancel_token ( ) . drop_guard ( ) ;
1361- let ticket = provider. ticket ( hash) . unwrap ( ) ;
1368+ let ticket = provider. ticket ( hash) . await . unwrap ( ) ;
13621369 println ! ( "addrs: {:?}" , ticket. addrs( ) ) ;
13631370 assert ! ( !ticket. addrs( ) . is_empty( ) ) ;
13641371 }
0 commit comments