Trait RecordStore
pub trait RecordStore {
type RecordsIter<'a>: Iterator<Item = Cow<'a, Record>>
where Self: 'a;
type ProvidedIter<'a>: Iterator<Item = Cow<'a, ProviderRecord>>
where Self: 'a;
// Required methods
fn get(&self, k: &Key) -> Option<Cow<'_, Record>>;
fn put(&mut self, r: Record) -> Result<(), Error>;
fn remove(&mut self, k: &Key);
fn records(&self) -> Self::RecordsIter<'_>;
fn add_provider(&mut self, record: ProviderRecord) -> Result<(), Error>;
fn providers(&self, key: &Key) -> Vec<ProviderRecord>;
fn provided(&self) -> Self::ProvidedIter<'_>;
fn remove_provider(&mut self, k: &Key, p: &PeerId);
}
kad
only.Expand description
Trait for types implementing a record store.
There are two types of records managed by a RecordStore
:
-
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.
-
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.
Required Associated Types§
type RecordsIter<'a>: Iterator<Item = Cow<'a, Record>> where Self: 'a
type ProvidedIter<'a>: Iterator<Item = Cow<'a, ProviderRecord>> where Self: 'a
Required Methods§
fn records(&self) -> Self::RecordsIter<'_>
fn records(&self) -> Self::RecordsIter<'_>
Gets an iterator over all (value-) records currently stored.
fn add_provider(&mut self, record: ProviderRecord) -> Result<(), Error>
fn add_provider(&mut self, record: ProviderRecord) -> Result<(), Error>
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.
fn providers(&self, key: &Key) -> Vec<ProviderRecord>
fn providers(&self, key: &Key) -> Vec<ProviderRecord>
Gets a copy of the stored provider records for the given key.
fn provided(&self) -> Self::ProvidedIter<'_>
fn provided(&self) -> Self::ProvidedIter<'_>
Gets an iterator over all stored provider records for which the node owning the store is itself the provider.
fn remove_provider(&mut self, k: &Key, p: &PeerId)
fn remove_provider(&mut self, k: &Key, p: &PeerId)
Removes a provider record from the store.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.