[][src]Trait libp2p_kad::record::store::RecordStore

pub trait RecordStore<'a> {
    type RecordsIter: Iterator<Item = Cow<'a, Record>>;
    type ProvidedIter: Iterator<Item = Cow<'a, ProviderRecord>>;
    pub fn get(&'a self, k: &Key) -> Option<Cow<'_, Record>>;
pub fn put(&'a mut self, r: Record) -> Result<()>;
pub fn remove(&'a mut self, k: &Key);
pub fn records(&'a self) -> Self::RecordsIter;
pub fn add_provider(&'a mut self, record: ProviderRecord) -> Result<()>;
pub fn providers(&'a self, key: &Key) -> Vec<ProviderRecord>;
pub fn provided(&'a self) -> Self::ProvidedIter;
pub fn remove_provider(&'a mut self, k: &Key, p: &PeerId); }

Trait for types implementing a record store.

There are two types of records managed by a RecordStore:

  1. Regular (value-)records. These records store an arbitrary value associated with a key which is distributed to the closest nodes to the key in the Kademlia DHT as per the standard Kademlia "push-model". These records are subject to re-replication and re-publication as per the standard Kademlia protocol.

  2. Provider records. These records associate the ID of a peer with a key who can supposedly provide the associated value. These records are mere "pointers" to the data which may be followed by contacting these providers to obtain the value. These records are specific to the libp2p Kademlia specification and realise a "pull-model" for distributed content. Just like a regular record, a provider record is distributed to the closest nodes to the key.

Associated Types

Loading content...

Required methods

pub fn get(&'a self, k: &Key) -> Option<Cow<'_, Record>>[src]

Gets a record from the store, given its key.

pub fn put(&'a mut self, r: Record) -> Result<()>[src]

Puts a record into the store.

pub fn remove(&'a mut self, k: &Key)[src]

Removes the record with the given key from the store.

pub fn records(&'a self) -> Self::RecordsIter[src]

Gets an iterator over all (value-) records currently stored.

pub fn add_provider(&'a mut self, record: ProviderRecord) -> Result<()>[src]

Adds a provider record to the store.

A record store only needs to store a number of provider records for a key corresponding to the replication factor and should store those records whose providers are closest to the key.

pub fn providers(&'a self, key: &Key) -> Vec<ProviderRecord>[src]

Gets a copy of the stored provider records for the given key.

pub fn provided(&'a self) -> Self::ProvidedIter[src]

Gets an iterator over all stored provider records for which the node owning the store is itself the provider.

pub fn remove_provider(&'a mut self, k: &Key, p: &PeerId)[src]

Removes a provider record from the store.

Loading content...

Implementors

impl<'a> RecordStore<'a> for MemoryStore[src]

type RecordsIter = Map<Values<'a, Key, Record>, fn(_: &'a Record) -> Cow<'a, Record>>

type ProvidedIter = Map<Iter<'a, ProviderRecord>, fn(_: &'a ProviderRecord) -> Cow<'a, ProviderRecord>>

Loading content...