helia-block-brokers

Crates.iohelia-block-brokers
lib.rshelia-block-brokers
version0.1.3
created_at2025-10-08 12:09:09.928135+00
updated_at2025-10-11 04:11:17.868291+00
descriptionBlock broker abstractions for retrieving content from various sources
homepagehttps://github.com/cyberfly-io/rust-helia
repositoryhttps://github.com/cyberfly-io/rust-helia
max_upload_size
id1873935
size190,425
Syed (abuvanth)

documentation

README

helia-block-brokers

Block broker abstractions for coordinating block retrieval from multiple sources in Helia.

Overview

This crate provides the core traits and types for implementing block brokers - components that coordinate retrieving and announcing blocks across different protocols and sources.

Features

  • BlockBroker Trait: Core async trait for implementing different block retrieval strategies
  • Provider Types: Support for Bitswap and Gateway providers
  • Statistics Tracking: Built-in statistics for monitoring broker performance
  • Flexible Options: Configurable timeout, priority, caching, and provider selection

Usage

use helia_block_brokers::{BlockBroker, BrokerStats, BlockRetrievalOptions};
use bytes::Bytes;
use cid::Cid;

// Implement the BlockBroker trait for your custom broker
#[async_trait::async_trait]
impl BlockBroker for MyCustomBroker {
    async fn retrieve(&self, cid: Cid, options: BlockRetrievalOptions) -> Result<Bytes> {
        // Your implementation here
    }
    
    async fn announce(&self, cid: Cid, data: Bytes, options: BlockAnnounceOptions) -> Result<()> {
        // Your implementation here
    }
    
    async fn start(&self) -> Result<()> {
        // Start broker
        Ok(())
    }
    
    async fn stop(&self) -> Result<()> {
        // Stop broker
        Ok(())
    }
    
    fn get_stats(&self) -> BrokerStats {
        // Return statistics
        BrokerStats::default()
    }
    
    fn name(&self) -> &str {
        "my-custom-broker"
    }
}

Architecture

The block broker abstraction allows for multiple implementation strategies:

  • Bitswap Brokers: Retrieve blocks via the Bitswap protocol over libp2p
  • Gateway Brokers: Retrieve blocks from HTTP trustless gateways
  • Composite Brokers: Coordinate multiple brokers with fallback strategies
  • Custom Brokers: Implement your own retrieval logic

Status

This is a foundational package providing core abstractions. Concrete implementations will be added in future iterations.

License

Licensed under either of

at your option.

Commit count: 0

cargo fmt