Repository navigation
shaping: let records span full-size packets, as real servers' do - #44
Merged
Merged
Conversation
The schedule is of packets, and every packet became its own TLS record, so no record in the shaped window was longer than a packet. Censors read record lengths from the headers, and real servers write records that span packets. Now a full-size packet (1448 bytes) and the next packet from the same side are one record: one write that TCP cuts back into the scheduled packets, with a header only on the first. Plans that span packets get their own marker (a version byte in the HMAC), and servers accept both it and the legacy marker, so clients from before this keep working. Clients send only the new plan, so servers need this first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T1ZGojMkTHq5tE2Y6VNyAg
…packets The schedule counts packets, not records, so shapingRecords is now shapingPackets and the README says data passes through after the 10th packet. Where the MSS isn't 1448, TCP cuts a spanning record at the path's MSS: at 1460, as full packets, as a real server's would. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🔵 Needs a closer look
Existing loopback tests inspect TLS records rather than actual TCP packets, so validating the packet-size and direction guarantees requires human review of packet captures on representative 1448-byte MSS paths.
No open issues 🎉
What changed in this PR
Updates the initial 10-packet shaping plan so TLS records can span full-size packets, making visible record lengths more like real TLS traffic.
Changes:
- Merge eligible same-direction packet runs into records within the TLS size limit.
- Give new clients a distinct marker while servers accept both current and legacy plans; servers must be deployed first.
- Extend tests for spanning and legacy compatibility, and document packet counts and TCP segmentation limits.
| File | Description |
|---|---|
shaping.go |
Builds both shaping plans, merges eligible packets, and accepts either marker. |
shaping_test.go |
Tests spanning rules, marker separation, and legacy-client compatibility. |
README.md |
Explains packet-based shaping, spanning records, and segmentation caveats. |
client.go |
Uses the current shaping plan, with a legacy override for tests. |
Review effort: Balanced
This was referenced Nov 27, 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.
Why
Shaping draws the sizes and directions of a connection's first 10 packets from the CenKL model, but every packet then went out as its own TLS record, so within the shaped window no record was ever longer than a packet. Record lengths are readable from the unencrypted record headers, and real servers routinely write records that span several packets (a 16 KB record leaves as a run of full-MSS packets and a remainder).
What
shapingSpanRecordsturns the packet schedule into records: a full-size packet (shapingMaxPacket, 1448) and the next packet from the same side are one record. That record is one write, and TCP cuts it back into exactly the scheduled packets, so on a 1448-byte MSS path, packet sizes and directions are unchanged; only the record headers differ. About 13% of drawn schedules contain such a run; the rest are identical to before.Only exactly-full packets start a span: cutting after e.g. a 1440-byte packet would make TCP split the write at 1448 and change the packets. On a 1460-byte MSS path (no TCP timestamps), a spanning record leaves as full 1460-byte packets, as a real server's would.
shapingRecordsis renamedshapingPackets, since it counts packets.Compatibility
acceptShaping), so existing clients keep working.Performance
shapingGracewaits on an idle side: an idle schedule with two full-size runs finished in 23 ms vs 56 ms before (10 records → 4).Testing
TestShapingSpanRecords: runs, direction changes, a trailing full packet, near-full sizes that must not merge, the 16 KB record cap.TestShapingRecordsSpanPackets: on-the-wire record sizes for both HTTP/2 servers, for new clients and for a legacy client against an updated server. Verified to fail with merging disabled.TestShapingScheduleDeterministicchecks, for 198 seeds, that the current plan's records are the legacy plan's packets spanned and that the two markers differ.TestShapingEndToEndno longer expects exactly 10 records (it failed intermittently when a drawn schedule merged).go build ./...,go vet ./...,go test -race -count=1 ./...pass (as CI runs them); the end-to-end shaping tests passed 40× in a row.Risk
shaping.go(shapingPlans,acceptShaping).How to revert
Revert the merge commit. If clients already shipped it, servers must keep accepting the spanning marker until those clients are gone, so revert servers last.
Pre-PR review (local gate: Claude code review, in place of Codex)
codex execfailed twice). At the author's request, Claude Code's/code-reviewreplaced it.20bd5c2; fixes in76dec7acr=r1 CODERABBIT GATE: status=completed critical=0 important=0 minor=0 nits=0 reviewed_files=4 reviewed_sha=20bd5c2shapingRecordscounted records where the schedule counts packetsshapingUseLegacyis an unsynchronized test global — same pattern asshapingScheduleOverride; each subtest's cleanup closes its client before the next one writes it; every-racerun was clean.TestShapingScheduleDeterministicand the edge cases inTestShapingSpanRecords.AGENTS.mdadditions: noneGitHub review (
/review-pr)COPILOT GATE: unresolved_threads=0 threads_capped=false head=76dec7a copilot_reviewed=76dec7a comments_at_head=0 summary_missed=false: Copilot reviewed this head (automatic, 1 review) with no open issues. It flags that loopback tests can't confirm packet sizes on a real 1448-byte MSS path, as Testing above says.76dec7a: success, "Review completed", no findings./code-reviewinstead.🤖 Generated with Claude Code