Skip to content

Commit 532971d

Browse files
authored
Merge pull request #26 from n0-computer/iroh-v0.32.0
chore: upgrade to `iroh` and `iroh-blobs` @ v0.32.0
2 parents 3b6744b + 3a8b6a4 commit 532971d

File tree

16 files changed

+157
-58
lines changed

16 files changed

+157
-58
lines changed

content-discovery/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ missing_debug_implementations = "warn"
2727
unused-async = "warn"
2828

2929
[workspace.dependencies]
30-
iroh = "0.31"
31-
iroh-base = "0.31"
32-
iroh-blobs = { version = "0.31", features = ["rpc"] }
30+
iroh = { version ="0.32", features = ["discovery-pkarr-dht"] }
31+
iroh-base = "0.32"
32+
iroh-blobs = { version = "0.32", features = ["rpc"] }

content-discovery/iroh-mainline-content-discovery-cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async fn announce(args: AnnounceArgs) -> anyhow::Result<()> {
6666
let connection = iroh_endpoint
6767
.connect(tracker, iroh_mainline_content_discovery::protocol::ALPN)
6868
.await?;
69-
iroh_mainline_content_discovery::announce(connection, signed_announce).await?;
69+
iroh_mainline_content_discovery::announce_iroh(connection, signed_announce).await?;
7070
}
7171
}
7272
if !args.quic_tracker.is_empty() {
@@ -82,7 +82,7 @@ async fn announce(args: AnnounceArgs) -> anyhow::Result<()> {
8282
for tracker in args.quic_tracker {
8383
println!("announcing via quic to {:?}: {}", tracker, content);
8484
let connection = quinn_endpoint.connect(tracker, "localhost")?.await?;
85-
iroh_mainline_content_discovery::announce(connection, signed_announce).await?;
85+
iroh_mainline_content_discovery::announce_quinn(connection, signed_announce).await?;
8686
}
8787
}
8888

content-discovery/iroh-mainline-content-discovery/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ hex = "0.4.3"
2222

2323
# Optional features for the client functionality
2424
tracing = { version = "0.1", optional = true }
25-
iroh-quinn = { version = "0.12", optional = true }
25+
iroh-quinn = { version = "0.13", optional = true }
2626
mainline = { version = "2.0.0", optional = true, features = ["async"] }
2727
anyhow = { version = "1", features = ["backtrace"], optional = true }
2828
postcard = { version = "1", default-features = false, features = ["alloc", "use-std"], optional = true }

content-discovery/iroh-mainline-content-discovery/src/client.rs

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,30 @@ use crate::protocol::{
3232
/// `tracker` is the node id of the tracker to announce to. It must understand the [TRACKER_ALPN] protocol.
3333
/// `content` is the content to announce.
3434
/// `kind` is the kind of the announcement. We can claim to have the complete data or only some of it.
35-
pub async fn announce(
35+
pub async fn announce_quinn(
36+
connection: iroh_quinn::Connection,
37+
signed_announce: SignedAnnounce,
38+
) -> anyhow::Result<()> {
39+
let (mut send, mut recv) = connection.open_bi().await?;
40+
tracing::debug!("opened bi stream");
41+
let request = Request::Announce(signed_announce);
42+
let request = postcard::to_stdvec(&request)?;
43+
tracing::debug!("sending announce");
44+
send.write_all(&request).await?;
45+
send.finish()?;
46+
let _response = recv.read_to_end(REQUEST_SIZE_LIMIT).await?;
47+
Ok(())
48+
}
49+
50+
/// Announce to a tracker.
51+
///
52+
/// You can only announce content you yourself claim to have, to avoid spamming other nodes.
53+
///
54+
/// `endpoint` is the iroh endpoint to use for announcing.
55+
/// `tracker` is the node id of the tracker to announce to. It must understand the [TRACKER_ALPN] protocol.
56+
/// `content` is the content to announce.
57+
/// `kind` is the kind of the announcement. We can claim to have the complete data or only some of it.
58+
pub async fn announce_iroh(
3659
connection: iroh::endpoint::Connection,
3760
signed_announce: SignedAnnounce,
3861
) -> anyhow::Result<()> {
@@ -80,7 +103,7 @@ async fn query_socket_one(
80103
args: Query,
81104
) -> anyhow::Result<Vec<SignedAnnounce>> {
82105
let connection = endpoint.connect(addr).await?;
83-
let result = query(connection, args).await?;
106+
let result = query_quinn(connection, args).await?;
84107
Ok(result.hosts)
85108
}
86109

@@ -90,7 +113,7 @@ async fn query_iroh_one(
90113
args: Query,
91114
) -> anyhow::Result<Vec<SignedAnnounce>> {
92115
let connection = endpoint.connect(node_id, ALPN).await?;
93-
let result = query(connection, args).await?;
116+
let result = query_iroh(connection, args).await?;
94117
Ok(result.hosts)
95118
}
96119

@@ -185,9 +208,29 @@ pub fn announce_dht(
185208
}
186209

187210
/// Assume an existing connection to a tracker and query it for peers for some content.
188-
pub async fn query(
211+
pub async fn query_iroh(
189212
connection: iroh::endpoint::Connection,
190213
args: Query,
214+
) -> anyhow::Result<QueryResponse> {
215+
tracing::info!("connected to {:?}", connection.remote_node_id()?);
216+
let (mut send, mut recv) = connection.open_bi().await?;
217+
tracing::info!("opened bi stream");
218+
let request = Request::Query(args);
219+
let request = postcard::to_stdvec(&request)?;
220+
tracing::info!("sending query");
221+
send.write_all(&request).await?;
222+
send.finish()?;
223+
let response = recv.read_to_end(REQUEST_SIZE_LIMIT).await?;
224+
let response = postcard::from_bytes::<Response>(&response)?;
225+
Ok(match response {
226+
Response::QueryResponse(response) => response,
227+
})
228+
}
229+
230+
/// Assume an existing connection to a tracker and query it for peers for some content.
231+
pub async fn query_quinn(
232+
connection: iroh_quinn::Connection,
233+
args: Query,
191234
) -> anyhow::Result<QueryResponse> {
192235
tracing::info!("connected to {:?}", connection.remote_address());
193236
let (mut send, mut recv) = connection.open_bi().await?;
@@ -283,14 +326,23 @@ pub async fn connect(
283326
tracker: &TrackerId,
284327
local_ipv4_addr: SocketAddrV4,
285328
local_ipv6_addr: SocketAddrV6,
286-
) -> anyhow::Result<iroh::endpoint::Connection> {
329+
) -> anyhow::Result<Connection> {
287330
match tracker {
288-
TrackerId::Quinn(tracker) => connect_socket(*tracker, local_ipv4_addr.into()).await,
289-
TrackerId::Iroh(tracker) => connect_iroh(*tracker, local_ipv4_addr, local_ipv6_addr).await,
331+
TrackerId::Quinn(tracker) => Ok(Connection::Quinn(
332+
connect_socket(*tracker, local_ipv4_addr.into()).await?,
333+
)),
334+
TrackerId::Iroh(tracker) => Ok(Connection::Iroh(
335+
connect_iroh(*tracker, local_ipv4_addr, local_ipv6_addr).await?,
336+
)),
290337
TrackerId::Udp(_) => anyhow::bail!("can not connect to udp tracker"),
291338
}
292339
}
293340

341+
pub enum Connection {
342+
Iroh(iroh::endpoint::Connection),
343+
Quinn(iroh_quinn::Connection),
344+
}
345+
294346
/// Create a iroh endpoint and connect to a tracker using the [crate::protocol::ALPN] protocol.
295347
async fn connect_iroh(
296348
tracker: NodeId,
@@ -307,13 +359,13 @@ async fn connect_iroh(
307359
Ok(connection)
308360
}
309361

310-
/// Create a quinn endpoint and connect to a tracker using the [crate::protocol::ALPN] protocol.
362+
/// Create a quinn endpoint and connect to a tracker using the [crate] protocol.
311363
async fn connect_socket(
312364
tracker: SocketAddr,
313365
local_addr: SocketAddr,
314-
) -> anyhow::Result<iroh::endpoint::Connection> {
366+
) -> anyhow::Result<iroh_quinn::Connection> {
315367
let endpoint = create_quinn_client(local_addr, vec![ALPN.to_vec()], false)?;
316-
tracing::info!("trying to connect to tracker at {:?}", tracker);
368+
tracing::info!("trying t?o )connect to tracker at {:?}", tracker);
317369
let connection = endpoint.connect(tracker, "localhost")?.await?;
318370
Ok(connection)
319371
}

content-discovery/iroh-mainline-tracker/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ iroh-blobs = { workspace = true }
2323
mainline = { version = "2.0.0", features = ["async"] }
2424
pkarr = { version = "1.0.1", features = ["async"] }
2525
postcard = { version = "1", default-features = false, features = ["alloc", "use-std"] }
26-
iroh-quinn = "0.12"
26+
iroh-quinn = "0.13"
2727
rand = "0.8"
2828
rcgen = "0.12.0"
2929
redb = "1.5.0"
3030
rustls = "0.21"
31+
rustls-pki-types = "1.11"
3132
serde = { version = "1", features = ["derive"] }
3233
serde_json = "1.0.107"
3334
tempfile = "3.4"

content-discovery/iroh-mainline-tracker/src/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn log_connection_attempt(
9191
path: &Option<PathBuf>,
9292
host: &NodeId,
9393
t0: Instant,
94-
outcome: &anyhow::Result<iroh_quinn::Connection>,
94+
outcome: &anyhow::Result<iroh::endpoint::Connection>,
9595
) -> anyhow::Result<()> {
9696
if let Some(path) = path {
9797
let now = SystemTime::now()

content-discovery/iroh-mainline-tracker/src/iroh_blobs_util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rand::Rng;
1919
/// This is just reading the size header and then immediately closing the connection.
2020
/// It can be used to check if a peer has any data at all.
2121
pub async fn unverified_size(
22-
connection: &iroh_quinn::Connection,
22+
connection: &iroh::endpoint::Connection,
2323
hash: &Hash,
2424
) -> anyhow::Result<(u64, Stats)> {
2525
let request = iroh_blobs::protocol::GetRequest::new(
@@ -42,7 +42,7 @@ pub async fn unverified_size(
4242
/// This asks for the last chunk of the blob and validates the response.
4343
/// Note that this does not validate that the peer has all the data.
4444
pub async fn verified_size(
45-
connection: &iroh_quinn::Connection,
45+
connection: &iroh::endpoint::Connection,
4646
hash: &Hash,
4747
) -> anyhow::Result<(u64, Stats)> {
4848
tracing::debug!("Getting verified size of {}", hash.to_hex());
@@ -81,7 +81,7 @@ pub async fn verified_size(
8181
}
8282

8383
pub async fn get_hash_seq_and_sizes(
84-
connection: &iroh_quinn::Connection,
84+
connection: &iroh::endpoint::Connection,
8585
hash: &Hash,
8686
max_size: u64,
8787
) -> anyhow::Result<(HashSeq, Arc<[u64]>)> {
@@ -135,7 +135,7 @@ pub async fn get_hash_seq_and_sizes(
135135

136136
/// Probe for a single chunk of a blob.
137137
pub async fn chunk_probe(
138-
connection: &iroh_quinn::Connection,
138+
connection: &iroh::endpoint::Connection,
139139
hash: &Hash,
140140
chunk: ChunkNum,
141141
) -> anyhow::Result<Stats> {

content-discovery/iroh-mainline-tracker/src/main.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::{
1010
};
1111

1212
use clap::Parser;
13-
use iroh::{discovery::pkarr::dht::DhtDiscovery, endpoint::get_remote_node_id, Endpoint, NodeId};
13+
use iroh::{discovery::pkarr::dht::DhtDiscovery, Endpoint, NodeId};
1414
use iroh_blobs::util::fs::load_secret_key;
1515
use iroh_mainline_content_discovery::protocol::ALPN;
1616
use iroh_mainline_tracker::{
@@ -24,8 +24,6 @@ use iroh_mainline_tracker::{
2424

2525
use crate::args::Args;
2626

27-
use iroh_mainline_tracker::tracker::get_alpn;
28-
2927
static VERBOSE: AtomicBool = AtomicBool::new(false);
3028

3129
fn set_verbose(verbose: bool) {
@@ -82,11 +80,11 @@ async fn create_endpoint(
8280

8381
/// Accept an incoming connection and extract the client-provided [`NodeId`] and ALPN protocol.
8482
pub async fn accept_conn(
85-
mut conn: iroh_quinn::Connecting,
86-
) -> anyhow::Result<(NodeId, String, iroh_quinn::Connection)> {
87-
let alpn = get_alpn(&mut conn).await?;
83+
mut conn: iroh::endpoint::Connecting,
84+
) -> anyhow::Result<(NodeId, String, iroh::endpoint::Connection)> {
85+
let alpn = String::from_utf8(conn.alpn().await?)?;
8886
let conn = conn.await?;
89-
let peer_id = get_remote_node_id(&conn)?;
87+
let peer_id = conn.remote_node_id()?;
9088
Ok((peer_id, alpn, conn))
9189
}
9290

0 commit comments

Comments
 (0)