Skip to content

Commit

Permalink
refactor(iroh)!: Move blobs and tags rpc client and server to iroh-bl…
Browse files Browse the repository at this point in the history
…obs (#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.
  • Loading branch information
rklaehn authored Nov 6, 2024
1 parent 911d7a6 commit d6a32f4
Show file tree
Hide file tree
Showing 24 changed files with 105 additions and 3,647 deletions.
33 changes: 20 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ iroh-metrics = { path = "./iroh-metrics" }
iroh-test = { path = "./iroh-test" }
iroh-router = { path = "./iroh-router" }

iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }
iroh-gossip = { git = "https://github.com/n0-computer/iroh-gossip", branch = "main" }
iroh-docs = { git = "https://github.com/n0-computer/iroh-docs", branch = "main" }
iroh-blobs = { git = "https://github.com/n0-computer/iroh-blobs", branch = "main" }
2 changes: 1 addition & 1 deletion iroh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pkarr = { version = "2.2.0", default-features = false }
portable-atomic = "1"
portmapper = { version = "0.1.0", path = "../net-tools/portmapper" }
postcard = "1.0.8"
quic-rpc = { version = "0.14", features = ["flume-transport", "quinn-transport"] }
quic-rpc = { version = "0.15", features = ["flume-transport", "quinn-transport"] }
rand = "0.8.5"
ratatui = "0.26.2"
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
Expand Down
8 changes: 5 additions & 3 deletions iroh-cli/src/commands/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use iroh::{
base::{node_addr::AddrInfoOptions, ticket::BlobTicket},
blobs::{
get::{db::DownloadProgress, progress::BlobProgress, Stats},
net_protocol::DownloadMode,
provider::AddProgress,
store::{
ConsistencyCheckProgress, ExportFormat, ExportMode, ReportLevel, ValidateProgress,
Expand All @@ -28,8 +29,7 @@ use iroh::{
},
client::{
blobs::{
BlobInfo, BlobStatus, CollectionInfo, DownloadMode, DownloadOptions,
IncompleteBlobInfo, WrapOption,
BlobInfo, BlobStatus, CollectionInfo, DownloadOptions, IncompleteBlobInfo, WrapOption,
},
Iroh,
},
Expand Down Expand Up @@ -370,7 +370,9 @@ impl BlobCommands {
BlobFormat::Raw
};
let status = iroh.blobs().status(hash).await?;
let ticket = iroh.blobs().share(hash, format, addr_options).await?;
let mut addr: NodeAddr = iroh.net().node_addr().await?;
addr.apply_options(addr_options);
let ticket = BlobTicket::new(addr, hash, format)?;

let (blob_status, size) = match (status, format) {
(BlobStatus::Complete { size }, BlobFormat::Raw) => ("blob", size),
Expand Down
2 changes: 1 addition & 1 deletion iroh-net/src/relay/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ fn host_header_value(relay_url: RelayUrl) -> Result<String, ClientError> {
.host_str()
.ok_or_else(|| ClientError::InvalidUrl(relay_url.to_string()))?;
// strip the trailing dot, if present: example.com. -> example.com
let relay_url_host = relay_url_host.strip_suffix(".").unwrap_or(relay_url_host);
let relay_url_host = relay_url_host.strip_suffix('.').unwrap_or(relay_url_host);
// build the host header value (reserve up to 6 chars for the ":" and port digits):
let mut host_header_value = String::with_capacity(relay_url_host.len() + 6);
host_header_value += relay_url_host;
Expand Down
5 changes: 2 additions & 3 deletions iroh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ iroh-docs = { version = "0.28.0" }
iroh-gossip = "0.28.1"
parking_lot = "0.12.1"
postcard = { version = "1", default-features = false, features = ["alloc", "use-std", "experimental-derive"] }
quic-rpc = { version = "0.14", default-features = false, features = ["flume-transport", "quinn-transport"] }
quic-rpc-derive = { version = "0.14" }
quic-rpc = { version = "0.15", default-features = false, features = ["flume-transport", "quinn-transport"] }
quic-rpc-derive = { version = "0.15" }
quinn = { package = "iroh-quinn", version = "0.12" }
rand = "0.8"
serde = { version = "1", features = ["derive"] }
Expand All @@ -51,7 +51,6 @@ tokio = { version = "1", features = ["io-util", "rt"] }
tokio-stream = "0.1"
tokio-util = { version = "0.7", features = ["codec", "io-util", "io", "time"] }
tracing = "0.1"
walkdir = "2"

# Examples
clap = { version = "4", features = ["derive"], optional = true }
Expand Down
13 changes: 4 additions & 9 deletions iroh/examples/collection-provide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! run this example from the project root:
//! $ cargo run --example collection-provide
use iroh::blobs::{format::collection::Collection, util::SetTagOption, BlobFormat};
use iroh_base::node_addr::AddrInfoOptions;
use iroh_base::{node_addr::AddrInfoOptions, ticket::BlobTicket};
use tracing_subscriber::{prelude::*, EnvFilter};

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

// create a ticket
// tickets wrap all details needed to get a collection
let ticket = node
.blobs()
.share(
hash,
BlobFormat::HashSeq,
AddrInfoOptions::RelayAndAddresses,
)
.await?;
let mut addr = node.net().node_addr().await?;
addr.apply_options(AddrInfoOptions::RelayAndAddresses);
let ticket = BlobTicket::new(addr, hash, BlobFormat::HashSeq)?;

// print some info about the node
println!("serving hash: {}", ticket.hash());
Expand Down
2 changes: 1 addition & 1 deletion iroh/examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ async fn main() -> Result<()> {

// Print out our query results.
for hash in hashes {
read_and_print(node.blobs(), hash).await?;
read_and_print(&node.blobs(), hash).await?;
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions iroh/examples/hello-world-provide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This is using an in memory database and a random node id.
//! run this example from the project root:
//! $ cargo run --example hello-world-provide
use iroh_base::node_addr::AddrInfoOptions;
use iroh_base::{node_addr::AddrInfoOptions, ticket::BlobTicket};
use tracing_subscriber::{prelude::*, EnvFilter};

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

// create a ticket
let ticket = node
.blobs()
.share(res.hash, res.format, AddrInfoOptions::RelayAndAddresses)
.await?;
let mut addr = node.net().node_addr().await?;
addr.apply_options(AddrInfoOptions::RelayAndAddresses);
let ticket = BlobTicket::new(addr, res.hash, res.format)?;

// print some info about the node
println!("serving hash: {}", ticket.hash());
Expand Down
21 changes: 8 additions & 13 deletions iroh/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::collections::BTreeMap;

use anyhow::Result;
use futures_lite::{Stream, StreamExt};
use quic_rpc::client::BoxedServiceConnection;
use ref_cast::RefCast;

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

pub mod authors;
pub mod blobs;
pub use iroh_blobs::rpc::client::{blobs, tags};
pub use iroh_gossip::rpc::client as gossip;
pub mod docs;
pub mod net;
pub mod tags;

/// Iroh rpc connection - boxed so that we can have a concrete type.
pub(crate) type RpcConnection = BoxedServiceConnection<RpcService>;

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

/// Returns the blobs client.
pub fn blobs(&self) -> &blobs::Client {
blobs::Client::ref_cast(&self.rpc)
pub fn blobs(&self) -> blobs::Client {
blobs::Client::new(self.rpc.clone().map().boxed())
}

/// Returns the docs client.
Expand All @@ -75,14 +71,13 @@ impl Iroh {
}

/// Returns the tags client.
pub fn tags(&self) -> &tags::Client {
tags::Client::ref_cast(&self.rpc)
pub fn tags(&self) -> tags::Client {
tags::Client::new(self.rpc.clone().map().boxed())
}

/// Returns the gossip client.
pub fn gossip(&self) -> iroh_gossip::RpcClient<RpcService> {
let channel = self.rpc.clone().map::<iroh_gossip::RpcService>();
iroh_gossip::RpcClient::new(channel)
pub fn gossip(&self) -> gossip::Client {
gossip::Client::new(self.rpc.clone().map().boxed())
}

/// Returns the net client.
Expand Down
Loading

0 comments on commit d6a32f4

Please sign in to comment.