DhtProvider

Trait DhtProvider 

Source
pub trait DhtProvider: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn version(&self) -> &str;
    fn capabilities(&self) -> DhtCapabilities;
    fn bootstrap(&self, peers: Vec<PeerId>) -> Result<(), DhtProviderError>;
    fn provide(&self, cid: &Cid) -> Result<(), DhtProviderError>;
    fn find_providers(
        &self,
        cid: &Cid,
    ) -> Result<DhtQueryResult, DhtProviderError>;
    fn find_peer(
        &self,
        peer_id: &PeerId,
    ) -> Result<DhtPeerInfo, DhtProviderError>;
    fn get_closest_peers(
        &self,
        key: &[u8],
        count: usize,
    ) -> Result<Vec<DhtPeerInfo>, DhtProviderError>;
    fn stats(&self) -> DhtProviderStats;

    // Provided methods
    fn put_value(
        &self,
        key: &[u8],
        value: &[u8],
    ) -> Result<(), DhtProviderError> { ... }
    fn get_value(&self, key: &[u8]) -> Result<Vec<u8>, DhtProviderError> { ... }
    fn is_healthy(&self) -> bool { ... }
}
Expand description

Common trait for DHT providers

Required Methods§

Source

fn name(&self) -> &str

Get provider name

Source

fn version(&self) -> &str

Get provider version

Source

fn capabilities(&self) -> DhtCapabilities

Get provider capabilities

Source

fn bootstrap(&self, peers: Vec<PeerId>) -> Result<(), DhtProviderError>

Bootstrap the DHT with known peers

Source

fn provide(&self, cid: &Cid) -> Result<(), DhtProviderError>

Announce content availability

Source

fn find_providers(&self, cid: &Cid) -> Result<DhtQueryResult, DhtProviderError>

Find providers for content

Source

fn find_peer(&self, peer_id: &PeerId) -> Result<DhtPeerInfo, DhtProviderError>

Find a specific peer

Source

fn get_closest_peers( &self, key: &[u8], count: usize, ) -> Result<Vec<DhtPeerInfo>, DhtProviderError>

Get closest peers to a key

Source

fn stats(&self) -> DhtProviderStats

Get DHT statistics

Provided Methods§

Source

fn put_value(&self, key: &[u8], value: &[u8]) -> Result<(), DhtProviderError>

Put a key-value pair (if supported)

Source

fn get_value(&self, key: &[u8]) -> Result<Vec<u8>, DhtProviderError>

Get a value by key (if supported)

Source

fn is_healthy(&self) -> bool

Check if DHT is healthy

Implementors§