@@ -29,7 +29,6 @@ use crate::{
2929 Executor ,
3030 Multiaddr ,
3131 PeerId ,
32- address_translation,
3332 connection:: {
3433 ConnectionId ,
3534 ConnectionLimit ,
@@ -199,21 +198,8 @@ where
199198 /// * `observed_addr` - should be an address a remote observes you as, which can be obtained for
200199 /// example with the identify protocol.
201200 ///
202- pub fn address_translation < ' a > ( & ' a self , observed_addr : & ' a Multiaddr )
203- -> impl Iterator < Item = Multiaddr > + ' a
204- where
205- TMuxer : ' a ,
206- THandler : ' a ,
207- {
208- let mut addrs: Vec < _ > = self . listen_addrs ( )
209- . filter_map ( move |server| address_translation ( server, observed_addr) )
210- . collect ( ) ;
211-
212- // remove duplicates
213- addrs. sort_unstable ( ) ;
214- addrs. dedup ( ) ;
215-
216- addrs. into_iter ( )
201+ pub fn address_translation ( & self , observed_addr : & Multiaddr ) -> Vec < Multiaddr > {
202+ self . listeners . address_translation ( observed_addr)
217203 }
218204
219205 /// Returns the peer id of the local node.
@@ -240,7 +226,7 @@ where
240226 TPeerId : Send + ' static ,
241227 {
242228 let info = OutgoingInfo { address, peer_id : None } ;
243- match self . transport ( ) . dialer ( ) . dial ( address. clone ( ) ) {
229+ match self . listeners . dialer_for_addr ( address ) . dial ( address. clone ( ) ) {
244230 Ok ( f) => {
245231 let f = f. map_err ( |err| PendingConnectionError :: Transport ( TransportError :: Other ( err) ) ) ;
246232 self . pool . add_outgoing ( f, handler, info)
@@ -435,8 +421,8 @@ where
435421 let dialing = & mut self . dialing ;
436422 let ( next, event) = on_connection_failed ( dialing, id, endpoint, error, handler) ;
437423 if let Some ( dial) = next {
438- let transport = self . listeners . transport ( ) . clone ( ) ;
439- if let Err ( e) = dial_peer_impl ( transport , pool, dialing, dial) {
424+ let dialer = self . listeners . dialer_for_addr ( & dial . address ) ;
425+ if let Err ( e) = dial_peer_impl ( dialer , pool, dialing, dial) {
440426 log:: warn!( "Dialing aborted: {:?}" , e) ;
441427 }
442428 }
@@ -481,7 +467,8 @@ where
481467 TOutEvent : Send + ' static ,
482468 TPeerId : Send + ' static ,
483469 {
484- dial_peer_impl ( self . transport ( ) . clone ( ) , & mut self . pool , & mut self . dialing , opts)
470+ let dialer = self . listeners . dialer_for_addr ( & opts. address ) ;
471+ dial_peer_impl ( dialer, & mut self . pool , & mut self . dialing , opts)
485472 }
486473}
487474
@@ -495,9 +482,9 @@ struct DialingOpts<TPeerId, THandler> {
495482}
496483
497484/// Standalone implementation of `Network::dial_peer` for more granular borrowing.
498- fn dial_peer_impl < TMuxer , TInEvent , TOutEvent , THandler , TTrans , TConnInfo , TPeerId > (
499- transport : TTrans ,
500- pool : & mut Pool < TInEvent , TOutEvent , THandler , TTrans :: Error ,
485+ fn dial_peer_impl < TMuxer , TInEvent , TOutEvent , THandler , TDialer , TConnInfo , TPeerId > (
486+ dialer : TDialer ,
487+ pool : & mut Pool < TInEvent , TOutEvent , THandler , TDialer :: Error ,
501488 <THandler :: Handler as ConnectionHandler >:: Error , TConnInfo , TPeerId > ,
502489 dialing : & mut FnvHashMap < TPeerId , SmallVec < [ peer:: DialingState ; 10 ] > > ,
503490 opts : DialingOpts < TPeerId , THandler >
@@ -511,17 +498,17 @@ where
511498 InEvent = TInEvent ,
512499 OutEvent = TOutEvent ,
513500 > + Send + ' static ,
514- TTrans : Transport < Output = ( TConnInfo , TMuxer ) > ,
515- TTrans :: Dial : Send + ' static ,
516- TTrans :: Error : error:: Error + Send + ' static ,
501+ TDialer : Dialer < Output = ( TConnInfo , TMuxer ) > ,
502+ TDialer :: Dial : Send + ' static ,
503+ TDialer :: Error : error:: Error + Send + ' static ,
517504 TMuxer : StreamMuxer + Send + Sync + ' static ,
518505 TMuxer :: OutboundSubstream : Send + ' static ,
519506 TInEvent : Send + ' static ,
520507 TOutEvent : Send + ' static ,
521508 TPeerId : Eq + Hash + Send + Clone + ' static ,
522509 TConnInfo : ConnectionInfo < PeerId = TPeerId > + Send + ' static ,
523510{
524- let result = match transport . dialer ( ) . dial ( opts. address . clone ( ) ) {
511+ let result = match dialer. dial ( opts. address . clone ( ) ) {
525512 Ok ( fut) => {
526513 let fut = fut. map_err ( |e| PendingConnectionError :: Transport ( TransportError :: Other ( e) ) ) ;
527514 let info = OutgoingInfo { address : & opts. address , peer_id : Some ( & opts. peer ) } ;
0 commit comments