Struct MemoryStore
pub struct MemoryStore<T = ()> { /* private fields */ }
peer-store
only.Expand description
A in-memory store that uses LRU cache for bounded storage of addresses and a frequency-based ordering of addresses.
Implementations§
§impl<T> MemoryStore<T>
impl<T> MemoryStore<T>
pub fn new(config: Config) -> MemoryStore<T>
pub fn new(config: Config) -> MemoryStore<T>
Create a new MemoryStore
with the given config.
pub fn update_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
pub fn update_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
Update an address record and notify swarm if the address is new.
The added address will NOT be removed from the store on dial failure. If the added address
is supposed to be cleared from the store on dial failure, add it by emitting
FromSwarm::NewExternalAddrOfPeer
to the swarm, e.g. via
Swarm::add_peer_address
.
Returns true
if the address is new.
pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool
Remove an address record.
Returns true
when the address existed.
pub fn get_custom_data(&self, peer: &PeerId) -> Option<&T>
pub fn take_custom_data(&mut self, peer: &PeerId) -> Option<T>
pub fn take_custom_data(&mut self, peer: &PeerId) -> Option<T>
Take ownership of the internal data, leaving None
in its place.
pub fn insert_custom_data(&mut self, peer: &PeerId, custom_data: T)
pub fn insert_custom_data(&mut self, peer: &PeerId, custom_data: T)
Insert the data and notify the swarm about the update, dropping the old data if it exists.
pub fn get_custom_data_mut(&mut self, peer: &PeerId) -> Option<&mut T>
pub fn get_custom_data_mut(&mut self, peer: &PeerId) -> Option<&mut T>
Get a mutable reference to a peer’s custom data. If it exists, the swarm is notified about its modification, regardless of whether it will actually be modified.
pub fn record_iter(&self) -> impl Iterator<Item = (&PeerId, &PeerRecord<T>)>
pub fn record_iter(&self) -> impl Iterator<Item = (&PeerId, &PeerRecord<T>)>
Iterate over all internal records.
pub fn record_iter_mut(
&mut self,
) -> impl Iterator<Item = (&PeerId, &mut PeerRecord<T>)>
pub fn record_iter_mut( &mut self, ) -> impl Iterator<Item = (&PeerId, &mut PeerRecord<T>)>
Iterate over all internal records mutably.
Will not wake up the task.
Trait Implementations§
§impl<T> Default for MemoryStore<T>where
T: Default,
impl<T> Default for MemoryStore<T>where
T: Default,
§fn default() -> MemoryStore<T>
fn default() -> MemoryStore<T>
Auto Trait Implementations§
impl<T> Freeze for MemoryStore<T>
impl<T> RefUnwindSafe for MemoryStore<T>where
T: RefUnwindSafe,
impl<T> Send for MemoryStore<T>where
T: Send,
impl<T> Sync for MemoryStore<T>where
T: Sync,
impl<T> Unpin for MemoryStore<T>where
T: Unpin,
impl<T> UnwindSafe for MemoryStore<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more