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§
Sourcefn capabilities(&self) -> DhtCapabilities
fn capabilities(&self) -> DhtCapabilities
Get provider capabilities
Sourcefn bootstrap(&self, peers: Vec<PeerId>) -> Result<(), DhtProviderError>
fn bootstrap(&self, peers: Vec<PeerId>) -> Result<(), DhtProviderError>
Bootstrap the DHT with known peers
Sourcefn find_providers(&self, cid: &Cid) -> Result<DhtQueryResult, DhtProviderError>
fn find_providers(&self, cid: &Cid) -> Result<DhtQueryResult, DhtProviderError>
Find providers for content
Sourcefn find_peer(&self, peer_id: &PeerId) -> Result<DhtPeerInfo, DhtProviderError>
fn find_peer(&self, peer_id: &PeerId) -> Result<DhtPeerInfo, DhtProviderError>
Find a specific peer
Sourcefn get_closest_peers(
&self,
key: &[u8],
count: usize,
) -> Result<Vec<DhtPeerInfo>, DhtProviderError>
fn get_closest_peers( &self, key: &[u8], count: usize, ) -> Result<Vec<DhtPeerInfo>, DhtProviderError>
Get closest peers to a key
Sourcefn stats(&self) -> DhtProviderStats
fn stats(&self) -> DhtProviderStats
Get DHT statistics
Provided Methods§
Sourcefn put_value(&self, key: &[u8], value: &[u8]) -> Result<(), DhtProviderError>
fn put_value(&self, key: &[u8], value: &[u8]) -> Result<(), DhtProviderError>
Put a key-value pair (if supported)
Sourcefn get_value(&self, key: &[u8]) -> Result<Vec<u8>, DhtProviderError>
fn get_value(&self, key: &[u8]) -> Result<Vec<u8>, DhtProviderError>
Get a value by key (if supported)
Sourcefn is_healthy(&self) -> bool
fn is_healthy(&self) -> bool
Check if DHT is healthy