Skip to content

Commit 8810d55

Browse files
author
“ramfox”
committed
docs: add INSTALL.md with "getting started" instructions
1 parent 9ae2e52 commit 8810d55

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

INSTALL.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Getting started
2+
3+
The `iroh-blobs` protocol is meant to be use in conjunction with `iroh`. [Iroh](https://docs.rs/iroh/latest/iroh/index.html) is a networking library for making direct connections, these connections are what power the data transfers in `iroh-blobs`.
4+
5+
Iroh provides a [`Router`](https://docs.rs/iroh/latest/iroh/protocol/struct.Router.html) that takes an [`Endpoint`](https://docs.rs/iroh/latest/iroh/endpoint/struct.Endpoint.html) 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`.
6+
7+
Here is a basic example of how to set up `iroh-blobs` with `iroh`:
8+
9+
```rust
10+
use iroh::{protocol::Router, Endpoint};
11+
use iroh_blobs::{net_protocol::Blobs, util::local_pool::LocalPool};
12+
13+
#[tokio::main]
14+
async fn main() -> Result<(), std::fmt::Error> {
15+
// create an iroh endpoint that includes the standard discovery mechanisms
16+
// we've built at number0
17+
let endpoint = Endpoint::builder().discovery_n0().bind().await.unwrap();
18+
19+
// spawn a local pool with one thread per CPU
20+
// for a single threaded pool use `LocalPool::single`
21+
let local_pool = LocalPool::default();
22+
23+
// create an in-memory blob store
24+
// use `iroh_blobs::net_protocol::Blobs::persistent` to load or create a
25+
// persistent blob store from a path
26+
let blobs = Blobs::memory().build(local_pool.handle(), &endpoint);
27+
28+
// turn on the "rpc" feature if you need to create blobs and tags clients
29+
let blobs_client = blobs.clone().client();
30+
let tags_client = blobs_client.tags();
31+
32+
// build the router
33+
let router = Router::builder(endpoint)
34+
.accept(iroh_blobs::ALPN, blobs)
35+
.spawn();
36+
37+
// do fun stuff with the blobs protocol!
38+
// make sure not to drop the local_pool before you are finished
39+
Ok(())
40+
}
41+
```

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
//!
2424
//! [BLAKE3]: https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf
2525
//! [iroh]: https://docs.rs/iroh
26+
#![doc = include_str!("../INSTALL.md")]
2627
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
2728
#![recursion_limit = "256"]
2829
#![cfg_attr(iroh_docsrs, feature(doc_cfg))]

0 commit comments

Comments
 (0)