Skip to content

Commit ccc30f9

Browse files
open additional paths after the initial connection
1 parent e9aab29 commit ccc30f9

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iroh/src/endpoint.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,15 +1811,9 @@ impl Connection {
18111811

18121812
// Grab the remote identity and register this connection
18131813
if let Some(remote) = remote_id {
1814-
let weak_handle = conn.inner.weak_handle();
1815-
let path_events = conn.inner.path_events();
1816-
ep.msock
1817-
.register_connection(remote, weak_handle, path_events);
1814+
ep.msock.register_connection(remote, &conn.inner);
18181815
} else if let Ok(remote) = conn.remote_node_id() {
1819-
let weak_handle = conn.inner.weak_handle();
1820-
let path_events = conn.inner.path_events();
1821-
ep.msock
1822-
.register_connection(remote, weak_handle, path_events);
1816+
ep.msock.register_connection(remote, &conn.inner);
18231817
} else {
18241818
warn!("unable to determine node id for the remote");
18251819
}

iroh/src/magicsock.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use netwatch::netmon;
4343
#[cfg(not(wasm_browser))]
4444
use netwatch::{ip::LocalAddresses, UdpSocket};
4545
use quinn::{AsyncUdpSocket, ServerConfig, WeakConnectionHandle};
46-
use quinn_proto::PathEvent;
4746
use rand::Rng;
4847
use relay_mapped_addrs::{IpMappedAddr, RelayMappedAddresses};
4948
use smallvec::SmallVec;
@@ -292,18 +291,14 @@ impl MagicSock {
292291
self.local_addrs_watch.get().expect("disconnected")
293292
}
294293

295-
pub(crate) fn register_connection(
296-
&self,
297-
remote: NodeId,
298-
conn: WeakConnectionHandle,
299-
mut path_events: tokio::sync::broadcast::Receiver<PathEvent>,
300-
) {
301-
self.connection_map.insert(remote, conn);
294+
pub(crate) fn register_connection(&self, remote: NodeId, conn: &quinn::Connection) {
295+
let weak_handle = conn.weak_handle();
296+
self.connection_map.insert(remote, weak_handle);
302297

303-
// TODO: open additional paths
304298
// TODO: track task
305299
// TODO: find a good home for this
306-
task::spawn(async move {
300+
let mut path_events = conn.path_events();
301+
let _task = task::spawn(async move {
307302
loop {
308303
match path_events.recv().await {
309304
Ok(event) => {
@@ -316,6 +311,11 @@ impl MagicSock {
316311
}
317312
}
318313
});
314+
315+
// open additional paths
316+
if let Some(addr) = self.node_map.get_current_addr(remote) {
317+
self.add_paths(addr);
318+
}
319319
}
320320

321321
#[cfg(not(wasm_browser))]

iroh/src/magicsock/node_map.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,14 @@ impl NodeMap {
189189
.unwrap_or_default()
190190
}
191191

192+
pub(super) fn get_current_addr(&self, node_key: NodeId) -> Option<NodeAddr> {
193+
self.inner
194+
.lock()
195+
.expect("poisoned")
196+
.get(NodeStateKey::NodeId(node_key))
197+
.map(|ep| ep.get_current_addr())
198+
}
199+
192200
pub(super) fn handle_call_me_maybe(
193201
&self,
194202
sender: PublicKey,

iroh/src/magicsock/node_map/node_state.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,17 @@ impl NodeState {
647647
(udp_addr, relay_url, ping_msgs)
648648
}
649649

650+
pub(crate) fn get_current_addr(&self) -> NodeAddr {
651+
// TODO: more selective?
652+
let mut node_addr =
653+
NodeAddr::new(self.node_id).with_direct_addresses(self.udp_paths.addrs());
654+
if let Some((url, _)) = &self.relay_url {
655+
node_addr = node_addr.with_relay_url(url.clone());
656+
}
657+
658+
node_addr
659+
}
660+
650661
/// Get the direct addresses for this endpoint.
651662
pub(super) fn direct_addresses(&self) -> impl Iterator<Item = IpPort> + '_ {
652663
self.udp_paths.paths.keys().copied()

iroh/src/magicsock/node_map/udp_paths.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ impl NodeUdpPaths {
8888
chosen_candidate: None,
8989
}
9090
}
91+
pub(super) fn addrs(&self) -> Vec<SocketAddr> {
92+
self.paths.keys().map(|ip| (*ip).into()).collect()
93+
}
9194

9295
/// Returns the current UDP address to send on.
9396
///

0 commit comments

Comments
 (0)