Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
796 changes: 236 additions & 560 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ bytes = { version = "1", features = ["serde"] }
derive_more = { version = "2.0.1", features = ["from", "try_from", "into", "debug", "display", "deref", "deref_mut"] }
futures-lite = "2.6.0"
quinn = { package = "iroh-quinn", version = "0.14.0" }
n0-future = "0.2.0"
n0-future = "0.3.0"
n0-snafu = "0.2.2"
range-collections = { version = "0.4.6", features = ["serde"] }
smallvec = { version = "1", features = ["serde", "const_new"] }
Expand All @@ -36,11 +36,12 @@ chrono = "0.4.39"
nested_enum_utils = "0.2.1"
ref-cast = "1.0.24"
arrayvec = "0.7.6"
iroh = "0.93"
iroh = "0.94"
self_cell = "1.1.0"
genawaiter = { version = "0.99.1", features = ["futures03"] }
iroh-base = "0.93"
irpc = { version = "0.9.0", features = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"], default-features = false }
iroh-base = "0.94"
iroh-tickets = "0.1"
irpc = { version = "0.10.0", features = ["rpc", "quinn_endpoint_setup", "spans", "stream", "derive"], default-features = false }
iroh-metrics = { version = "0.36" }
redb = { version = "2.6.3", optional = true }
reflink-copy = { version = "0.1.24", optional = true }
Expand All @@ -59,7 +60,7 @@ tracing-subscriber = { version = "0.3.20", features = ["fmt"] }
tracing-test = "0.2.5"
walkdir = "2.5.0"
atomic_refcell = "0.1.13"
iroh = { version = "0.93", features = ["discovery-local-network"]}
iroh = { version = "0.94", features = ["discovery-local-network"]}
async-compression = { version = "0.4.30", features = ["lz4", "tokio"] }
concat_const = "0.2.0"

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ use iroh_blobs::{store::mem::MemStore, BlobsProtocol, ticket::BlobTicket};
async fn main() -> anyhow::Result<()> {
// create an iroh endpoint that includes the standard discovery mechanisms
// we've built at number0
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
let endpoint = Endpoint::bind().await?;

// create a protocol handler using an in-memory blob store.
let store = MemStore::new();
let tag = store.add_slice(b"Hello world").await?;

let _ = endpoint.online().await;
let addr = endpoint.node_addr();
let addr = endpoint.addr();
let ticket = BlobTicket::new(addr, tag.hash, tag.format);

// build the router
Expand Down
14 changes: 5 additions & 9 deletions examples/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::common::get_or_generate_secret_key;
#[derive(Debug, Parser)]
#[command(version, about)]
pub enum Args {
/// Limit requests by node id
/// Limit requests by endpoint id
Provide {
/// Path for files to add.
path: PathBuf,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl<C: Compression> ProtocolHandler for CompressedBlobsProtocol<C> {
.events
.client_connected(|| ClientConnected {
connection_id,
node_id: connection.remote_node_id().ok(),
endpoint_id: connection.remote_id().ok(),
})
.await
{
Expand All @@ -184,11 +184,7 @@ async fn main() -> Result<()> {
setup_logging();
let args = Args::parse();
let secret = get_or_generate_secret_key()?;
let endpoint = iroh::Endpoint::builder()
.secret_key(secret)
.discovery_n0()
.bind()
.await?;
let endpoint = iroh::Endpoint::builder().secret_key(secret).bind().await?;
let compression = lz4::Compression;
match args {
Args::Provide { path } => {
Expand All @@ -198,7 +194,7 @@ async fn main() -> Result<()> {
let router = iroh::protocol::Router::builder(endpoint.clone())
.accept(lz4::Compression::ALPN, blobs)
.spawn();
let ticket = BlobTicket::new(endpoint.node_id().into(), tag.hash, tag.format);
let ticket = BlobTicket::new(endpoint.id().into(), tag.hash, tag.format);
println!("Serving blob with hash {}", tag.hash);
println!("Ticket: {ticket}");
println!("Node is running. Press Ctrl-C to exit.");
Expand All @@ -209,7 +205,7 @@ async fn main() -> Result<()> {
Args::Get { ticket, target } => {
let store = MemStore::new();
let conn = endpoint
.connect(ticket.node_addr().clone(), lz4::Compression::ALPN)
.connect(ticket.addr().clone(), lz4::Compression::ALPN)
.await?;
let connection_id = conn.stable_id() as u64;
let (send, recv) = conn.open_bi().await?;
Expand Down
50 changes: 23 additions & 27 deletions examples/custom-protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
//!
//! cargo run --example custom-protocol -- listen "hello-world" "foo-bar" "hello-moon"
//!
//! This spawns an iroh nodes with three blobs. It will print the node's node id.
//! This spawns an iroh node with three blobs. It will print the node's endpoint id.
//!
//! In another terminal, run
//!
//! cargo run --example custom-protocol -- query <node-id> hello
//! cargo run --example custom-protocol -- query <endpoint-id> hello
//!
//! Replace <node-id> with the node id from above. This will connect to the listening node with our
//! Replace <endpoint-id> with the endpoint id from above. This will connect to the listening node with our
//! custom protocol and query for the string `hello`. The listening node will return a list of
//! blob hashes that contain `hello`. We will then download all these blobs with iroh-blobs,
//! and then print a list of the hashes with their content.
Expand All @@ -46,7 +46,7 @@ use iroh::{
discovery::pkarr::PkarrResolver,
endpoint::Connection,
protocol::{AcceptError, ProtocolHandler, Router},
Endpoint, NodeId,
Endpoint, EndpointId,
};
use iroh_blobs::{api::Store, store::mem::MemStore, BlobsProtocol, Hash};
mod common;
Expand All @@ -67,8 +67,8 @@ pub enum Command {
},
/// Query a remote node for data and print the results.
Query {
/// The node id of the node we want to query.
node_id: NodeId,
/// The endpoint id of the node we want to query.
endpoint_id: EndpointId,
/// The text we want to match.
query: String,
},
Expand All @@ -81,17 +81,13 @@ pub enum Command {
const ALPN: &[u8] = b"iroh-example/text-search/0";

async fn listen(text: Vec<String>) -> Result<()> {
// allow the user to provide a secret so we can have a stable node id.
// allow the user to provide a secret so we can have a stable endpoint id.
// This is only needed for the listen side.
let secret_key = get_or_generate_secret_key()?;
// Use an in-memory store for this example. You would use a persistent store in production code.
let store = MemStore::new();
// Create an endpoint with the secret key and discovery publishing to the n0 dns server enabled.
let endpoint = Endpoint::builder()
.secret_key(secret_key)
.discovery_n0()
.bind()
.await?;
let endpoint = Endpoint::builder().secret_key(secret_key).bind().await?;
// Build our custom protocol handler. The `builder` exposes access to various subsystems in the
// iroh node. In our case, we need a blobs client and the endpoint.
let proto = BlobSearch::new(&store);
Expand All @@ -108,30 +104,30 @@ async fn listen(text: Vec<String>) -> Result<()> {
.accept(iroh_blobs::ALPN, blobs.clone())
.spawn();

// Print our node id, so clients know how to connect to us.
let node_id = node.endpoint().node_id();
println!("our node id: {node_id}");
// Print our endpoint id, so clients know how to connect to us.
let node_id = node.endpoint().id();
println!("our endpoint id: {node_id}");

// Wait for Ctrl-C to be pressed.
tokio::signal::ctrl_c().await?;
node.shutdown().await?;
Ok(())
}

async fn query(node_id: NodeId, query: String) -> Result<()> {
async fn query(endpoint_id: EndpointId, query: String) -> Result<()> {
// Build a in-memory node. For production code, you'd want a persistent node instead usually.
let store = MemStore::new();
// Create an endpoint with a random secret key and no discovery publishing.
// For a client we just need discovery resolution via the n0 dns server, which
// the PkarrResolver provides.
let endpoint = Endpoint::builder()
.add_discovery(PkarrResolver::n0_dns())
let endpoint = Endpoint::empty_builder(iroh::RelayMode::Default)
.discovery(PkarrResolver::n0_dns())
.bind()
.await?;
// Query the remote node.
// This will send the query over our custom protocol, read hashes on the reply stream,
// and download each hash over iroh-blobs.
let hashes = query_remote(&endpoint, &store, node_id, &query).await?;
let hashes = query_remote(&endpoint, &store, endpoint_id, &query).await?;

// Print out our query results.
for hash in hashes {
Expand All @@ -157,10 +153,10 @@ async fn main() -> Result<()> {
listen(text).await?;
}
Command::Query {
node_id,
endpoint_id,
query: query_text,
} => {
query(node_id, query_text).await?;
query(endpoint_id, query_text).await?;
}
}

Expand All @@ -180,8 +176,8 @@ impl ProtocolHandler for BlobSearch {
/// the connection lasts.
async fn accept(&self, connection: Connection) -> std::result::Result<(), AcceptError> {
let this = self.clone();
// We can get the remote's node id from the connection.
let node_id = connection.remote_node_id()?;
// We can get the remote's endpoint id from the connection.
let node_id = connection.remote_id()?;
println!("accepted connection from {node_id}");

// Our protocol is a simple request-response protocol, so we expect the
Expand Down Expand Up @@ -269,14 +265,14 @@ impl BlobSearch {
pub async fn query_remote(
endpoint: &Endpoint,
store: &Store,
node_id: NodeId,
endpoint_id: EndpointId,
query: &str,
) -> Result<Vec<Hash>> {
// Establish a connection to our node.
// We use the default node discovery in iroh, so we can connect by node id without
// We use the default node discovery in iroh, so we can connect by endpoint id without
// providing further information.
let conn = endpoint.connect(node_id, ALPN).await?;
let blobs_conn = endpoint.connect(node_id, iroh_blobs::ALPN).await?;
let conn = endpoint.connect(endpoint_id, ALPN).await?;
let blobs_conn = endpoint.connect(endpoint_id, iroh_blobs::ALPN).await?;

// Open a bi-directional in our connection.
let (mut send, mut recv) = conn.open_bi().await?;
Expand Down
6 changes: 2 additions & 4 deletions examples/get-blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ async fn main() -> anyhow::Result<()> {
setup_logging();
let cli = Cli::parse();
let ticket = cli.ticket;
let endpoint = iroh::Endpoint::builder()
let endpoint = iroh::Endpoint::empty_builder(iroh::RelayMode::Default)
.discovery(PkarrResolver::n0_dns())
.bind()
.await?;
anyhow::ensure!(
ticket.format() == BlobFormat::Raw,
"This example only supports raw blobs."
);
let connection = endpoint
.connect(ticket.node_addr().node_id, iroh_blobs::ALPN)
.await?;
let connection = endpoint.connect(ticket.addr().id, iroh_blobs::ALPN).await?;
let mut progress = iroh_blobs::get::request::get_blob(connection, ticket.hash());
let stats = if cli.progress {
loop {
Expand Down
Loading
Loading