Skip to main content

PexEngine

Struct PexEngine 

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

The transport-agnostic PEX engine (SPEC Appendix A). One instance per participant; it multiplexes all of that participant’s links.

Implementations§

Source§

impl PexEngine

Source

pub fn new(cfg: PexConfig) -> Self

Create an engine from cfg.

Source

pub fn upsert_known(&mut self, entry: PeerEntry)

Add or update a first-hand-known peer in the advertise set (SPEC §8.1, §9.3). The caller supplies the honest via + a fresh last_seen; the Provenance type structurally forbids a "pex" provenance, so a PEX-learned entry can never be re-advertised unverified. The change surfaces as added in the next tick delta on each link.

Source

pub fn remove_known(&mut self, peer_id: &str)

Remove a peer from the advertise set — it disconnected or went stale (SPEC §9.3). It surfaces as dropped in the next delta on links that were told it.

A link came up: register it and produce our outgoing direction — the pex_handshake followed (back-to-back) by the pex_snapshot of our current first-hand set (SPEC §5.1, §6.1). Write the returned messages on our sending stream. Preserves any receiver-side state if the link already exists (e.g. an inbound message arrived first).

A link went down: discard all per-link state, and unlist it as the source of any current hints (SPEC §5.5, §9.2). A new connection starts fresh.

Source

pub fn on_message( &mut self, peer_id: &str, msg: PexMessage, now_ms: u64, ) -> PexOutcome

Feed one decoded inbound message from peer_id. Returns replies to send + events to act on. A malformed entry inside a valid message is skipped silently; a malformed message / rate / oversize / state violation is discarded with a strike (SPEC §7.3, §11.2).

Source

pub fn record_violation( &mut self, peer_id: &str, code: PexErrorCode, _now_ms: u64, ) -> PexOutcome

Record a transport-detected violation the engine could not see itself: a frame-size overrun (Oversized) or an undecodable/malformed frame (BadMessage) — SPEC §7.2, §7.3. Counts a strike and mutes at the limit, exactly like an engine-detected violation.

Source

pub fn tick(&mut self, now_ms: u64) -> Vec<(String, PexMessage)>

Drive the send cadence (call ~1/s). For each link whose effective interval has elapsed since its last data message and that has pending changes, emits a pex_delta (SPEC §4.4, §6). A delta with no changes is suppressed (empty deltas are never sent). Returns (peer_id, message) pairs to write to the matching links.

Source

pub fn known_count(&self) -> usize

Number of peers in the first-hand advertise set.

Number of live links.

Source

pub fn is_muted(&self, peer_id: &str) -> bool

Whether the incoming direction of peer_id’s link is muted (SPEC §5.2, §11.2).

Source

pub fn strikes(&self, peer_id: &str) -> u32

The violation strike count on peer_id’s incoming direction (SPEC §11.2).

Source

pub fn told_count(&self, peer_id: &str) -> usize

How many peer ids we have currently told peer_id’s link (told-state size, SPEC §9.1).

Source

pub fn current_hint(&self, peer_id: &str) -> Option<(&str, u64)>

The current deduplicated hint for peer_id (SPEC §9.2): (source link, last_seen), if any.

Source

pub fn received_count(&self, peer_id: &str) -> usize

How many peer_ids peer_id’s link has told us are currently tracked in its received accumulator (SPEC §9.2, §11.3) — bounded by crate::caps::PEX_MAX_RECEIVED_PER_LINK.

Source

pub fn hints_count(&self) -> usize

The total number of deduplicated hints currently held across all links (SPEC §9.2, §11.3) — bounded by crate::caps::PEX_MAX_HINTS.

Trait Implementations§

Source§

impl Debug for PexEngine

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

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

Source§

fn vzip(self) -> V