Skip to main content

WaitingQueue

Struct WaitingQueue 

Source
pub struct WaitingQueue { /* private fields */ }
Expand description

Decides which unaccepted peers are recorded as waiting, without storing anything: the policy of TrustStore::record_waiting, for a host that keeps its waiting entries elsewhere.

A source is an IPv4 address (an IPv4-mapped IPv6 address counts as its IPv4 address), an IPv6 prefix of with_ipv6_prefix bits (/64 unless set, since one holder controls every address of a /64), or no address at all, which is one source. The queue remembers what it admitted, per source, oldest first; it forgets nothing on its own, beyond the per_source entries it keeps for each source.

Implementations§

Source§

impl WaitingQueue

Source

pub fn new(limits: WaitingLimits) -> Self

An empty queue under limits, grouping IPv6 sources by /64.

Source

pub fn with_ipv6_prefix(self, bits: u8) -> Self

This queue grouping IPv6 sources by their first bits bits (values above 128 are 128).

Source

pub fn limits(&self) -> WaitingLimits

The limits it applies.

Source

pub fn ipv6_prefix(&self) -> u8

The IPv6 prefix length sources are grouped by.

Source

pub fn admit( &mut self, id: PeerId, source: Option<SocketAddr>, stored: usize, now: Instant, ) -> Admission

Decides whether id, from source, is recorded now.

stored is how many waiting entries the host holds; at total or above, nothing is recorded (the newcomer waits, no entry is dropped for it). The same peer from the same source is recorded again only after rerecord. A source past per_source gives up its oldest entries, listed in Admission::evict for the host to remove. The host checks itself whether id is already stored, and does not call this then.

Source

pub fn remember( &mut self, id: PeerId, source: Option<SocketAddr>, at: Instant, ) -> Vec<PeerId>

Remembers that id from source was recorded at at, for a host that seeds the queue from entries it stored earlier. Entries past per_source for that source are forgotten, oldest first, and returned.

Source

pub fn prune(&mut self, now: Instant, stored: impl Fn(&PeerId) -> bool)

Forgets every entry the host no longer stores (stored is false for it) once its rerecord time has passed; within it the entry still keeps the same peer from being recorded again from its source.

For a host whose entries another process may accept or remove: without it, the queue remembers them, and its memory grows with every source it has seen.

Source

pub fn len(&self) -> usize

The number of entries remembered, across every source.

Source

pub fn is_empty(&self) -> bool

Whether nothing is remembered.

Source

pub fn forget(&mut self, id: &PeerId)

Forgets id from every source, as when the host accepts or removes it.

Trait Implementations§

Source§

impl Clone for WaitingQueue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WaitingQueue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.