Skip to content

Commit d6a32f4

Browse files
authored
refactor(iroh)!: Move blobs and tags rpc client and server to iroh-blobs (#2874)
## Description Move blobs and tags rpc client and server to iroh-blobs. Depends on n0-computer/iroh-blobs#7 Todo: - [x] merge n0-computer/iroh-blobs#7 ## Breaking Changes - Lots of types in client::blobs and client::tags become reexports - blob share goes away, since it requires the node client ## Notes & open questions I want to keep the client::blobs and client::tags modules self-contained, so the idea is that these will reexport all the things from iroh-blobs::rpc::client that a user will need (except I have probably forgotten something). Maybe I should use wildcard exports here even though people dislike them... ? ~~The client::blobs::Client itself is *not* a reexport but a newtype to hide the ugly type parameters. Same for client::tags::Client.~~ With the changes in quic-rpc, these are now just module reexports! The Blobs protocol handler now takes an Endpoint, since that was needed to implement one of the functions. <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented.
1 parent 911d7a6 commit d6a32f4

24 files changed

+105
-3647
lines changed

Cargo.lock

Lines changed: 20 additions & 13 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ iroh-metrics = { path = "./iroh-metrics" }
5454
iroh-test = { path = "./iroh-test" }
5555
iroh-router = { path = "./iroh-router" }
5656

57-
iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }
5857
iroh-gossip = { git = "https://github.com/n0-computer/iroh-gossip", branch = "main" }
5958
iroh-docs = { git = "https://github.com/n0-computer/iroh-docs", branch = "main" }
59+
iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }

iroh-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pkarr = { version = "2.2.0", default-features = false }
4848
portable-atomic = "1"
4949
portmapper = { version = "0.1.0", path = "../net-tools/portmapper" }
5050
postcard = "1.0.8"
51-
quic-rpc = { version = "0.14", features = ["flume-transport", "quinn-transport"] }
51+
quic-rpc = { version = "0.15", features = ["flume-transport", "quinn-transport"] }
5252
rand = "0.8.5"
5353
ratatui = "0.26.2"
5454
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }

