feat(capture): live-proxy pump pipeline (#56, part 1)#63
Merged
Conversation
The socket-free heart of the MITM proxy. `pumpDirection` drives one direction over a generic Io.Reader/Io.Writer: it relays every WebSocket frame verbatim (Studio is transparent — masking polarity is preserved hop for hop) and taps a copy to decode into canonical events. A `Sink` accumulates the tapped events, appends a JSONL recording (embedding the exact OCPP-J bytes, with explicit direction/timestamp so it re-parses offline identically), reassembles fragmented messages, and runs detection on demand. Operating over generic readers/writers keeps the whole pipeline unit-testable in memory (no sockets): verbatim relay, fragmented reassembly + stop-on-close, and a parity test proving streaming detection over the live events equals a cold offline pass over the recording. The real-socket accept/dial/connect wiring and the io.async bidirectional concurrency build on this to close #56 (part 2). Part of #56.
This was referenced Jul 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 1 of #56 (the flagship proxy). This lands the socket-free pump
pipeline; a follow-up wires it to real
std.Io.netsockets withio.asyncbidirectional concurrency to close the issue.
Why split
The pipeline (relay + decode + record + detect) is pure data-flow and worth
verifying in isolation, deterministically. The transport layer (accept/dial +
structured concurrency over Zig 0.16's new async
std.Io.net) is a separable,novel-API concern. Keeping them apart gives each a green, reviewable checkpoint.
What's here —
src/capture/proxy.zigpumpDirectiondrives one direction over a genericIo.Reader/Io.Writer:it relays every frame verbatim (Studio is transparent) and taps a copy
to decode. Verbatim relay is correct because masking polarity is preserved hop
for hop — CP→CSMS stays client→server (masked), CSMS→CP stays server→client
(unmasked) — so raw bytes forward untouched; the tap decodes a copy (decode
unmasks in place, never the relayed bytes).
Sinkaccumulates tapped events, appends a JSONL recording embeddingthe exact OCPP-J bytes with explicit direction/timestamp (so it re-parses
offline identically), reassembles fragmented messages via
ws.Assembler, andruns detection on demand (
detect— the streaming/session-end surface).relayed close ends the direction.
Hardening
Per-frame cap (1 MiB) → oversize closes the session; per-session event cap bounds
retained memory; a frame that fails to decode is counted (
dropped) and skipped,never fatal.
Tests (3 new, 147 total)
socket-known direction.
detectFailuresover the recording (aFAILED_AUTHORIZATIONcase).Verification
native test -Dplatform=null→ 147/147.native build(ReleaseFast) → clean.zig fmt --checkclean.Next (part 2, closes #56)
Real
IpAddress.listen/accept/connect, the MITM handshake relay (reusing#54's both-halves codec),
io.async/Groupconcurrency guarded by astd.Io.Mutex, and an in-processnetSocketCreatePairCP ↔ proxy ↔ CSMSintegration test — plus ADR-0009 recording the transport/concurrency decision.