Skip to content

Commit 7a67148

Browse files
author
“ramfox”
committed
chore: upgrade to iroh@main and quic-rpc@branch
1 parent 64b6ae6 commit 7a67148

File tree

8 files changed

+256
-204
lines changed

8 files changed

+256
-204
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ postcard = { version = "1", default-features = false, features = [
5656
] }
5757
quic-rpc = { version = "0.18", optional = true }
5858
quic-rpc-derive = { version = "0.17", optional = true }
59-
quinn = { package = "iroh-quinn", version = "0.12", features = ["ring"] }
59+
quinn = { package = "iroh-quinn", version = "0.13", features = ["ring"] }
6060
rand = "0.8"
6161
range-collections = "0.4.0"
6262
redb = { version = "2.2.0", optional = true }
@@ -184,3 +184,8 @@ debug-assertions = false
184184
opt-level = 3
185185
panic = 'abort'
186186
incremental = false
187+
188+
[patch.crates-io]
189+
iroh-base = { git = "https://github.com/n0-computer/iroh.git", branch = "main" }
190+
iroh = { git = "https://github.com/n0-computer/iroh.git", branch = "main" }
191+
quic-rpc = { git = "https://github.com/n0-computer/quic-rpc.git", branch = "release-prep" }

examples/custom-protocol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use anyhow::Result;
4444
use clap::Parser;
4545
use futures_lite::future::Boxed as BoxedFuture;
4646
use iroh::{
47-
endpoint::{get_remote_node_id, Connecting},
47+
endpoint::Connecting,
4848
protocol::{ProtocolHandler, Router},
4949
Endpoint, NodeId,
5050
};
@@ -149,7 +149,7 @@ impl ProtocolHandler for BlobSearch {
149149
// Wait for the connection to be fully established.
150150
let connection = connecting.await?;
151151
// We can get the remote's node id from the connection.
152-
let node_id = get_remote_node_id(&connection)?;
152+
let node_id = connection.remote_node_id()?;
153153
println!("accepted connection from {node_id}");
154154

155155
// Our protocol is a simple request-response protocol, so we expect the

examples/fetch-fsm.rs

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,19 @@
33
//! Since this example does not use [`iroh-net::Endpoint`], it does not do any holepunching, and so will only work locally or between two processes that have public IP addresses.
44
//!
55
//! Run the provide-bytes example first. It will give instructions on how to run this example properly.
6-
use std::net::SocketAddr;
6+
use std::str::FromStr;
77

88
use anyhow::{Context, Result};
99
use iroh_blobs::{
1010
get::fsm::{AtInitial, ConnectedNext, EndBlobNext},
1111
hashseq::HashSeq,
1212
protocol::GetRequest,
13-
Hash,
13+
BlobFormat,
1414
};
1515
use iroh_io::ConcatenateSliceWriter;
1616
use tracing_subscriber::{prelude::*, EnvFilter};
1717

1818
mod connect;
19-
use connect::{load_certs, make_client_endpoint};
2019

2120
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
2221
pub fn setup_logging() {
@@ -29,50 +28,49 @@ pub fn setup_logging() {
2928

3029
#[tokio::main]
3130
async fn main() -> Result<()> {
32-
println!("\nfetch bytes example!");
31+
println!("\nfetch fsm example!");
3332
setup_logging();
3433
let args: Vec<_> = std::env::args().collect();
35-
if args.len() != 4 {
36-
anyhow::bail!("usage: fetch-bytes [HASH] [SOCKET_ADDR] [FORMAT]");
34+
if args.len() != 2 {
35+
anyhow::bail!("usage: fetch-fsm [TICKET]");
3736
}
38-
let hash: Hash = args[1].parse().context("unable to parse [HASH]")?;
39-
let addr: SocketAddr = args[2].parse().context("unable to parse [SOCKET_ADDR]")?;
40-
let format = {
41-
if args[3] != "blob" && args[3] != "collection" {
42-
anyhow::bail!(
43-
"expected either 'blob' or 'collection' for FORMAT argument, got {}",
44-
args[3]
45-
);
46-
}
47-
args[3].clone()
48-
};
37+
let ticket =
38+
iroh_blobs::ticket::BlobTicket::from_str(&args[1]).context("unable to parse [TICKET]")?;
4939

50-
// load tls certificates
51-
// This will error if you have not run the `provide-bytes` example
52-
let roots = load_certs().await?;
40+
let (node, hash, format) = ticket.into_parts();
5341

5442
// create an endpoint to listen for incoming connections
55-
let endpoint = make_client_endpoint(roots)?;
56-
println!("\nlistening on {}", endpoint.local_addr()?);
57-
println!("fetching hash {hash} from {addr}");
43+
let endpoint = iroh::Endpoint::builder()
44+
.relay_mode(iroh::RelayMode::Disabled)
45+
.alpns(vec![connect::EXAMPLE_ALPN.into()])
46+
.bind()
47+
.await?;
48+
println!(
49+
"\nlistening on {:?}",
50+
endpoint.node_addr().await?.direct_addresses
51+
);
52+
println!("fetching hash {hash} from {:?}", node.node_id);
5853

5954
// connect
60-
let connection = endpoint.connect(addr, "localhost")?.await?;
61-
62-
if format == "collection" {
63-
// create a request for a collection
64-
let request = GetRequest::all(hash);
65-
// create the initial state of the finite state machine
66-
let initial = iroh_blobs::get::fsm::start(connection, request);
67-
68-
write_collection(initial).await
69-
} else {
70-
// create a request for a single blob
71-
let request = GetRequest::single(hash);
72-
// create the initial state of the finite state machine
73-
let initial = iroh_blobs::get::fsm::start(connection, request);
74-
75-
write_blob(initial).await
55+
let connection = endpoint.connect(node, connect::EXAMPLE_ALPN).await?;
56+
57+
match format {
58+
BlobFormat::HashSeq => {
59+
// create a request for a collection
60+
let request = GetRequest::all(hash);
61+
// create the initial state of the finite state machine
62+
let initial = iroh_blobs::get::fsm::start(connection, request);
63+
64+
write_collection(initial).await
65+
}
66+
BlobFormat::Raw => {
67+
// create a request for a single blob
68+
let request = GetRequest::single(hash);
69+
// create the initial state of the finite state machine
70+
let initial = iroh_blobs::get::fsm::start(connection, request);
71+
72+
write_blob(initial).await
73+
}
7674
}
7775
}
7876

examples/fetch-stream.rs

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Since this example does not use [`iroh-net::Endpoint`], it does not do any holepunching, and so will only work locally or between two processes that have public IP addresses.
44
//!
55
//! Run the provide-bytes example first. It will give instructions on how to run this example properly.
6-
use std::{io, net::SocketAddr};
6+
use std::{io, str::FromStr};
77

88
use anyhow::{Context, Result};
99
use bao_tree::io::fsm::BaoContentItem;
@@ -14,13 +14,12 @@ use iroh_blobs::{
1414
get::fsm::{AtInitial, BlobContentNext, ConnectedNext, EndBlobNext},
1515
hashseq::HashSeq,
1616
protocol::GetRequest,
17-
Hash,
17+
BlobFormat,
1818
};
1919
use tokio::io::AsyncWriteExt;
2020
use tracing_subscriber::{prelude::*, EnvFilter};
2121

2222
mod connect;
23-
use connect::{load_certs, make_client_endpoint};
2423

2524
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
2625
pub fn setup_logging() {
@@ -36,51 +35,50 @@ async fn main() -> Result<()> {
3635
println!("\nfetch stream example!");
3736
setup_logging();
3837
let args: Vec<_> = std::env::args().collect();
39-
if args.len() != 4 {
40-
anyhow::bail!("usage: fetch-bytes [HASH] [SOCKET_ADDR] [FORMAT]");
38+
if args.len() != 2 {
39+
anyhow::bail!("usage: fetch-stream [TICKET]");
4140
}
42-
let hash: Hash = args[1].parse().context("unable to parse [HASH]")?;
43-
let addr: SocketAddr = args[2].parse().context("unable to parse [SOCKET_ADDR]")?;
44-
let format = {
45-
if args[3] != "blob" && args[3] != "collection" {
46-
anyhow::bail!(
47-
"expected either 'blob' or 'collection' for FORMAT argument, got {}",
48-
args[3]
49-
);
50-
}
51-
args[3].clone()
52-
};
41+
let ticket =
42+
iroh_blobs::ticket::BlobTicket::from_str(&args[1]).context("unable to parse [TICKET]")?;
5343

54-
// load tls certificates
55-
// This will error if you have not run the `provide-bytes` example
56-
let roots = load_certs().await?;
44+
let (node, hash, format) = ticket.into_parts();
5745

5846
// create an endpoint to listen for incoming connections
59-
let endpoint = make_client_endpoint(roots)?;
60-
println!("\nlistening on {}", endpoint.local_addr()?);
61-
println!("fetching hash {hash} from {addr}");
47+
let endpoint = iroh::Endpoint::builder()
48+
.relay_mode(iroh::RelayMode::Disabled)
49+
.alpns(vec![connect::EXAMPLE_ALPN.into()])
50+
.bind()
51+
.await?;
52+
println!(
53+
"\nlistening on {:?}",
54+
endpoint.node_addr().await?.direct_addresses
55+
);
56+
println!("fetching hash {hash} from {:?}", node.node_id);
6257

6358
// connect
64-
let connection = endpoint.connect(addr, "localhost")?.await?;
59+
let connection = endpoint.connect(node, connect::EXAMPLE_ALPN).await?;
6560

66-
let mut stream = if format == "collection" {
67-
// create a request for a collection
68-
let request = GetRequest::all(hash);
61+
let mut stream = match format {
62+
BlobFormat::HashSeq => {
63+
// create a request for a collection
64+
let request = GetRequest::all(hash);
6965

70-
// create the initial state of the finite state machine
71-
let initial = iroh_blobs::get::fsm::start(connection, request);
66+
// create the initial state of the finite state machine
67+
let initial = iroh_blobs::get::fsm::start(connection, request);
7268

73-
// create a stream that yields all the data of the blob
74-
stream_children(initial).boxed_local()
75-
} else {
76-
// create a request for a single blob
77-
let request = GetRequest::single(hash);
69+
// create a stream that yields all the data of the blob
70+
stream_children(initial).boxed_local()
71+
}
72+
BlobFormat::Raw => {
73+
// create a request for a single blob
74+
let request = GetRequest::single(hash);
7875

79-
// create the initial state of the finite state machine
80-
let initial = iroh_blobs::get::fsm::start(connection, request);
76+
// create the initial state of the finite state machine
77+
let initial = iroh_blobs::get::fsm::start(connection, request);
8178

82-
// create a stream that yields all the data of the blob
83-
stream_blob(initial).boxed_local()
79+
// create a stream that yields all the data of the blob
80+
stream_blob(initial).boxed_local()
81+
}
8482
};
8583
while let Some(item) = stream.next().await {
8684
let item = item?;

examples/provide-bytes.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010
//! cargo run --example provide-bytes collection
1111
//! To provide a collection (multiple blobs)
1212
use anyhow::Result;
13-
use iroh_blobs::{format::collection::Collection, util::local_pool::LocalPool, Hash};
13+
use iroh_blobs::{format::collection::Collection, util::local_pool::LocalPool, BlobFormat, Hash};
1414
use tracing::warn;
1515
use tracing_subscriber::{prelude::*, EnvFilter};
1616

1717
mod connect;
18-
use connect::{make_and_write_certs, make_server_endpoint, CERT_PATH};
1918

2019
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
2120
pub fn setup_logging() {
@@ -45,7 +44,7 @@ async fn main() -> Result<()> {
4544
};
4645
println!("\nprovide bytes {format} example!");
4746

48-
let (db, hash) = if format == "collection" {
47+
let (db, hash, format) = if format == "collection" {
4948
let (mut db, names) = iroh_blobs::store::readonly_mem::Store::new([
5049
("blob1", b"the first blob of bytes".to_vec()),
5150
("blob2", b"the second blob of bytes".to_vec()),
@@ -56,28 +55,31 @@ async fn main() -> Result<()> {
5655
.collect();
5756
// add it to the db
5857
let hash = db.insert_many(collection.to_blobs()).unwrap();
59-
(db, hash)
58+
(db, hash, BlobFormat::HashSeq)
6059
} else {
6160
// create a new database and add a blob
6261
let (db, names) =
6362
iroh_blobs::store::readonly_mem::Store::new([("hello", b"Hello World!".to_vec())]);
6463

6564
// get the hash of the content
6665
let hash = names.get("hello").unwrap();
67-
(db, Hash::from(hash.as_bytes()))
66+
(db, Hash::from(hash.as_bytes()), BlobFormat::Raw)
6867
};
6968

70-
// create tls certs and save to CERT_PATH
71-
let (key, cert) = make_and_write_certs().await?;
72-
7369
// create an endpoint to listen for incoming connections
74-
let endpoint = make_server_endpoint(key, cert)?;
75-
let addr = endpoint.local_addr()?;
76-
println!("\nlistening on {addr}");
70+
let endpoint = iroh::Endpoint::builder()
71+
.relay_mode(iroh::RelayMode::Disabled)
72+
.alpns(vec![connect::EXAMPLE_ALPN.into()])
73+
.bind()
74+
.await?;
75+
let addr = endpoint.node_addr().await?;
76+
println!("\nlistening on {:?}", addr.direct_addresses);
7777
println!("providing hash {hash}");
7878

79-
println!("\nfetch the content using a finite state machine by running the following example:\n\ncargo run --example fetch-fsm {hash} \"{addr}\" {format}");
80-
println!("\nfetch the content using a stream by running the following example:\n\ncargo run --example fetch-stream {hash} \"{addr}\" {format}\n");
79+
let ticket = iroh_blobs::ticket::BlobTicket::new(addr, hash, format)?;
80+
81+
println!("\nfetch the content using a finite state machine by running the following example:\n\ncargo run --example fetch-fsm {ticket}");
82+
println!("\nfetch the content using a stream by running the following example:\n\ncargo run --example fetch-stream {ticket}\n");
8183

8284
// create a new local pool handle with 1 worker thread
8385
let lp = LocalPool::single();
@@ -100,11 +102,10 @@ async fn main() -> Result<()> {
100102

101103
// spawn a task to handle the connection
102104
tokio::spawn(async move {
103-
let remote_addr = conn.remote_address();
104105
let conn = match conn.await {
105106
Ok(conn) => conn,
106107
Err(err) => {
107-
warn!(%remote_addr, "Error connecting: {err:#}");
108+
warn!("Error connecting: {err:#}");
108109
return;
109110
}
110111
};
@@ -115,7 +116,6 @@ async fn main() -> Result<()> {
115116

116117
match tokio::signal::ctrl_c().await {
117118
Ok(()) => {
118-
tokio::fs::remove_dir_all(std::path::PathBuf::from(CERT_PATH)).await?;
119119
accept_task.abort();
120120
Ok(())
121121
}

src/downloader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,7 @@ impl DialerT for Dialer {
15231523
#[derive(Debug)]
15241524
struct Dialer {
15251525
endpoint: Endpoint,
1526-
pending: JoinSet<(NodeId, anyhow::Result<quinn::Connection>)>,
1526+
pending: JoinSet<(NodeId, anyhow::Result<endpoint::Connection>)>,
15271527
pending_dials: HashMap<NodeId, CancellationToken>,
15281528
}
15291529

@@ -1572,7 +1572,7 @@ impl Dialer {
15721572
}
15731573

15741574
impl Stream for Dialer {
1575-
type Item = (NodeId, anyhow::Result<quinn::Connection>);
1575+
type Item = (NodeId, anyhow::Result<endpoint::Connection>);
15761576

15771577
fn poll_next(
15781578
mut self: Pin<&mut Self>,

src/provider.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,8 @@ pub async fn handle_connection<D: Map>(
412412
events: EventSender,
413413
rt: LocalPoolHandle,
414414
) {
415-
let remote_addr = connection.remote_address();
416415
let connection_id = connection.stable_id() as u64;
417-
let span = debug_span!("connection", connection_id, %remote_addr);
416+
let span = debug_span!("connection", connection_id);
418417
async move {
419418
while let Ok((writer, reader)) = connection.accept_bi().await {
420419
// The stream ID index is used to identify this request. Requests only arrive in

0 commit comments

Comments
 (0)