Skip to content

Commit d953b42

Browse files
committed
fix: reduce size of Connection struct and improve watchers
1 parent 41285a1 commit d953b42

File tree

7 files changed

+103
-97
lines changed

7 files changed

+103
-97
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ unused-async = "warn"
4646
iroh-quinn = { git = "https://github.com/n0-computer/quinn", branch = "main-iroh" }
4747
iroh-quinn-proto = { git = "https://github.com/n0-computer/quinn", branch = "main-iroh" }
4848
iroh-quinn-udp = { git = "https://github.com/n0-computer/quinn", branch = "main-iroh" }
49+
n0-watcher = { git = "https://github.com/n0-computer/n0-watcher", branch = "Frando/lazy-direct" }
4950

5051
# iroh-quinn = { path = "../iroh-quinn/quinn" }
5152
# iroh-quinn-proto = { path = "../iroh-quinn/quinn-proto" }

iroh/src/endpoint.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use url::Url;
2626

2727
pub use super::magicsock::{
2828
AddEndpointAddrError, ConnectionType, DirectAddr, DirectAddrType, PathInfo,
29-
endpoint_map::{PathInfoList, Source},
29+
endpoint_map::{PathInfoIter, Source},
3030
};
3131
#[cfg(wasm_browser)]
3232
use crate::discovery::pkarr::PkarrResolver;
@@ -1804,9 +1804,9 @@ mod tests {
18041804
send.write_all(b"hello").await.anyerr()?;
18051805
let mut paths = conn.paths().stream();
18061806
info!("Waiting for direct connection");
1807-
while let Some(infos) = paths.next().await {
1807+
while let Some(mut infos) = paths.next().await {
18081808
info!(?infos, "new PathInfos");
1809-
if infos.iter().any(|info| info.is_ip()) {
1809+
if infos.any(|info| info.is_ip()) {
18101810
break;
18111811
}
18121812
}
@@ -1893,15 +1893,15 @@ mod tests {
18931893

18941894
// We should be connected via IP, because it is faster than the relay server.
18951895
// TODO: Maybe not panic if this is not true?
1896-
let path_info = conn.paths().get();
1896+
let mut path_info = conn.paths().get();
18971897
assert_eq!(path_info.len(), 1);
1898-
assert!(path_info.iter().next().unwrap().is_ip());
1898+
assert!(path_info.next().unwrap().is_ip());
18991899

19001900
let mut paths = conn.paths().stream();
19011901
time::timeout(Duration::from_secs(5), async move {
1902-
while let Some(infos) = paths.next().await {
1902+
while let Some(mut infos) = paths.next().await {
19031903
info!(?infos, "new PathInfos");
1904-
if infos.iter().any(|info| info.is_relay()) {
1904+
if infos.any(|info| info.is_relay()) {
19051905
break;
19061906
}
19071907
}
@@ -1944,9 +1944,9 @@ mod tests {
19441944
// being added on this side too.
19451945
let mut paths = conn.paths().stream();
19461946
time::timeout(Duration::from_secs(5), async move {
1947-
while let Some(infos) = paths.next().await {
1947+
while let Some(mut infos) = paths.next().await {
19481948
info!(?infos, "new PathInfos");
1949-
if infos.iter().any(|path| path.is_relay()) {
1949+
if infos.any(|path| path.is_relay()) {
19501950
break;
19511951
}
19521952
}

iroh/src/endpoint/connection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::{
4343
discovery::DiscoveryTask,
4444
magicsock::{
4545
EndpointStateActorStoppedError,
46-
endpoint_map::{PathInfoList, PathsWatcher},
46+
endpoint_map::{PathInfoIter, PathsWatcher},
4747
},
4848
};
4949

@@ -1462,8 +1462,8 @@ impl Connection {
14621462
///
14631463
/// [`PathInfo::is_selected`]: crate::magicsock::PathInfo::is_selected
14641464
/// [`PathInfo`]: crate::magicsock::PathInfo
1465-
pub fn paths(&self) -> impl Watcher<Value = PathInfoList> {
1466-
self.paths.clone()
1465+
pub fn paths(&self) -> impl Watcher<Value = PathInfoIter> {
1466+
self.paths.watch(self.inner.weak_handle())
14671467
}
14681468

14691469
/// Derives keying material from this connection's TLS session secrets.

iroh/src/magicsock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,7 @@ mod tests {
19851985
info!("stats: {:#?}", stats);
19861986
// TODO: ensure panics in this function are reported ok
19871987
if matches!(loss, ExpectedLoss::AlmostNone) {
1988-
for info in conn.paths().get().iter() {
1988+
for info in conn.paths().get() {
19891989
assert!(
19901990
info.stats().lost_packets < 10,
19911991
"[receiver] path {:?} should not loose many packets",

iroh/src/magicsock/endpoint_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod path_state;
2626

2727
pub(super) use endpoint_state::EndpointStateMessage;
2828
pub(crate) use endpoint_state::PathsWatcher;
29-
pub use endpoint_state::{ConnectionType, PathInfo, PathInfoList};
29+
pub use endpoint_state::{ConnectionType, PathInfo, PathInfoIter};
3030
use endpoint_state::{EndpointStateActor, EndpointStateHandle};
3131

3232
// TODO: use this

0 commit comments

Comments
 (0)