feat(proto): add directional packet codecs #41

Merged
Lochnair merged 3 commits from feat/directional-codecs into main 2026-08-03 17:48:26 +00:00
Lochnair commented 2026-08-03 17:45:07 +00:00 (Migrated from github.com)

Summary

  • centralize shared packet-envelope handling in a private protocol module
  • add server-direction open, echo, and close codecs
  • separate wire-only EchoRequest data from negotiated Params
  • adapt SessionMachine to pass negotiated echo parameters explicitly

Wire-format rationale

Packet headers, directional flags, exact layouts, HMAC presence and
verification, and HMAC finalization are shared wire concerns. The new private
envelope module centralizes those mechanics without exposing a generic codec
API or introducing server lifecycle policy.

Public API changes

Adds:

  • decode_open_request
  • encode_open_reply
  • decode_echo_request
  • encode_echo_reply
  • decode_close_request

EchoRequest now contains only token, sequence, and payload.
encode_echo_request now receives &Params separately. This is an intentional
source-breaking irtt-proto API correction.

Validation behavior

Directional request/reply flags are enforced strictly. Valid no-test openings
and peer-close echo replies remain supported. Encoder HMAC behavior is
authoritative from key presence, and decoders reject missing, unexpected, or
invalid authentication.

Normal open replies with a zero token remain ProtoError::ZeroToken.
MissingField and UnexpectedField distinguish negotiated echo layout errors.

Testing

  • exact authenticated and unauthenticated vectors
  • directional codec round trips
  • required and forbidden flags
  • HMAC normalization and verification
  • optional-field layouts
  • malformed and exact lengths
  • payload bounds and zero filling
  • no-test and peer-close forms
  • full workspace tests and targeted clippy checks
## Summary - centralize shared packet-envelope handling in a private protocol module - add server-direction open, echo, and close codecs - separate wire-only EchoRequest data from negotiated Params - adapt SessionMachine to pass negotiated echo parameters explicitly ## Wire-format rationale Packet headers, directional flags, exact layouts, HMAC presence and verification, and HMAC finalization are shared wire concerns. The new private envelope module centralizes those mechanics without exposing a generic codec API or introducing server lifecycle policy. ## Public API changes Adds: - decode_open_request - encode_open_reply - decode_echo_request - encode_echo_reply - decode_close_request EchoRequest now contains only token, sequence, and payload. encode_echo_request now receives &Params separately. This is an intentional source-breaking irtt-proto API correction. ## Validation behavior Directional request/reply flags are enforced strictly. Valid no-test openings and peer-close echo replies remain supported. Encoder HMAC behavior is authoritative from key presence, and decoders reject missing, unexpected, or invalid authentication. Normal open replies with a zero token remain ProtoError::ZeroToken. MissingField and UnexpectedField distinguish negotiated echo layout errors. ## Testing - exact authenticated and unauthenticated vectors - directional codec round trips - required and forbidden flags - HMAC normalization and verification - optional-field layouts - malformed and exact lengths - payload bounds and zero filling - no-test and peer-close forms - full workspace tests and targeted clippy checks
Sign in to join this conversation.