Skip to content

Commit 7643ec9

Browse files
author
“ramfox”
committed
remove INSTALL.md, move content to README.md
1 parent 8810d55 commit 7643ec9

File tree

3 files changed

+45
-43
lines changed

3 files changed

+45
-43
lines changed

INSTALL.md

Lines changed: 0 additions & 41 deletions
This file was deleted.

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ request blobs or ranges of blobs, as well as collections.
77

88
The requester opens a quic stream to the provider and sends the request. The provider answers with the requested data, encoded as [blake3](https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf) verified streams, on the same quic stream.
99

10-
This crate is usually used together with [iroh-net](https://crates.io/crates/iroh-net), but can also be used with normal [quinn](https://crates.io/crates/quinn) connections. Connection establishment is left up to the user or a higher level APIs such as the iroh CLI.
10+
This crate is usually used together with [iroh](https://crates.io/crates/iroh), but can also be used with normal [quinn](https://crates.io/crates/quinn) connections. Connection establishment is left up to the user or a higher level APIs such as the iroh CLI.
1111

1212
## Concepts
1313

@@ -21,6 +21,49 @@ This crate is usually used together with [iroh-net](https://crates.io/crates/iro
2121

2222
- **Requester:** The side that asks for data. It is initiating requests to one or many providers.
2323

24+
25+
## Getting started
26+
27+
The `iroh-blobs` protocol was designed to be used in conjunction with `iroh`. [Iroh](https://docs.rs/iroh) is a networking library for making direct connections, these connections are what power the data transfers in `iroh-blobs`.
28+
29+
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`.
30+
31+
Here is a basic example of how to set up `iroh-blobs` with `iroh`:
32+
33+
```rust
34+
use iroh::{protocol::Router, Endpoint};
35+
use iroh_blobs::{net_protocol::Blobs, util::local_pool::LocalPool};
36+
37+
#[tokio::main]
38+
async fn main() -> Result<(), std::fmt::Error> {
39+
// create an iroh endpoint that includes the standard discovery mechanisms
40+
// we've built at number0
41+
let endpoint = Endpoint::builder().discovery_n0().bind().await.unwrap();
42+
43+
// spawn a local pool with one thread per CPU
44+
// for a single threaded pool use `LocalPool::single`
45+
let local_pool = LocalPool::default();
46+
47+
// create an in-memory blob store
48+
// use `iroh_blobs::net_protocol::Blobs::persistent` to load or create a
49+
// persistent blob store from a path
50+
let blobs = Blobs::memory().build(local_pool.handle(), &endpoint);
51+
52+
// turn on the "rpc" feature if you need to create blobs and tags clients
53+
let blobs_client = blobs.client();
54+
let tags_client = blobs_client.tags();
55+
56+
// build the router
57+
let router = Router::builder(endpoint)
58+
.accept(iroh_blobs::ALPN, blobs.clone())
59+
.spawn();
60+
61+
// do fun stuff with the blobs protocol!
62+
// make sure not to drop the local_pool before you are finished
63+
Ok(())
64+
}
65+
```
66+
2467
## Examples
2568

2669
Examples that use `iroh-blobs` can be found in the `iroh` crate. the iroh crate publishes `iroh_blobs` as `iroh::bytes`.

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![doc = include_str!("../README.md")]
12
//! Blobs layer for iroh.
23
//!
34
//! The crate is designed to be used from the [iroh] crate, which provides a
@@ -23,7 +24,6 @@
2324
//!
2425
//! [BLAKE3]: https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf
2526
//! [iroh]: https://docs.rs/iroh
26-
#![doc = include_str!("../INSTALL.md")]
2727
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
2828
#![recursion_limit = "256"]
2929
#![cfg_attr(iroh_docsrs, feature(doc_cfg))]

0 commit comments

Comments
 (0)