Skip to content

Commit d915bfd

Browse files
feat(iroh)!: introduce transport abstraction (#3279)
A first step towards the work of #3276 ## Breaking changes - `iroh::watcher` is now its own crate `n0-watcher` - `iroh::endpoint::Endpoint::node_addr` now returns `impl Watcher<Value = Option<NodeAddr>>` - `iroh::endpoint::Endpoint::home_relay` now returns `impl Watcher<Value = Vec<RelayUrl>>` - `iroh::endpoint::Endpoint::bound_sockets` now returns `Vec<SocketAddr>` - `iroh-quinn` is updated to `0.14.0` Depends on - [x] n0-computer/n0-watcher#1 - [x] n0-computer/net-tools#26 - [x] n0-computer/quinn#67 - [x] n0-computer/n0-watcher#3 --------- Co-authored-by: Franz Heinzmann <frando@unbiskant.org>
1 parent c7cf08d commit d915bfd

34 files changed

+2199
-2578
lines changed

Cargo.lock

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

iroh-relay/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ postcard = { version = "1", default-features = false, features = [
4242
"use-std",
4343
"experimental-derive",
4444
] }
45-
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false, features = ["rustls-ring"] }
45+
quinn = { package = "iroh-quinn", version = "0.14.0", default-features = false, features = ["rustls-ring"] }
4646
quinn-proto = { package = "iroh-quinn-proto", version = "0.13.0" }
4747
rand = "0.8"
4848
reqwest = { version = "0.12", default-features = false, features = [

iroh/Cargo.toml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ workspace = true
2323
[dependencies]
2424
anyhow = "1.0.98"
2525
aead = { version = "0.5.2", features = ["bytes", "std"] }
26-
atomic-waker = "1.1.2"
27-
concurrent-queue = "2.5"
2826
backon = { version = "1.4" }
2927
bytes = "1.7"
3028
crypto_box = { version = "0.9.1", features = ["serde", "chacha20"] }
@@ -44,13 +42,14 @@ iroh-base = { version = "0.35.0", default-features = false, features = ["key", "
4442
iroh-relay = { version = "0.35", path = "../iroh-relay", default-features = false }
4543
n0-future = "0.1.2"
4644
n0-snafu = "0.2.0"
45+
n0-watcher = "0.2"
4746
nested_enum_utils = "0.2.1"
48-
netwatch = { version = "0.5" }
47+
netwatch = { version = "0.6" }
4948
pin-project = "1"
5049
pkarr = { version = "3.7", default-features = false, features = [
5150
"relays",
5251
] }
53-
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false, features = ["rustls-ring"] }
52+
quinn = { package = "iroh-quinn", version = "0.14.0", default-features = false, features = ["rustls-ring"] }
5453
quinn-proto = { package = "iroh-quinn-proto", version = "0.13.0" }
5554
quinn-udp = { package = "iroh-quinn-udp", version = "0.5.7" }
5655
rand = "0.8"
@@ -104,13 +103,14 @@ tracing-subscriber = { version = "0.3", features = [
104103
indicatif = { version = "0.17", features = ["tokio"], optional = true }
105104
parse-size = { version = "=1.0.0", optional = true, features = ['std'] } # pinned version to avoid bumping msrv to 1.81
106105

106+
107107
# non-wasm-in-browser dependencies
108108
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dependencies]
109109
hickory-resolver = "0.25.1"
110110
igd-next = { version = "0.16", features = ["aio_tokio"] }
111111
netdev = { version = "0.31.0" }
112112
portmapper = { version = "0.5.0", default-features = false }
113-
quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false, features = ["runtime-tokio", "rustls-ring"] }
113+
quinn = { package = "iroh-quinn", version = "0.14.0", default-features = false, features = ["runtime-tokio", "rustls-ring"] }
114114
tokio = { version = "1", features = [
115115
"io-util",
116116
"macros",
@@ -141,7 +141,6 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] }
141141
[target.'cfg(not(all(target_family = "wasm", target_os = "unknown")))'.dev-dependencies]
142142
axum = { version = "0.8" }
143143
clap = { version = "4", features = ["derive"] }
144-
futures-lite = "2.6"
145144
pretty_assertions = "1.4"
146145
rand_chacha = "0.3.1"
147146
tokio = { version = "1", features = [

iroh/bench/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ iroh = { path = ".." }
1212
iroh-metrics = "0.34"
1313
n0-future = "0.1.1"
1414
n0-snafu = "0.2.0"
15-
quinn = { package = "iroh-quinn", version = "0.13" }
15+
n0-watcher = "0.2"
16+
quinn = { package = "iroh-quinn", version = "0.14" }
1617
rand = "0.8"
1718
rcgen = "0.13"
1819
rustls = { version = "0.23", default-features = false, features = ["ring"] }

iroh/bench/src/iroh.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use std::{
66
use bytes::Bytes;
77
use iroh::{
88
endpoint::{Connection, ConnectionError, RecvStream, SendStream, TransportConfig},
9-
watcher::Watcher as _,
109
Endpoint, NodeAddr, RelayMode, RelayUrl,
1110
};
1211
use n0_snafu::{Result, ResultExt};
12+
use n0_watcher::Watcher as _;
1313
use tracing::{trace, warn};
1414

1515
use crate::{
@@ -54,7 +54,7 @@ pub fn server_endpoint(
5454
}
5555

5656
let addr = ep.bound_sockets();
57-
let addr = SocketAddr::new("127.0.0.1".parse().unwrap(), addr.0.port());
57+
let addr = SocketAddr::new("127.0.0.1".parse().unwrap(), addr[0].port());
5858
let mut addr = NodeAddr::new(ep.node_id()).with_direct_addresses([addr]);
5959
if let Some(relay_url) = relay_url {
6060
addr = addr.with_relay_url(relay_url.clone());

iroh/examples/0rtt.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use std::{env, future::Future, str::FromStr, time::Instant};
33
use clap::Parser;
44
use iroh::{
55
endpoint::{Connecting, Connection},
6-
watcher::Watcher,
76
SecretKey,
87
};
98
use iroh_base::ticket::NodeTicket;
109
use n0_future::{future, StreamExt};
1110
use n0_snafu::ResultExt;
11+
use n0_watcher::Watcher;
1212
use rand::thread_rng;
1313
use tracing::{info, trace};
1414

@@ -150,6 +150,7 @@ async fn accept(_args: Args) -> n0_snafu::Result<()> {
150150
println!("Listening on: {:?}", addr);
151151
println!("Node ID: {:?}", addr.node_id);
152152
println!("Ticket: {}", NodeTicket::from(addr));
153+
153154
let accept = async move {
154155
while let Some(incoming) = endpoint.accept().await {
155156
tokio::spawn(async move {

iroh/examples/connect-unreliable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
use std::net::SocketAddr;
99

1010
use clap::Parser;
11-
use iroh::{watcher::Watcher as _, Endpoint, NodeAddr, RelayMode, RelayUrl, SecretKey};
11+
use iroh::{Endpoint, NodeAddr, RelayMode, RelayUrl, SecretKey};
1212
use n0_snafu::ResultExt;
13+
use n0_watcher::Watcher as _;
1314
use tracing::info;
1415

1516
// An example ALPN that we are using to communicate over the `Endpoint`

iroh/examples/connect.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
use std::net::SocketAddr;
99

1010
use clap::Parser;
11-
use iroh::{watcher::Watcher as _, Endpoint, NodeAddr, RelayMode, RelayUrl, SecretKey};
11+
use iroh::{Endpoint, NodeAddr, RelayMode, RelayUrl, SecretKey};
1212
use n0_snafu::{Result, ResultExt};
13+
use n0_watcher::Watcher as _;
1314
use tracing::info;
1415

1516
// An example ALPN that we are using to communicate over the `Endpoint`
@@ -67,6 +68,8 @@ async fn main() -> Result<()> {
6768
.home_relay()
6869
.get()
6970
.unwrap()
71+
.first()
72+
.cloned()
7073
.expect("should be connected to a relay server, try calling `endpoint.local_endpoints()` or `endpoint.connect()` first, to ensure the endpoint has actually attempted a connection before checking for the connected relay server");
7174
println!("node relay server url: {relay_url}\n");
7275
// Build a `NodeAddr` from the node_id, relay url, and UDP addresses.

iroh/examples/echo-no-router.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
//!
88
//! cargo run --example echo-no-router --features=examples
99
10-
use iroh::{watcher::Watcher as _, Endpoint, NodeAddr};
10+
use iroh::{Endpoint, NodeAddr};
1111
use n0_snafu::{Error, Result, ResultExt};
12+
use n0_watcher::Watcher as _;
1213

1314
/// Each protocol is identified by its ALPN string.
1415
///

iroh/examples/echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use iroh::{
1010
endpoint::Connection,
1111
protocol::{AcceptError, ProtocolHandler, Router},
12-
watcher::Watcher as _,
1312
Endpoint, NodeAddr,
1413
};
1514
use n0_snafu::{Result, ResultExt};
15+
use n0_watcher::Watcher as _;
1616

1717
/// Each protocol is identified by its ALPN string.
1818
///

0 commit comments

Comments
 (0)