Struct libp2p_kad::Kademlia
source · pub struct Kademlia<TSubstream> { /* private fields */ }
Expand description
Network behaviour that handles Kademlia.
Implementations
sourceimpl<TSubstream> Kademlia<TSubstream>
impl<TSubstream> Kademlia<TSubstream>
sourcepub fn find_node(&mut self, peer_id: PeerId)
pub fn find_node(&mut self, peer_id: PeerId)
Starts an iterative FIND_NODE
request.
This will eventually produce an event containing the nodes of the DHT closest to the
requested PeerId
.
sourcepub fn get_providers(&mut self, key: Multihash)
pub fn get_providers(&mut self, key: Multihash)
Starts an iterative GET_PROVIDERS
request.
sourcepub fn add_providing(&mut self, key: PeerId)
pub fn add_providing(&mut self, key: PeerId)
Register the local node as the provider for the given key.
This will periodically send ADD_PROVIDER
messages to the nodes closest to the key. When
someone performs a GET_PROVIDERS
iterative request on the DHT, our local node will be
returned as part of the results.
The actual meaning of providing the value of a key is not defined, and is specific to the value whose key is the hash.
sourcepub fn remove_providing(&mut self, key: &Multihash)
pub fn remove_providing(&mut self, key: &Multihash)
Cancels a registration done with add_providing
.
There doesn’t exist any “remove provider” message to broadcast on the network, therefore we will still be registered as a provider in the DHT for as long as the timeout doesn’t expire.
Trait Implementations
sourceimpl<TSubstream, TTopology> NetworkBehaviour<TTopology> for Kademlia<TSubstream>where
TSubstream: AsyncRead + AsyncWrite,
TTopology: KademliaTopology,
impl<TSubstream, TTopology> NetworkBehaviour<TTopology> for Kademlia<TSubstream>where
TSubstream: AsyncRead + AsyncWrite,
TTopology: KademliaTopology,
type ProtocolsHandler = KademliaHandler<TSubstream, QueryId>
type ProtocolsHandler = KademliaHandler<TSubstream, QueryId>
type OutEvent = KademliaOut
type OutEvent = KademliaOut
sourcefn new_handler(&mut self) -> Self::ProtocolsHandler
fn new_handler(&mut self) -> Self::ProtocolsHandler
ProtocolsHandler
.