iroh-cli/src/commands/blobs.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use iroh::{
1919
base::{node_addr::AddrInfoOptions, ticket::BlobTicket},
2020
blobs::{
2121
get::{db::DownloadProgress, progress::BlobProgress, Stats},
22+
net_protocol::DownloadMode,
2223
provider::AddProgress,
2324
store::{
2425
ConsistencyCheckProgress, ExportFormat, ExportMode, ReportLevel, ValidateProgress,
@@ -28,8 +29,7 @@ use iroh::{
2829
},
2930
client::{
3031
blobs::{
31-
BlobInfo, BlobStatus, CollectionInfo, DownloadMode, DownloadOptions,
32-
IncompleteBlobInfo, WrapOption,
32+
BlobInfo, BlobStatus, CollectionInfo, DownloadOptions, IncompleteBlobInfo, WrapOption,
3333
},
3434
Iroh,
3535
},
@@ -370,7 +370,9 @@ impl BlobCommands {
370370
BlobFormat::Raw
371371
};
372372
let status = iroh.blobs().status(hash).await?;
373-
let ticket = iroh.blobs().share(hash, format, addr_options).await?;
373+
let mut addr: NodeAddr = iroh.net().node_addr().await?;
374+
addr.apply_options(addr_options);
375+
let ticket = BlobTicket::new(addr, hash, format)?;
374376

375377
let (blob_status, size) = match (status, format) {
376378
(BlobStatus::Complete { size }, BlobFormat::Raw) => ("blob", size),

iroh-net/src/relay/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ fn host_header_value(relay_url: RelayUrl) -> Result<String, ClientError> {
10291029
.host_str()
10301030
.ok_or_else(|| ClientError::InvalidUrl(relay_url.to_string()))?;
10311031
// strip the trailing dot, if present: example.com. -> example.com
1032-
let relay_url_host = relay_url_host.strip_suffix(".").unwrap_or(relay_url_host);
1032+
let relay_url_host = relay_url_host.strip_suffix('.').unwrap_or(relay_url_host);
10331033
// build the host header value (reserve up to 6 chars for the ":" and port digits):
10341034
let mut host_header_value = String::with_capacity(relay_url_host.len() + 6);
10351035
host_header_value += relay_url_host;

iroh/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ iroh-docs = { version = "0.28.0" }
3939
iroh-gossip = "0.28.1"
4040
parking_lot = "0.12.1"
4141
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
42-
quic-rpc = { version = "0.14", default-features = false, features = ["flume-transport", "quinn-transport"] }
43-
quic-rpc-derive = { version = "0.14" }
42+
quic-rpc = { version = "0.15", default-features = false, features = ["flume-transport", "quinn-transport"] }
43+
quic-rpc-derive = { version = "0.15" }
4444
quinn = { package = "iroh-quinn", version = "0.12" }
4545
rand = "0.8"
4646
serde = { version = "1", features = ["derive"] }
@@ -51,7 +51,6 @@ tokio = { version = "1", features = ["io-util", "rt"] }
5151
tokio-stream = "0.1"
5252
tokio-util = { version = "0.7", features = ["codec", "io-util", "io", "time"] }
5353
tracing = "0.1"
54-
walkdir = "2"
5554

5655
# Examples
5756
clap = { version = "4", features = ["derive"], optional = true }

iroh/examples/collection-provide.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! run this example from the project root:
88
//! $ cargo run --example collection-provide
99
use iroh::blobs::{format::collection::Collection, util::SetTagOption, BlobFormat};
10-
use iroh_base::node_addr::AddrInfoOptions;
10+
use iroh_base::{node_addr::AddrInfoOptions, ticket::BlobTicket};
1111
use tracing_subscriber::{prelude::*, EnvFilter};
1212

1313
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
@@ -44,14 +44,9 @@ async fn main() -> anyhow::Result<()> {
4444

4545
// create a ticket
4646
// tickets wrap all details needed to get a collection
47-
let ticket = node
48-
.blobs()
49-
.share(
50-
hash,
51-
BlobFormat::HashSeq,
52-
AddrInfoOptions::RelayAndAddresses,
53-
)
54-
.await?;
47+
let mut addr = node.net().node_addr().await?;
48+
addr.apply_options(AddrInfoOptions::RelayAndAddresses);
49+
let ticket = BlobTicket::new(addr, hash, BlobFormat::HashSeq)?;
5550

5651
// print some info about the node
5752
println!("serving hash: {}", ticket.hash());

iroh/examples/custom-protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ async fn main() -> Result<()> {
118118

119119
// Print out our query results.
120120
for hash in hashes {
121-
read_and_print(node.blobs(), hash).await?;
121+
read_and_print(&node.blobs(), hash).await?;
122122
}
123123
}
124124
}

iroh/examples/hello-world-provide.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This is using an in memory database and a random node id.
44
//! run this example from the project root:
55
//! $ cargo run --example hello-world-provide
6-
use iroh_base::node_addr::AddrInfoOptions;
6+
use iroh_base::{node_addr::AddrInfoOptions, ticket::BlobTicket};
77
use tracing_subscriber::{prelude::*, EnvFilter};
88

99
// set the RUST_LOG env var to one of {debug,info,warn} to see logging info
@@ -27,10 +27,9 @@ async fn main() -> anyhow::Result<()> {
2727
let res = node.blobs().add_bytes("Hello, world!").await?;
2828

2929
// create a ticket
30-
let ticket = node
31-
.blobs()
32-
.share(res.hash, res.format, AddrInfoOptions::RelayAndAddresses)
33-
.await?;
30+
let mut addr = node.net().node_addr().await?;
31+
addr.apply_options(AddrInfoOptions::RelayAndAddresses);
32+
let ticket = BlobTicket::new(addr, res.hash, res.format)?;
3433

3534
// print some info about the node
3635
println!("serving hash: {}", ticket.hash());

iroh/src/client.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::collections::BTreeMap;
66

77
use anyhow::Result;
88
use futures_lite::{Stream, StreamExt};
9-
use quic_rpc::client::BoxedServiceConnection;
109
use ref_cast::RefCast;
1110

1211
use crate::rpc_protocol::node::{CounterStats, ShutdownRequest, StatsRequest, StatusRequest};
@@ -19,13 +18,10 @@ pub(crate) use self::quic::{connect_raw as quic_connect_raw, RPC_ALPN};
1918
pub use self::{docs::Doc, net::NodeStatus};
2019

2120
pub mod authors;
22-
pub mod blobs;
21+
pub use iroh_blobs::rpc::client::{blobs, tags};
22+
pub use iroh_gossip::rpc::client as gossip;
2323
pub mod docs;
2424
pub mod net;
25-
pub mod tags;
26-
27-
/// Iroh rpc connection - boxed so that we can have a concrete type.
28-
pub(crate) type RpcConnection = BoxedServiceConnection<RpcService>;
2925

3026
// Keep this type exposed, otherwise every occurrence of `RpcClient` in the API
3127
// will show up as `RpcClient<RpcService, Connection<RpcService>>` in the docs.
@@ -60,8 +56,8 @@ impl Iroh {
6056
}
6157

6258
/// Returns the blobs client.
63-
pub fn blobs(&self) -> &blobs::Client {
64-
blobs::Client::ref_cast(&self.rpc)
59+
pub fn blobs(&self) -> blobs::Client {
60+
blobs::Client::new(self.rpc.clone().map().boxed())
6561
}
6662

6763
/// Returns the docs client.
@@ -75,14 +71,13 @@ impl Iroh {
7571
}
7672

7773
/// Returns the tags client.
78-
pub fn tags(&self) -> &tags::Client {
79-
tags::Client::ref_cast(&self.rpc)
74+
pub fn tags(&self) -> tags::Client {
75+
tags::Client::new(self.rpc.clone().map().boxed())
8076
}
8177

8278
/// Returns the gossip client.
83-
pub fn gossip(&self) -> iroh_gossip::RpcClient<RpcService> {
84-
let channel = self.rpc.clone().map::<iroh_gossip::RpcService>();
85-
iroh_gossip::RpcClient::new(channel)
79+
pub fn gossip(&self) -> gossip::Client {
80+
gossip::Client::new(self.rpc.clone().map().boxed())
8681
}
8782

8883
/// Returns the net client.

0 commit comments

Comments
 (0)