[−][src]Struct libp2p::kad::Kademlia
Network behaviour that handles Kademlia.
Methods
impl<TSubstream, TRecordStorage> Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: RecordStore,
[src]
TRecordStorage: RecordStore,
pub fn new(local_peer_id: PeerId) -> Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Default,
[src]
TRecordStorage: Default,
Creates a new Kademlia
network behaviour with the given local PeerId
.
pub fn with_protocol_name<impl Into>>(
local_peer_id: PeerId,
name: impl Into>
) -> Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Default,
impl Into>: Into<Cow<'static, [u8]>>,
[src]
local_peer_id: PeerId,
name: impl Into
) -> Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Default,
impl Into
The same as new
, but using a custom protocol name.
Kademlia nodes only communicate with other nodes using the same protocol name. Using a custom name therefore allows to segregate the DHT from others, if that is desired.
pub fn with_storage(
local_peer_id: PeerId,
records: TRecordStorage
) -> Kademlia<TSubstream, TRecordStorage>
[src]
local_peer_id: PeerId,
records: TRecordStorage
) -> Kademlia<TSubstream, TRecordStorage>
The same as new
, but with a custom storage.
The default records storage is in memory, this lets override the storage with user-defined behaviour
pub fn without_init(
local_peer_id: PeerId
) -> Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Default,
[src]
local_peer_id: PeerId
) -> Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Default,
this function is now equivalent to new() and will be removed in the future
Creates a Kademlia
.
Contrary to new
, doesn't perform the initialization queries that store our local ID into
the DHT and fill our buckets.
pub fn add_address(&mut self, peer_id: &PeerId, address: Multiaddr)
[src]
Adds a known address of a peer participating in the Kademlia DHT to the routing table.
This allows prepopulating the Kademlia routing table with known addresses, so that they can be used immediately in following DHT operations involving one of these peers, without having to dial them upfront.
pub fn kbuckets_entries(&mut self) -> impl Iterator<Item = &PeerId>
[src]
Returns an iterator over all peer IDs of nodes currently contained in a bucket of the Kademlia routing table.
pub fn find_node(&mut self, peer_id: PeerId)
[src]
Starts an iterative FIND_NODE
request.
This will eventually produce an event containing the nodes of the DHT closest to the
requested PeerId
.
pub fn get_providers(&mut self, target: Multihash)
[src]
Starts an iterative GET_PROVIDERS
request.
pub fn get_value(&mut self, key: &Multihash, num_results: NonZeroU8)
[src]
Starts an iterative GET_VALUE
request.
Returns a number of results that is in the interval [1, 20], if the user requested a larger amount of results it is cropped to 20.
pub fn put_value(&mut self, key: Multihash, value: Vec<u8>)
[src]
Starts an iterative PUT_VALUE
request
pub fn add_providing(&mut self, key: Multihash)
[src]
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.
pub fn remove_providing(&mut self, key: &Multihash)
[src]
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
impl<TSubstream, TRecordStorage> NetworkBehaviour for Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: RecordStore,
TSubstream: AsyncRead + AsyncWrite,
[src]
TRecordStorage: RecordStore,
TSubstream: AsyncRead + AsyncWrite,
type ProtocolsHandler = KademliaHandler<TSubstream, QueryId>
Handler for all the protocols the network behaviour supports.
type OutEvent = KademliaOut
Event generated by the NetworkBehaviour
and that the swarm will report back.
fn new_handler(
&mut self
) -> <Kademlia<TSubstream, TRecordStorage> as NetworkBehaviour>::ProtocolsHandler
[src]
&mut self
) -> <Kademlia<TSubstream, TRecordStorage> as NetworkBehaviour>::ProtocolsHandler
fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr>
[src]
fn inject_connected(&mut self, id: PeerId, endpoint: ConnectedPoint)
[src]
fn inject_addr_reach_failure(
&mut self,
peer_id: Option<&PeerId>,
addr: &Multiaddr,
&dyn Error
)
[src]
&mut self,
peer_id: Option<&PeerId>,
addr: &Multiaddr,
&dyn Error
)
fn inject_dial_failure(&mut self, peer_id: &PeerId)
[src]
fn inject_disconnected(&mut self, id: &PeerId, _old_endpoint: ConnectedPoint)
[src]
fn inject_replaced(
&mut self,
peer_id: PeerId,
_old: ConnectedPoint,
new_endpoint: ConnectedPoint
)
[src]
&mut self,
peer_id: PeerId,
_old: ConnectedPoint,
new_endpoint: ConnectedPoint
)
fn inject_node_event(
&mut self,
source: PeerId,
event: KademliaHandlerEvent<QueryId>
)
[src]
&mut self,
source: PeerId,
event: KademliaHandlerEvent<QueryId>
)
fn poll<impl PollParameters>(
&mut self,
parameters: &mut impl PollParameters
) -> Async<NetworkBehaviourAction<<<Kademlia<TSubstream, TRecordStorage> as NetworkBehaviour>::ProtocolsHandler as ProtocolsHandler>::InEvent, <Kademlia<TSubstream, TRecordStorage> as NetworkBehaviour>::OutEvent>> where
impl PollParameters: PollParameters,
[src]
&mut self,
parameters: &mut impl PollParameters
) -> Async<NetworkBehaviourAction<<<Kademlia<TSubstream, TRecordStorage> as NetworkBehaviour>::ProtocolsHandler as ProtocolsHandler>::InEvent, <Kademlia<TSubstream, TRecordStorage> as NetworkBehaviour>::OutEvent>> where
impl PollParameters: PollParameters,
fn inject_new_listen_addr(&mut self, _addr: &Multiaddr)
[src]
Indicates to the behaviour that we have started listening on a new multiaddr.
fn inject_expired_listen_addr(&mut self, _addr: &Multiaddr)
[src]
Indicates to the behaviour that a new multiaddr we were listening on has expired, which means that we are no longer listening in it. Read more
fn inject_new_external_addr(&mut self, _addr: &Multiaddr)
[src]
Indicates to the behaviour that we have discovered a new external address for us.
Auto Trait Implementations
impl<TSubstream, TRecordStorage> Send for Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Send,
TSubstream: Send,
TRecordStorage: Send,
TSubstream: Send,
impl<TSubstream, TRecordStorage> Sync for Kademlia<TSubstream, TRecordStorage> where
TRecordStorage: Sync,
TSubstream: Sync,
TRecordStorage: Sync,
TSubstream: Sync,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Same<T> for T
type Output = T
Should always be Self