Skip to main content

void_core/transport/
block.rs

1//! Async block transport trait for network operations.
2//!
3//! Defines the interface between void-core and network backends (void-daemon).
4//! Raw `&[u8]` is correct here — this is a network boundary operation.
5//! Typed blob wrapping and CID verification happen in the layers above
6//! (`RemoteStore`, `ObjectStoreExt`).
7
8use async_trait::async_trait;
9
10use crate::cid::VoidCid;
11use crate::Result;
12
13/// Async block transport for moving encrypted blocks over the network.
14///
15/// Implementations fetch and store raw content-addressed blocks via
16/// protocols like bitswap. The transport layer doesn't know or care
17/// what type of blob it's carrying — that's handled by `RemoteStore`
18/// and `ObjectStoreExt` above.
19///
20/// # Data flow
21///
22/// ```text
23/// RemoteStore::push<EncryptedShard>(blob) → blob.as_bytes() → BlockTransport::put(cid, &[u8])
24/// RemoteStore::fetch<EncryptedShard>(cid) ← B::from_bytes()  ← BlockTransport::get(cid)
25/// ```
26#[async_trait]
27pub trait BlockTransport: Send + Sync {
28    /// Push a block to the network.
29    ///
30    /// Stores the block locally and announces availability via DHT.
31    async fn put(&self, cid: &VoidCid, data: &[u8]) -> Result<()>;
32
33    /// Fetch a block from the network.
34    ///
35    /// Checks local store first, falls back to bitswap if not found.
36    async fn get(&self, cid: &VoidCid) -> Result<Vec<u8>>;
37
38    /// Check if a block exists (locally or announced on network).
39    async fn has(&self, cid: &VoidCid) -> Result<bool>;
40
41    /// Announce availability of a CID via DHT provide.
42    ///
43    /// Best-effort — failure doesn't fail the operation.
44    async fn provide(&self, cid: &VoidCid) -> Result<()>;
45
46    /// Find peers that have a CID via DHT findprovs.
47    async fn find_providers(&self, cid: &VoidCid) -> Result<Vec<String>>;
48}