Expand description
The BitTorrent peer wire protocol (BEP-3) as a typed AST.
After the TCP/uTP handshake, two peers exchange a stream of
length-prefixed messages. This crate models that stream as the
pleme-io idiom demands — a typed PeerMessage AST
(parse-don’t-validate) with a [PeerMessage::parse] decoder and a
typed-emission PeerMessage::encode (the framing is built from
typed integers and byte literals, never a format!() of the wire —
the ★★ TYPED EMISSION rule). It is the exact shape proven in mado’s
CsiCommand dispatch: bytes → typed message → interpret.
Frame layout: <u32 length><u8 id><payload>; a zero-length frame is
the PeerMessage::KeepAlive (no id byte). The Handshake that
precedes the stream has its own fixed layout.
Structs§
- Block
- A request/cancel block region (
index,begin,length) — a sub-range of a piece. - Handshake
- The opening handshake:
<19><"BitTorrent protocol"><8 reserved><20 info_hash><20 peer_id>— 68 bytes total.
Enums§
- Peer
Message - The typed peer-wire message AST (BEP-3 + the BEP-5
Portand BEP-10Extendedmessages). Unknown ids are kept (not dropped) asPeerMessage::Unknownso a forward-compatible peer round-trips. - Protocol
Error - A typed framing/decoding failure.
Constants§
- PROTOCOL
- The fixed protocol identifier string in the handshake (
pstr).
Functions§
- decode_
frame - Decode one complete frame from the front of a buffer: read the 4-byte
big-endian length prefix, and if that many body bytes are present,
return the parsed
PeerMessageand the number of bytes consumed.Ok(None)means “need more bytes” (the frame isn’t complete yet) — the caller keeps buffering. This is the streaming framing seam.