iroh_db_store/
blob.rs

1use std::{future::Future, pin::Pin};
2
3use iroh_db_core::BlobHash;
4
5/// A boxed future returned by an immutable blob repository.
6pub type BlobFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, BlobStoreError>> + Send + 'a>>;
7
8/// The minimal immutable-byte boundary required by the metadata store.
9pub trait BlobStore: Send + Sync + 'static {
10    /// Stores exact bytes durably and returns their BLAKE3 content hash.
11    fn put(&self, bytes: Vec<u8>) -> BlobFuture<'_, BlobHash>;
12
13    /// Loads exact bytes when the hash is available locally.
14    fn get(&self, hash: BlobHash) -> BlobFuture<'_, Option<Vec<u8>>>;
15
16    /// Lists locally complete immutable objects in deterministic hash order.
17    fn list(&self) -> BlobFuture<'_, Vec<BlobHash>>;
18
19    /// Records that an already stored immutable object belongs to the caller's domain context.
20    ///
21    /// Stores without domain metadata may keep the default no-op implementation.
22    fn claim(&self, _hash: BlobHash) -> BlobFuture<'_, ()> {
23        Box::pin(async { Ok(()) })
24    }
25}
26
27/// An implementation-independent blob repository failure.
28#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
29#[error("blob store operation failed: {message}")]
30pub struct BlobStoreError {
31    message: String,
32}
33
34impl BlobStoreError {
35    /// Constructs a redacted operational error.
36    pub fn new(message: impl Into<String>) -> Self {
37        Self {
38            message: message.into(),
39        }
40    }
41}