pub struct PeerEntry {
pub peer_id: String,
pub addresses: Vec<Address>,
pub network_id: String,
pub last_seen: u64,
pub via: Provenance,
pub flags: Vec<String>,
}Expand description
The unit of exchange — a peer entry (SPEC §3). Constructed via PeerEntry::new + the builder
methods for outgoing advertisements; decoded tolerantly for inbound validation.
Fields§
§peer_id: StringThe advertised peer’s mTLS identity, <64hex>.
addresses: Vec<Address>Candidate addresses, most-direct-first. MAY be empty (reachable only via shared
infrastructure, e.g. relay rendezvous by peer_id; see the relay-only flag).
network_id: StringThe network the peer belongs to. MUST equal the link’s network.
last_seen: u64Unix seconds when the advertiser last had first-hand evidence of the peer (SPEC §8.2).
via: ProvenanceThe advertiser’s provenance for this entry (SPEC §8.1).
flags: Vec<String>Per-peer capability flags (SPEC §3.2). Optional; defaults to empty.
Implementations§
Source§impl PeerEntry
impl PeerEntry
Sourcepub fn new(
peer_id: impl Into<String>,
network_id: impl Into<String>,
last_seen: u64,
via: Provenance,
) -> Self
pub fn new( peer_id: impl Into<String>, network_id: impl Into<String>, last_seen: u64, via: Provenance, ) -> Self
A new entry for peer_id on network_id, last seen at last_seen (Unix seconds), with
provenance via. Add addresses/flags with the builder methods.
Sourcepub fn with_address(self, addr: Address) -> Self
pub fn with_address(self, addr: Address) -> Self
Builder: append a candidate address.
Sourcepub fn with_flag(self, flag: impl Into<String>) -> Self
pub fn with_flag(self, flag: impl Into<String>) -> Self
Builder: append a capability flag token.
Sourcepub fn validate(&self, ctx: &ValidateCtx<'_>) -> Result<(), EntrySkip>
pub fn validate(&self, ctx: &ValidateCtx<'_>) -> Result<(), EntrySkip>
Validate this entry against the receiver’s link context (SPEC §3.3). Returns the reason a
conformant receiver skips it, or Ok(()) to keep it. Skipping is silent — no strike.
Sourcepub fn clamped(&self, now_secs: u64) -> PeerEntry
pub fn clamped(&self, now_secs: u64) -> PeerEntry
A copy with a future last_seen clamped to now_secs (SPEC §3.3 — a receiver SHOULD clamp a
last_seen in the future to its own clock).
Sourcepub fn fingerprint(&self) -> String
pub fn fingerprint(&self) -> String
The per-link advertised-content fingerprint — a stable string over the addresses and flags
excluding last_seen (SPEC §9.1), so heartbeat churn (a fresher last_seen alone) never
re-advertises an unchanged peer. Two entries with the same fingerprint are “the same
advertisement” for delta purposes.
This allocates (a Vec<String> per call plus the final formatted String) and is intended
for display/debugging/tests. The delta hot path uses the allocation-free
fingerprint_hash instead (#179 MED optimization).
Sourcepub fn fingerprint_hash(&self) -> u64
pub fn fingerprint_hash(&self) -> u64
The allocation-free equivalent of fingerprint: a 64-bit hash over the
same canonical content (addresses + flags, sorted, excluding last_seen) with the same
equality semantics — two entries with equal fingerprint() strings MUST have equal
fingerprint_hash() values (and vice versa for practical purposes; a hash collision is
possible but not a correctness concern for this delta-suppression use). Used as the told-map
value (SPEC §9.1) so the per-tick, per-link delta comparison is a Copy, allocation-free u64
equality check instead of building + sorting + formatting a String per advertisable entry
per link per tick (#179 MED optimization).
Sorts addresses/flags by reference (Vec<&Address> / Vec<&str>, no cloning) before
feeding a stable field-separated byte stream to the hasher, so the result is independent of
input order while never allocating an intermediate String.