libp2p-hs-0.1.0.0: Haskell implementation of the libp2p networking stack
Safe HaskellNone
LanguageGHC2021

LibP2P.Noise.Framing

Description

Noise message framing: 2-byte big-endian length prefix.

All Noise messages (handshake and transport) are framed as: [2 bytes BE length][noise_message]

Per the libp2p Noise spec, a Noise message has a maximum length of 65535 bytes. Plaintext larger than one message allows must be split across multiple Noise transport messages before encryption (see chunkPlaintext); encodeFrame rejects oversized messages instead of silently truncating the length prefix.

Synopsis

Documentation

encodeFrame :: ByteString -> Either String ByteString Source #

Encode a Noise message with a 2-byte big-endian length prefix. Rejects messages larger than maxNoiseMessageSize — the 2-byte prefix cannot represent them, and truncating the length would corrupt every subsequent frame boundary on the connection.

decodeFrame :: ByteString -> Either String (ByteString, ByteString) Source #

Decode a framed Noise message. Returns the message and remaining bytes.

chunkPlaintext :: ByteString -> [ByteString] Source #

Split plaintext into chunks of at most maxNoisePlaintextSize bytes, so each chunk plus its AEAD tag fits in a single Noise message. Empty input yields a single empty chunk so callers still emit one frame.

maxNoiseMessageSize :: Int Source #

Maximum Noise message size (limited by 2-byte length prefix).

maxNoisePlaintextSize :: Int Source #

Maximum plaintext per Noise transport message: the 65535-byte Noise message cap minus the 16-byte ChaChaPoly1305 authentication tag. Matches the chunking threshold used by go-libp2p.