pub enum PexMessage {
PexHandshake {
version: u32,
network_id: String,
interval: u32,
flags: Vec<String>,
},
PexSnapshot {
peers: Vec<PeerEntry>,
},
PexDelta {
added: Vec<PeerEntry>,
dropped: Vec<String>,
},
PexError {
code: u16,
message: String,
},
}Expand description
A PEX protocol message — one of the four type-tagged shapes (SPEC §4). The type tag and field
names are the frozen wire contract.
Variants§
PexHandshake
The first PEX message a participant sends on a link, in each direction, before anything else
(SPEC §4.2). Declares the wire version, the sender’s network_id, its minimum send
interval (seconds), and its own capability flags.
Fields
PexSnapshot
The first data message in a direction — a fuller, capped picture of the sender’s first-hand known-peer set, so a fresh link warms up in one message (SPEC §4.3). Exactly one per direction per link.
Fields
PexDelta
The periodic message: what changed in the sender’s first-hand set relative to what this link has already been told (SPEC §4.4). A delta with both arrays empty MUST NOT be sent.
Fields
PexError
The advisory error envelope, either direction (SPEC §4.5). Best-effort; never requires a reply.
Implementations§
Source§impl PexMessage
impl PexMessage
Sourcepub fn encode(&self) -> Vec<u8> ⓘ
pub fn encode(&self) -> Vec<u8> ⓘ
Serialize as a u32 big-endian length prefix + JSON body — the byte-stream framing (§4.1).
Sourcepub async fn decode<R: AsyncRead + Unpin>(r: &mut R) -> Result<Self>
pub async fn decode<R: AsyncRead + Unpin>(r: &mut R) -> Result<Self>
Read + decode one framed message from r, bounded by PEX_MAX_FRAME. A length prefix over
the bound errors before allocating or reading the body (SPEC §4.1, §7.2).
Sourcepub fn to_json(&self) -> String
pub fn to_json(&self) -> String
The bare JSON object as a string — the relay WebSocket text-frame form (§4.1, §10.2).
Sourcepub fn to_json_bytes(&self) -> Vec<u8> ⓘ
pub fn to_json_bytes(&self) -> Vec<u8> ⓘ
The bare JSON object as bytes.
Trait Implementations§
Source§impl Clone for PexMessage
impl Clone for PexMessage
Source§fn clone(&self) -> PexMessage
fn clone(&self) -> PexMessage
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more