[][src]Trait libp2p_kad::KademliaTopology

pub trait KademliaTopology: Topology {
    type ClosestPeersIter: Iterator<Item = PeerId>;
    type GetProvidersIter: Iterator<Item = PeerId>;
    fn add_kad_discovered_address(
        &mut self,
        peer: PeerId,
        addr: Multiaddr,
        connection_ty: KadConnectionType
    );
fn closest_peers(
        &mut self,
        target: &Multihash,
        max: usize
    ) -> Self::ClosestPeersIter;
fn add_provider(&mut self, key: Multihash, peer_id: PeerId);
fn get_providers(&mut self, key: &Multihash) -> Self::GetProvidersIter; }

Trait allowing retreival of information necessary for the Kadmelia system to work.

Associated Types

type ClosestPeersIter: Iterator<Item = PeerId>

Iterator returned by closest_peers.

type GetProvidersIter: Iterator<Item = PeerId>

Iterator returned by get_providers.

Loading content...

Required methods

fn add_kad_discovered_address(
    &mut self,
    peer: PeerId,
    addr: Multiaddr,
    connection_ty: KadConnectionType
)

Adds an address discovered through Kademlia to the topology.

Note: Keep in mind that peer can be the local peer.

fn closest_peers(
    &mut self,
    target: &Multihash,
    max: usize
) -> Self::ClosestPeersIter

Returns the known peers closest by XOR distance to the target.

The max parameter is the maximum number of results that we are going to use. If more than max elements are returned, they will be ignored.

Note: The results should include the local node.

fn add_provider(&mut self, key: Multihash, peer_id: PeerId)

Registers the given peer as provider of the resource with the given ID.

Note: There is no remove_provider method. Implementations must include a time-to-live system so that entries disappear after a while.

fn get_providers(&mut self, key: &Multihash) -> Self::GetProvidersIter

Returns the list of providers that have been registered with add_provider.

If the local node is a provider for key, our local peer ID should also be returned.

Loading content...

Implementations on Foreign Types

impl KademliaTopology for MemoryTopology
[src]

type ClosestPeersIter = IntoIter<PeerId>

type GetProvidersIter = IntoIter<PeerId>

Loading content...

Implementors

Loading content...