[][src]Struct libp2p::kad::Kademlia

pub struct Kademlia<TSubstream, TRecordStorage = MemoryRecordStorage> where
    TRecordStorage: RecordStore
{ /* fields omitted */ }

Network behaviour that handles Kademlia.

Methods

impl<TSubstream, TRecordStorage> Kademlia<TSubstream, TRecordStorage> where
    TRecordStorage: RecordStore
[src]

pub fn new(local_peer_id: PeerId) -> Kademlia<TSubstream, TRecordStorage> where
    TRecordStorage: Default
[src]

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]

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]

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]

Deprecated:

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]

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 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

impl<TSubstream, TRecordStorage> Sync for Kademlia<TSubstream, TRecordStorage> where
    TRecordStorage: Sync,
    TSubstream: Sync

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Erased for T

impl<T> Erased for T