Skip to content

Commit a1a5723

Browse files
add more paths
1 parent 2d8f739 commit a1a5723

File tree

4 files changed

+61
-42
lines changed

4 files changed

+61
-42
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ unused-async = "warn"
4545
[patch.crates-io]
4646
rustls = { git = "https://github.com/n0-computer/rustls", rev = "be02113e7837df60953d02c2bdd0f4634fef3a80" }
4747
netwatch = { git = "https://github.com/n0-computer/net-tools", branch = "feat-multipath" }
48+
49+
[patch."https://github.com/n0-computer/quinn"]
50+
# iroh-quinn = { path = "../iroh-quinn/quinn" }
51+
# iroh-quinn-proto = { path = "../iroh-quinn/quinn-proto" }
52+
# iroh-quinn-udp = { path = "../iroh-quinn/quinn-udp" }
53+
54+
iroh-quinn = { git = "https://github.com//n0-computer/quinn", branch = "multipath-misc" }
55+
iroh-quinn-proto = { git = "https://github.com//n0-computer/quinn", branch = "multipath-misc" }
56+
iroh-quinn-udp = { git = "https://github.com//n0-computer/quinn", branch = "multipath-misc" }

iroh/src/endpoint.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -769,15 +769,13 @@ impl Endpoint {
769769
client_config
770770
};
771771

772+
// TODO: race available addresses, this is currently only using the relay addr to connect
773+
let dest_addr = mapped_addr.private_socket_addr();
772774
let server_name = &tls::name::encode(node_id);
773775
let connect = self
774776
.msock
775777
.endpoint()
776-
.connect_with(
777-
client_config,
778-
mapped_addr.private_socket_addr(),
779-
server_name,
780-
)
778+
.connect_with(client_config, dest_addr, server_name)
781779
.context(QuinnSnafu)?;
782780

783781
Ok(Connecting {

iroh/src/magicsock.rs

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -425,39 +425,7 @@ impl MagicSock {
425425
.add_node_addr(addr.clone(), source, &self.metrics.magicsock);
426426

427427
// Add paths to the existing connections
428-
{
429-
let mut map = self.connection_map.map.lock().expect("poisoned");
430-
let mut to_delete = Vec::new();
431-
if let Some(conns) = map.get_mut(&addr.node_id) {
432-
for (i, conn) in conns.into_iter().enumerate() {
433-
if let Some(conn) = conn.upgrade() {
434-
for addr in addr.direct_addresses() {
435-
let conn = conn.clone();
436-
let addr = *addr;
437-
task::spawn(async move {
438-
if let Err(err) = conn
439-
.open_path(addr, quinn_proto::PathStatus::Available)
440-
.await
441-
{
442-
warn!("failed to open path {:?}", err);
443-
}
444-
});
445-
}
446-
// TODO: add relay path as mapped addr
447-
} else {
448-
to_delete.push(i);
449-
}
450-
}
451-
// cleanup dead connections
452-
let mut i = 0;
453-
conns.retain(|_| {
454-
let remove = to_delete.contains(&i);
455-
i += 1;
456-
457-
!remove
458-
});
459-
}
460-
}
428+
self.add_paths(addr);
461429

462430
Ok(())
463431
} else if pruned != 0 {
@@ -467,6 +435,41 @@ impl MagicSock {
467435
}
468436
}
469437

438+
/// Adds all available addresses in the given `addr` as paths
439+
fn add_paths(&self, addr: NodeAddr) {
440+
let mut map = self.connection_map.map.lock().expect("poisoned");
441+
let mut to_delete = Vec::new();
442+
if let Some(conns) = map.get_mut(&addr.node_id) {
443+
for (i, conn) in conns.into_iter().enumerate() {
444+
if let Some(conn) = conn.upgrade() {
445+
for addr in addr.direct_addresses() {
446+
let conn = conn.clone();
447+
let addr = *addr;
448+
task::spawn(async move {
449+
if let Err(err) = conn
450+
.open_path(addr, quinn_proto::PathStatus::Available)
451+
.await
452+
{
453+
warn!("failed to open path {:?}", err);
454+
}
455+
});
456+
}
457+
// TODO: add relay path as mapped addr
458+
} else {
459+
to_delete.push(i);
460+
}
461+
}
462+
// cleanup dead connections
463+
let mut i = 0;
464+
conns.retain(|_| {
465+
let remove = to_delete.contains(&i);
466+
i += 1;
467+
468+
!remove
469+
});
470+
}
471+
}
472+
470473
/// Stores a new set of direct addresses.
471474
///
472475
/// If the direct addresses have changed from the previous set, they are published to
@@ -877,9 +880,18 @@ impl MagicSock {
877880
return;
878881
}
879882
}
883+
884+
// Add new addresses as paths
885+
self.add_paths(NodeAddr {
886+
node_id: sender,
887+
relay_url: None,
888+
direct_addresses: cm.my_numbers.iter().copied().collect(),
889+
});
890+
880891
let ping_actions =
881892
self.node_map
882893
.handle_call_me_maybe(sender, cm, &self.metrics.magicsock);
894+
883895
for action in ping_actions {
884896
match action {
885897
PingAction::SendCallMeMaybe { .. } => {

0 commit comments

Comments
 (0)