Struct MemoryStore

Source
pub struct MemoryStore<T = ()> { /* private fields */ }
Expand description

A in-memory store that uses LRU cache for bounded storage of addresses and a frequency-based ordering of addresses.

Implementations§

Source§

impl<T> MemoryStore<T>

Source

pub fn new(config: Config) -> Self

Create a new MemoryStore with the given config.

Source

pub fn add_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool

Add an address for a peer.

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.

Source

pub fn remove_address(&mut self, peer: &PeerId, address: &Multiaddr) -> bool

Remove an address record.

Returns true when the address existed.

Source

pub fn get_custom_data(&self, peer: &PeerId) -> Option<&T>

Get a reference to a peer’s custom data.

Source

pub fn take_custom_data(&mut self, peer: &PeerId) -> Option<T>

Take ownership of the internal data, leaving None in its place.

Source

pub fn insert_custom_data(&mut self, peer: &PeerId, custom_data: T)

Insert the data, dropping the old data if it exists.

Source

pub fn get_custom_data_mut(&mut self, peer: &PeerId) -> Option<&mut T>

Get a mutable reference to a peer’s custom data.

Source

pub fn record_iter(&self) -> impl Iterator<Item = (&PeerId, &PeerRecord<T>)>

Iterate over all internal records.

Source

pub fn record_iter_mut( &mut self, ) -> impl Iterator<Item = (&PeerId, &mut PeerRecord<T>)>

Iterate over all internal records mutably.

Changes to the records will not generate an event.

Trait Implementations§

Source§

impl<T: Default> Default for MemoryStore<T>

Source§

fn default() -> MemoryStore<T>

Returns the “default value” for a type. Read more
Source§

impl<T> Store for MemoryStore<T>

Source§

type Event = Event

Event generated by the store and emitted to Swarm. Behaviour cannot handle this event.
Source§

fn on_swarm_event(&mut self, swarm_event: &FromSwarm<'_>)

How this store handles events from Swarm.
Source§

fn addresses_of_peer( &self, peer: &PeerId, ) -> Option<impl Iterator<Item = &Multiaddr>>

Get all stored addresses of the peer.
Source§

fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Event>

Polls for things that the store should do.
The task should be waked up to emit events to Behaviour and Swarm.

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T