Skip to content

Commit 217ac06

Browse files
refactor(iroh-blobs)!: expand docs (#2638)
## Description Extend iroh-blobs docs a bit ## Breaking Changes - There are some fn name changes, but they are for unpublished fns. - transfer_collection has been removed. It was very lowlevel and used in none of the examples, so I doubt anybody was using it outside. ## Notes & open questions <!-- Any notes, remarks or open questions you have to make about the PR. --> ## Change checklist - [ ] Self-review. - [ ] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [ ] Tests if relevant. - [ ] All breaking changes documented. --------- Co-authored-by: Friedel Ziegelmayer <[email protected]>
1 parent bb808b4 commit 217ac06

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

iroh-blobs/src/lib.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
//! Blobs layer for iroh.
2-
2+
//!
3+
//! The crate is designed to be used from the [iroh] crate, which provides a
4+
//! [high level interface](https://docs.rs/iroh/latest/iroh/client/blobs/index.html),
5+
//! but can also be used standalone.
6+
//!
7+
//! It implements a [protocol] for streaming content-addressed data transfer using
8+
//! [BLAKE3] verified streaming.
9+
//!
10+
//! It also provides a [store] interface for storage of blobs and outboards,
11+
//! as well as a [persistent](crate::store::fs) and a [memory](crate::store::mem)
12+
//! store implementation.
13+
//!
14+
//! To implement a server, the [provider] module provides helpers for handling
15+
//! connections and individual requests given a store.
16+
//!
17+
//! To perform get requests, the [get] module provides utilities to perform
18+
//! requests and store the result in a store, as well as a low level state
19+
//! machine for executing requests.
20+
//!
21+
//! The [downloader] module provides a component to download blobs from
22+
//! multiple sources and store them in a store.
23+
//!
24+
//! [BLAKE3]: https://github.com/BLAKE3-team/BLAKE3-specs/blob/master/blake3.pdf
25+
//! [iroh]: https://docs.rs/iroh
326
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
427
#![recursion_limit = "256"]
528

iroh-blobs/src/provider.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,21 @@ pub async fn read_request(mut reader: RecvStream) -> Result<Request> {
197197
Ok(request)
198198
}
199199

200-
/// Transfers the collection & blob data.
200+
/// Transfers a blob or hash sequence to the client.
201201
///
202-
/// First, it transfers the collection data & its associated outboard encoding data. Then it sequentially transfers each individual blob data & its associated outboard
203-
/// encoding data.
202+
/// The difference to [`handle_get`] is that we already have a reader for the
203+
/// root blob and outboard.
204204
///
205-
/// Will fail if there is an error writing to the getter or reading from
206-
/// the database.
205+
/// First, it transfers the root blob. Then, if needed, it sequentially
206+
/// transfers each individual blob data.
207207
///
208-
/// If a blob from the collection cannot be found in the database, the transfer will gracefully
209-
/// close the writer, and return with `Ok(SentStatus::NotFound)`.
208+
/// The transfer fail if there is an error writing to the writer or reading from
209+
/// the database.
210210
///
211-
/// If the transfer does _not_ end in error, the buffer will be empty and the writer is gracefully closed.
212-
pub async fn transfer_collection<D: Map>(
211+
/// If a blob from the hash sequence cannot be found in the database, the
212+
/// transfer will return with [`SentStatus::NotFound`]. If the transfer completes
213+
/// successfully, it will return with [`SentStatus::Sent`].
214+
pub(crate) async fn transfer_hash_seq<D: Map>(
213215
request: GetRequest,
214216
// Store from which to fetch blobs.
215217
db: &D,
@@ -358,7 +360,9 @@ pub trait CustomEventSender: std::fmt::Debug + Sync + Send + 'static {
358360
fn try_send(&self, event: Event);
359361
}
360362

361-
/// A possibly disabled sender for events.
363+
/// A sender for events related to blob transfers.
364+
///
365+
/// The sender is disabled by default.
362366
#[derive(Debug, Clone, Default)]
363367
pub struct EventSender {
364368
inner: Option<Arc<dyn CustomEventSender>>,
@@ -458,7 +462,9 @@ async fn handle_stream<D: Map>(db: D, reader: RecvStream, writer: ResponseWriter
458462
}
459463
}
460464

461-
/// Handle a single standard get request.
465+
/// Handle a single get request.
466+
///
467+
/// Requires the request, a database, and a writer.
462468
pub async fn handle_get<D: Map>(
463469
db: D,
464470
request: GetRequest,
@@ -482,7 +488,7 @@ pub async fn handle_get<D: Map>(
482488
let mut stats = Box::<TransferStats>::default();
483489
let t0 = std::time::Instant::now();
484490
// 5. Transfer data!
485-
let res = transfer_collection(
491+
let res = transfer_hash_seq(
486492
request,
487493
&db,
488494
&mut writer,

iroh-gossip/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! Broadcast messages to peers subscribed to a topic
2-
2+
//!
3+
//! The crate is designed to be used from the [iroh] crate, which provides a
4+
//! [high level interface](https://docs.rs/iroh/latest/iroh/client/gossip/index.html),
5+
//! but can also be used standalone.
6+
//!
7+
//! [iroh]: https://docs.rs/iroh
38
#![deny(missing_docs, rustdoc::broken_intra_doc_links)]
49

510
pub mod metrics;

iroh/src/client/blobs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@
4646
//! - [`validate`](Client::validate) validates the locally stored data against
4747
//! their BLAKE3 hashes.
4848
//! - [`delete_blob`](Client::delete_blob) deletes a blob from the local store.
49+
//!
50+
//! ### Batch operations
51+
//!
52+
//! For complex update operations, there is a [`batch`](Client::batch) API that
53+
//! allows you to add multiple blobs in a single logical batch.
54+
//!
55+
//! Operations in a batch return [temporary tags](crate::blobs::TempTag) that
56+
//! protect the added data from garbage collection as long as the batch is
57+
//! alive.
58+
//!
59+
//! To store the data permanently, a temp tag needs to be upgraded to a
60+
//! permanent tag using [`persist`](crate::client::blobs::Batch::persist) or
61+
//! [`persist_to`](crate::client::blobs::Batch::persist_to).
4962
use std::{
5063
future::Future,
5164
io,

iroh/src/client/blobs/batch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ impl Batch {
442442

443443
/// Upgrades a temp tag to a persistent tag with either a specific name or
444444
/// an automatically generated name.
445-
pub async fn upgrade_with_opts(&self, tt: TempTag, opts: SetTagOption) -> Result<Tag> {
445+
pub async fn persist_with_opts(&self, tt: TempTag, opts: SetTagOption) -> Result<Tag> {
446446
match opts {
447447
SetTagOption::Auto => self.persist(tt).await,
448448
SetTagOption::Named(tag) => {

iroh/tests/sync.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ async fn test_sync_via_relay() -> Result<()> {
576576

577577
#[tokio::test]
578578
#[cfg(feature = "test-utils")]
579+
#[ignore = "flaky"]
579580
async fn sync_restart_node() -> Result<()> {
580581
let mut rng = test_rng(b"sync_restart_node");
581582
setup_logging();

0 commit comments

Comments
 (0)