@@ -732,14 +732,13 @@ impl Endpoint {
732732 self . add_node_addr ( node_addr. clone ( ) ) ?;
733733 }
734734 let node_id = node_addr. node_id ;
735- let direct_addresses = node_addr. direct_addresses . clone ( ) ;
736735 let relay_url = node_addr. relay_url . clone ( ) ;
737736
738737 // Get the mapped IPv6 address from the magic socket. Quinn will connect to this
739738 // address. Start discovery for this node if it's enabled and we have no valid or
740739 // verified address information for this node. Dropping the discovery cancels any
741740 // still running task.
742- let ( mapped_addr, _discovery_drop_guard) = self
741+ let ( mapped_addr, direct_addresses , _discovery_drop_guard) = self
743742 . get_mapping_addr_and_maybe_start_discovery ( node_addr)
744743 . await
745744 . context ( NoAddressSnafu ) ?;
@@ -770,18 +769,26 @@ impl Endpoint {
770769 } ;
771770
772771 // TODO: race available addresses, this is currently only using the relay addr to connect
773- let dest_addr = mapped_addr. private_socket_addr ( ) ;
772+ let dest_addr = if relay_url. is_none ( ) && !direct_addresses. is_empty ( ) {
773+ direct_addresses[ 0 ]
774+ } else {
775+ mapped_addr. private_socket_addr ( )
776+ } ;
774777 let server_name = & tls:: name:: encode ( node_id) ;
775778 let connect = self
776779 . msock
777780 . endpoint ( )
778781 . connect_with ( client_config, dest_addr, server_name)
779782 . context ( QuinnSnafu ) ?;
780783
784+ let mut paths = direct_addresses;
785+ paths. push ( mapped_addr. private_socket_addr ( ) ) ;
786+
781787 Ok ( Connecting {
782788 inner : connect,
783789 ep : self . clone ( ) ,
784790 remote_node_id : Some ( node_id) ,
791+ paths,
785792 _discovery_drop_guard,
786793 } )
787794 }
@@ -1376,18 +1383,20 @@ impl Endpoint {
13761383 async fn get_mapping_addr_and_maybe_start_discovery (
13771384 & self ,
13781385 node_addr : NodeAddr ,
1379- ) -> Result < ( NodeIdMappedAddr , Option < DiscoveryTask > ) , GetMappingAddressError > {
1386+ ) -> Result < ( NodeIdMappedAddr , Vec < SocketAddr > , Option < DiscoveryTask > ) , GetMappingAddressError >
1387+ {
13801388 let node_id = node_addr. node_id ;
13811389
13821390 // Only return a mapped addr if we have some way of dialing this node, in other
13831391 // words, we have either a relay URL or at least one direct address.
13841392 let addr = if self . msock . has_send_address ( node_id) {
1385- self . msock . get_mapping_addr ( node_id)
1393+ let maddr = self . msock . get_mapping_addr ( node_id) ;
1394+ maddr. map ( |maddr| ( maddr, self . msock . get_direct_addrs ( node_id) ) )
13861395 } else {
13871396 None
13881397 } ;
13891398 match addr {
1390- Some ( addr ) => {
1399+ Some ( ( maddr , direct ) ) => {
13911400 // We have some way of dialing this node, but that doesn't actually mean
13921401 // we can actually connect to any of these addresses.
13931402 // Therefore, we will invoke the discovery service if we haven't received from the
@@ -1399,7 +1408,7 @@ impl Endpoint {
13991408 let discovery = DiscoveryTask :: maybe_start_after_delay ( self , node_id, delay)
14001409 . ok ( )
14011410 . flatten ( ) ;
1402- Ok ( ( addr , discovery) )
1411+ Ok ( ( maddr , direct , discovery) )
14031412 }
14041413
14051414 None => {
@@ -1414,7 +1423,8 @@ impl Endpoint {
14141423 . await
14151424 . context ( get_mapping_address_error:: DiscoverSnafu ) ?;
14161425 if let Some ( addr) = self . msock . get_mapping_addr ( node_id) {
1417- Ok ( ( addr, Some ( discovery) ) )
1426+ let direct = self . msock . get_direct_addrs ( node_id) ;
1427+ Ok ( ( addr, direct, Some ( discovery) ) )
14181428 } else {
14191429 Err ( get_mapping_address_error:: NoAddressSnafu . build ( ) )
14201430 }
@@ -1643,6 +1653,8 @@ pub struct Connecting {
16431653 inner : quinn:: Connecting ,
16441654 ep : Endpoint ,
16451655 remote_node_id : Option < NodeId > ,
1656+ /// Additional paths to open once a connection is created
1657+ paths : Vec < SocketAddr > ,
16461658 /// We run discovery as long as we haven't established a connection yet.
16471659 #[ debug( "Option<DiscoveryTask>" ) ]
16481660 _discovery_drop_guard : Option < DiscoveryTask > ,
@@ -1771,15 +1783,21 @@ impl Future for Connecting {
17711783 if let Some ( remote) = * this. remote_node_id {
17721784 let weak_handle = conn. inner . weak_handle ( ) ;
17731785 let path_events = conn. inner . path_events ( ) ;
1774- this. ep
1775- . msock
1776- . register_connection ( remote, weak_handle, path_events) ;
1786+ this. ep . msock . register_connection (
1787+ remote,
1788+ weak_handle,
1789+ path_events,
1790+ this. paths . clone ( ) ,
1791+ ) ;
17771792 } else if let Ok ( remote) = conn. remote_node_id ( ) {
17781793 let weak_handle = conn. inner . weak_handle ( ) ;
17791794 let path_events = conn. inner . path_events ( ) ;
1780- this. ep
1781- . msock
1782- . register_connection ( remote, weak_handle, path_events) ;
1795+ this. ep . msock . register_connection (
1796+ remote,
1797+ weak_handle,
1798+ path_events,
1799+ this. paths . clone ( ) ,
1800+ ) ;
17831801 } else {
17841802 warn ! ( "unable to determine node id for the remote" ) ;
17851803 }
0 commit comments