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
impl WaitingQueue
Sourcepub fn new(limits: WaitingLimits) -> Self
pub fn new(limits: WaitingLimits) -> Self
An empty queue under limits, grouping IPv6 sources by /64.
Sourcepub fn with_ipv6_prefix(self, bits: u8) -> Self
pub fn with_ipv6_prefix(self, bits: u8) -> Self
This queue grouping IPv6 sources by their first bits bits (values above 128 are 128).
Sourcepub fn limits(&self) -> WaitingLimits
pub fn limits(&self) -> WaitingLimits
The limits it applies.
Sourcepub fn ipv6_prefix(&self) -> u8
pub fn ipv6_prefix(&self) -> u8
The IPv6 prefix length sources are grouped by.
Sourcepub fn admit(
&mut self,
id: PeerId,
source: Option<SocketAddr>,
stored: usize,
now: Instant,
) -> Admission
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.
Sourcepub fn remember(
&mut self,
id: PeerId,
source: Option<SocketAddr>,
at: Instant,
) -> Vec<PeerId>
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.
Sourcepub fn prune(&mut self, now: Instant, stored: impl Fn(&PeerId) -> bool)
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.