@@ -22,6 +22,7 @@ This crate is used together with [iroh](https://crates.io/crates/iroh). Connecti
2222
2323- ** Requester:** The side that asks for data. It is initiating requests to one or many providers.
2424
25+ A node can be a provider and a requester at the same time.
2526
2627## Getting started
2728
@@ -31,33 +32,33 @@ Iroh provides a [`Router`](https://docs.rs/iroh/latest/iroh/protocol/struct.Rout
3132
3233Here is a basic example of how to set up ` iroh-blobs ` with ` iroh ` :
3334
34- ``` rust
35+ ``` rust,no_run
3536use iroh::{protocol::Router, Endpoint};
36- use iroh_blobs :: {store :: Store , net_protocol :: Blobs };
37+ use iroh_blobs::{store::mem::MemStore, BlobsProtocol };
3738
3839#[tokio::main]
3940async fn main() -> anyhow::Result<()> {
4041 // create an iroh endpoint that includes the standard discovery mechanisms
4142 // we've built at number0
4243 let endpoint = Endpoint::builder().discovery_n0().bind().await?;
4344
44- // create an in-memory blob store
45- // use `iroh_blobs::net_protocol::Blobs::persistent` to load or create a
46- // persistent blob store from a path
47- let blobs = Blobs :: memory (). build (& endpoint );
48-
49- // turn on the "rpc" feature if you need to create blobs and tags clients
50- let blobs_client = blobs . client ();
51- let tags_client = blobs_client . tags ();
45+ // create a protocol handler using an in-memory blob store.
46+ let store = MemStore::new();
47+ let blobs = BlobsProtocol::new(&store, endpoint.clone(), None);
5248
5349 // build the router
5450 let router = Router::builder(endpoint)
5551 .accept(iroh_blobs::ALPN, blobs.clone())
5652 .spawn();
5753
58- // do fun stuff with the blobs protocol!
54+ let tag = blobs.add_slice(b"Hello world").await?;
55+ println!("We are now serving {}", blobs.ticket(tag).await?);
56+
57+ // wait for control-c
58+ tokio::signal::ctrl_c().await;
59+
60+ // clean shutdown of router and store
5961 router.shutdown().await?;
60- drop (tags_client );
6162 Ok(())
6263}
6364```
@@ -81,4 +82,4 @@ at your option.
8182
8283Unless you explicitly state otherwise, any contribution intentionally submitted
8384for inclusion in this project by you, as defined in the Apache-2.0 license,
84- shall be dual licensed as above, without any additional terms or conditions.
85+ shall be dual licensed as above, without any additional terms or conditions.
0 commit comments