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
impl PexEngine
Sourcepub fn upsert_known(&mut self, entry: PeerEntry)
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.
Sourcepub fn remove_known(&mut self, peer_id: &str)
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.
Sourcepub fn link_up(&mut self, peer_id: &str, now_ms: u64) -> Vec<PexMessage>
pub fn link_up(&mut self, peer_id: &str, now_ms: u64) -> Vec<PexMessage>
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).
Sourcepub fn link_down(&mut self, peer_id: &str)
pub fn link_down(&mut self, peer_id: &str)
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.
Sourcepub fn on_message(
&mut self,
peer_id: &str,
msg: PexMessage,
now_ms: u64,
) -> PexOutcome
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).
Sourcepub fn record_violation(
&mut self,
peer_id: &str,
code: PexErrorCode,
_now_ms: u64,
) -> PexOutcome
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.
Sourcepub fn tick(&mut self, now_ms: u64) -> Vec<(String, PexMessage)>
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.
Sourcepub fn known_count(&self) -> usize
pub fn known_count(&self) -> usize
Number of peers in the first-hand advertise set.
Sourcepub fn link_count(&self) -> usize
pub fn link_count(&self) -> usize
Number of live links.
Sourcepub fn is_muted(&self, peer_id: &str) -> bool
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).
Sourcepub fn strikes(&self, peer_id: &str) -> u32
pub fn strikes(&self, peer_id: &str) -> u32
The violation strike count on peer_id’s incoming direction (SPEC §11.2).
Sourcepub fn told_count(&self, peer_id: &str) -> usize
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).
Sourcepub fn current_hint(&self, peer_id: &str) -> Option<(&str, u64)>
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.
Sourcepub fn received_count(&self, peer_id: &str) -> usize
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.
Sourcepub fn hints_count(&self) -> usize
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.