@@ -732,14 +732,13 @@ impl Endpoint {
732
732
self . add_node_addr ( node_addr. clone ( ) ) ?;
733
733
}
734
734
let node_id = node_addr. node_id ;
735
- let direct_addresses = node_addr. direct_addresses . clone ( ) ;
736
735
let relay_url = node_addr. relay_url . clone ( ) ;
737
736
738
737
// Get the mapped IPv6 address from the magic socket. Quinn will connect to this
739
738
// address. Start discovery for this node if it's enabled and we have no valid or
740
739
// verified address information for this node. Dropping the discovery cancels any
741
740
// still running task.
742
- let ( mapped_addr, _discovery_drop_guard) = self
741
+ let ( mapped_addr, direct_addresses , _discovery_drop_guard) = self
743
742
. get_mapping_addr_and_maybe_start_discovery ( node_addr)
744
743
. await
745
744
. context ( NoAddressSnafu ) ?;
@@ -770,18 +769,26 @@ impl Endpoint {
770
769
} ;
771
770
772
771
// 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
+ } ;
774
777
let server_name = & tls:: name:: encode ( node_id) ;
775
778
let connect = self
776
779
. msock
777
780
. endpoint ( )
778
781
. connect_with ( client_config, dest_addr, server_name)
779
782
. context ( QuinnSnafu ) ?;
780
783
784
+ let mut paths = direct_addresses;
785
+ paths. push ( mapped_addr. private_socket_addr ( ) ) ;
786
+
781
787
Ok ( Connecting {
782
788
inner : connect,
783
789
ep : self . clone ( ) ,
784
790
remote_node_id : Some ( node_id) ,
791
+ paths,
785
792
_discovery_drop_guard,
786
793
} )
787
794
}
@@ -1376,18 +1383,20 @@ impl Endpoint {
1376
1383
async fn get_mapping_addr_and_maybe_start_discovery (
1377
1384
& self ,
1378
1385
node_addr : NodeAddr ,
1379
- ) -> Result < ( NodeIdMappedAddr , Option < DiscoveryTask > ) , GetMappingAddressError > {
1386
+ ) -> Result < ( NodeIdMappedAddr , Vec < SocketAddr > , Option < DiscoveryTask > ) , GetMappingAddressError >
1387
+ {
1380
1388
let node_id = node_addr. node_id ;
1381
1389
1382
1390
// Only return a mapped addr if we have some way of dialing this node, in other
1383
1391
// words, we have either a relay URL or at least one direct address.
1384
1392
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) ) )
1386
1395
} else {
1387
1396
None
1388
1397
} ;
1389
1398
match addr {
1390
- Some ( addr ) => {
1399
+ Some ( ( maddr , direct ) ) => {
1391
1400
// We have some way of dialing this node, but that doesn't actually mean
1392
1401
// we can actually connect to any of these addresses.
1393
1402
// Therefore, we will invoke the discovery service if we haven't received from the
@@ -1399,7 +1408,7 @@ impl Endpoint {
1399
1408
let discovery = DiscoveryTask :: maybe_start_after_delay ( self , node_id, delay)
1400
1409
. ok ( )
1401
1410
. flatten ( ) ;
1402
- Ok ( ( addr , discovery) )
1411
+ Ok ( ( maddr , direct , discovery) )
1403
1412
}
1404
1413
1405
1414
None => {
@@ -1414,7 +1423,8 @@ impl Endpoint {
1414
1423
. await
1415
1424
. context ( get_mapping_address_error:: DiscoverSnafu ) ?;
1416
1425
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) ) )
1418
1428
} else {
1419
1429
Err ( get_mapping_address_error:: NoAddressSnafu . build ( ) )
1420
1430
}
@@ -1643,6 +1653,8 @@ pub struct Connecting {
1643
1653
inner : quinn:: Connecting ,
1644
1654
ep : Endpoint ,
1645
1655
remote_node_id : Option < NodeId > ,
1656
+ /// Additional paths to open once a connection is created
1657
+ paths : Vec < SocketAddr > ,
1646
1658
/// We run discovery as long as we haven't established a connection yet.
1647
1659
#[ debug( "Option<DiscoveryTask>" ) ]
1648
1660
_discovery_drop_guard : Option < DiscoveryTask > ,
@@ -1771,15 +1783,21 @@ impl Future for Connecting {
1771
1783
if let Some ( remote) = * this. remote_node_id {
1772
1784
let weak_handle = conn. inner . weak_handle ( ) ;
1773
1785
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
+ ) ;
1777
1792
} else if let Ok ( remote) = conn. remote_node_id ( ) {
1778
1793
let weak_handle = conn. inner . weak_handle ( ) ;
1779
1794
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
+ ) ;
1783
1801
} else {
1784
1802
warn ! ( "unable to determine node id for the remote" ) ;
1785
1803
}
0 commit comments