Expand description
§iroh-blobs
NOTE: this version of iroh-blobs is not yet considered production quality. For now, if you need production quality, use iroh-blobs 0.35
This crate provides blob and blob sequence transfer support for iroh. It implements a simple request-response protocol based on BLAKE3 verified streaming.
A request describes data in terms of BLAKE3 hashes and byte ranges. It is possible to request blobs or ranges of blobs, as well as entire sequences of blobs in one request.
The requester opens a QUIC stream to the provider and sends the request. The provider answers with the requested data, encoded as BLAKE3 verified streams, on the same QUIC stream.
This crate is used together with iroh. Connection establishment is left up to the user or higher level APIs.
§Concepts
-
Blob: a sequence of bytes of arbitrary size, without any metadata.
-
Link: a 32 byte BLAKE3 hash of a blob.
-
HashSeq: a blob that contains a sequence of links. Its size is a multiple of 32.
-
Provider: The side that provides data and answers requests. Providers wait for incoming requests from Requests.
-
Requester: The side that asks for data. It is initiating requests to one or many providers.
A node can be a provider and a requester at the same time.
§Getting started
The iroh-blobs
protocol was designed to be used in conjunction with iroh
. Iroh is a networking library for making direct connections, these connections are what power the data transfers in iroh-blobs
.
Iroh provides a Router
that takes an Endpoint
and any protocols needed for the application. Similar to a router in webserver library, it runs a loop accepting incoming connections and routes them to the specific protocol handler, based on ALPN
.
Here is a basic example of how to set up iroh-blobs
with iroh
:
use iroh::{protocol::Router, Endpoint};
use iroh_blobs::{store::mem::MemStore, BlobsProtocol};
#[tokio::main]
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?;
// create a protocol handler using an in-memory blob store.
let store = MemStore::new();
let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
// build the router
let router = Router::builder(endpoint)
.accept(iroh_blobs::ALPN, blobs.clone())
.spawn();
let tag = blobs.add_slice(b"Hello world").await?;
println!("We are now serving {}", blobs.ticket(tag).await?);
// wait for control-c
tokio::signal::ctrl_c().await;
// clean shutdown of router and store
router.shutdown().await?;
Ok(())
}
§Examples
Examples that use iroh-blobs
can be found in this repo.
§License
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
§Module docs
The crate is designed to be used from the iroh crate.
It implements a protocol for streaming content-addressed data transfer using BLAKE3 verified streaming.
It also provides a store module for storage of blobs and outboards, as well as a persistent and a memory store implementation.
To implement a server, the provider module provides helpers for handling connections and individual requests given a store.
To perform get requests, the get module provides utilities to perform requests and store the result in a store, as well as a low level state machine for executing requests.
The client API is available in the api module. You can get a client either from one of the store implementations, or from the BlobsProtocol via a
The downloader module provides a component to download blobs from multiple sources and store them in a store.
Re-exports§
pub use protocol::ALPN;
Modules§
- The user facing API of the store.
- Defines data formats for HashSeq.
- The low level client side API
- Helpers for blobs that contain a sequence of hashes.
- Protocol for transferring content-addressed blobs over [
iroh
] p2p QUIC connections. - The low level server side API
- Store implementations
- Tickets for blobs.
Structs§
- A protocol handler for the blobs protocol.
- Hash type used throughout.
- A hash and format pair
Enums§
- A format identifier