From c5caa64ebbeff077aff0fec8f25a5081153b47e5 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Fri, 11 Jul 2025 17:53:01 +0300 Subject: [PATCH 1/3] - Hide the test module from docs (it will be removed/hidden behind a feature flag into a separate crate eventually. - Make util pub(crate) - Remove unused code in the hash_seq module --- src/hashseq.rs | 52 +------------------------------------------------- src/lib.rs | 6 ++++-- 2 files changed, 5 insertions(+), 53 deletions(-) diff --git a/src/hashseq.rs b/src/hashseq.rs index bcbebf98..98d96e45 100644 --- a/src/hashseq.rs +++ b/src/hashseq.rs @@ -1,8 +1,7 @@ //! Helpers for blobs that contain a sequence of hashes. -use std::{fmt::Debug, io}; +use std::fmt::Debug; use bytes::Bytes; -use iroh_io::{AsyncSliceReader, AsyncSliceReaderExt}; use crate::Hash; @@ -51,34 +50,6 @@ impl IntoIterator for HashSeq { } } -/// Stream over the hashes in a [`HashSeq`]. -/// -/// todo: make this wrap a reader instead of a [`HashSeq`]. -#[derive(Debug, Clone)] -pub struct HashSeqStream(HashSeq); - -impl HashSeqStream { - /// Get the next hash in the sequence. - #[allow(clippy::should_implement_trait, clippy::unused_async)] - pub async fn next(&mut self) -> io::Result> { - Ok(self.0.pop_front()) - } - - /// Skip a number of hashes in the sequence. - #[allow(clippy::unused_async)] - pub async fn skip(&mut self, n: u64) -> io::Result<()> { - let ok = self.0.drop_front(n as usize); - if !ok { - Err(io::Error::new( - io::ErrorKind::UnexpectedEof, - "end of sequence", - )) - } else { - Ok(()) - } - } -} - impl HashSeq { /// Create a new sequence of hashes. pub fn new(bytes: Bytes) -> Option { @@ -89,16 +60,6 @@ impl HashSeq { } } - fn drop_front(&mut self, n: usize) -> bool { - let start = n * 32; - if start > self.0.len() { - false - } else { - self.0 = self.0.slice(start..); - true - } - } - /// Iterate over the hashes in this sequence. pub fn iter(&self) -> impl Iterator + '_ { self.0.chunks_exact(32).map(|chunk| { @@ -155,14 +116,3 @@ impl Iterator for HashSeqIter { self.0.pop_front() } } - -/// Parse a sequence of hashes. -pub async fn parse_hash_seq<'a, R: AsyncSliceReader + 'a>( - mut reader: R, -) -> anyhow::Result<(HashSeqStream, u64)> { - let bytes = reader.read_to_end().await?; - let hashes = HashSeq::try_from(bytes)?; - let num_hashes = hashes.len() as u64; - let stream = HashSeqStream(hashes); - Ok((stream, num_hashes)) -} diff --git a/src/lib.rs b/src/lib.rs index 06499b41..6fd46b0c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,9 +11,11 @@ mod net_protocol; pub use net_protocol::BlobsProtocol; pub mod protocol; pub mod provider; -pub mod test; pub mod ticket; -pub mod util; + +#[doc(hidden)] +pub mod test; +mod util; #[cfg(test)] mod tests; From 40024271f27674378ea3721347aee97a195aab34 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Fri, 11 Jul 2025 18:15:03 +0300 Subject: [PATCH 2/3] Reexport ChunkRanges and ChunkRangeExt in protocol. ChunkRangeExt is really the only thing we need out of util. Eventually I might have to newtype ChunkRanges even though that would be a PITA. --- src/protocol/range_spec.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/protocol/range_spec.rs b/src/protocol/range_spec.rs index c60414de..92cfe938 100644 --- a/src/protocol/range_spec.rs +++ b/src/protocol/range_spec.rs @@ -7,18 +7,19 @@ //! collection. use std::{fmt, sync::OnceLock}; -use bao_tree::{ChunkNum, ChunkRanges, ChunkRangesRef}; +pub use bao_tree::ChunkRanges; +use bao_tree::{ChunkNum, ChunkRangesRef}; use serde::{Deserialize, Serialize}; use smallvec::{smallvec, SmallVec}; +pub use crate::util::ChunkRangesExt; + static CHUNK_RANGES_EMPTY: OnceLock = OnceLock::new(); fn chunk_ranges_empty() -> &'static ChunkRanges { CHUNK_RANGES_EMPTY.get_or_init(ChunkRanges::empty) } -use crate::util::ChunkRangesExt; - #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(from = "wire::RangeSpecSeq", into = "wire::RangeSpecSeq")] pub struct ChunkRangesSeq(pub(crate) SmallVec<[(u64, ChunkRanges); 2]>); From ce6847e8298741a818f80601552b072e9b26f128 Mon Sep 17 00:00:00 2001 From: Ruediger Klaehn Date: Fri, 11 Jul 2025 18:27:11 +0300 Subject: [PATCH 3/3] Add api module docs people are confused how to obtain an API instance to work with, so this give them pointers. --- src/api.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/api.rs b/src/api.rs index f3c540cd..2296c3d7 100644 --- a/src/api.rs +++ b/src/api.rs @@ -2,6 +2,16 @@ //! //! This API is both for interacting with an in-process store and for interacting //! with a remote store via rpc calls. +//! +//! The entry point for the api is the [`Store`] struct. There are several ways +//! to obtain a `Store` instance: it is available via [`Deref`](std::ops::Deref) +//! from the different store implementations +//! (e.g. [`MemStore`](crate::store::mem::MemStore) +//! and [`FsStore`](crate::store::fs::FsStore)) as well as on the +//! [`BlobsProtocol`](crate::BlobsProtocol) iroh protocol handler. +//! +//! You can also [`connect`](Store::connect) to a remote store that is listening +//! to rpc requests. use std::{io, net::SocketAddr, ops::Deref, sync::Arc}; use bao_tree::io::EncodeError;