Skip to content

feat: bounded reproducible random record and write cuts - #4

Merged
Nemu-x merged 2 commits into
mainfrom
feat/split-randomization
Oct 28, 2026
Merged

Nemu-x merged 2 commits into
mainfrom
feat/split-randomization

Conversation

@Nemu-x

@Nemu-x Nemu-x commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Milestone 2 of docs/vnext.md: bounded, reproducible randomization of record and write cuts. Deterministic options keep their exact behaviour; with Random == nil the old code path runs unchanged.

type RandomOptions struct {
    TLSRec []RandomCut // extra TLS record cuts
    Split  []RandomCut // extra TCP write cuts (rejected with Fake, like Split)
    Seed   uint64      // 0: per-connection crypto/rand seed; nonzero: same cuts on every connection
}
type RandomCut struct {
    From, To Pos // inclusive range, both absolute or both SNI-relative
    Count    int // 1..64, 0 means 1
    MinPiece int // minimum distance between cuts and to the ends
}
func (o Options) Key() string // stable description of every option, policy and seed included
  • Cuts are drawn in logical handshake bytes, uniformly over all valid spaced sets, then merged with the deterministic positions and passed through the existing sort/dedup/record filter: handshake bytes, TLS framing, trailing data and partial-write accounting are preserved, no empty records or writes, no delay unless SplitDelay is set (the random split delay is interruptible by deadlines and Close like the deterministic one).
  • Unseeded: one 8-byte crypto/rand seed per connection, then splitmix64 (~110 ns, no extra allocation). Seeded: identical cuts across connections and write chunk sizes.
  • Options.Key() covers every field (fake payload as SHA-256) with a desync/v1 prefix pinned by a seed-42 golden test, so a changed draw algorithm forces a version bump. docs/controller.md now says to derive candidate IDs / PolicyVersion from it.

Tests: random_test.go (bounds over 500 seeds, multi-record and legacy-version input, chunked writes, reproduction, golden output, partial writes at every failure offset, deadline-interrupted delay, validation, copy-on-wrap, Key uniqueness, 20 loopback TLS 1.3 handshakes) and FuzzRandomCuts (20 s, ~500k execs, no failures). Windows Go 1.26.10 tests and vet for windows/linux/darwin pass; Linux Go 1.20.14 and -race on Go 1.26.9 in Docker pass.

Benchmarks (WrapConn + 517-byte first write + 16-byte write): deterministic 430 ns, 936 B, 9 allocs (main: 407 ns, 928 B, 10 allocs); seeded 525 ns, 1104 B, 9 allocs; unseeded 650 ns.

Not verified: macOS runtime, real-network effectiveness. desync-socks has no random flags yet. On Windows with Go 1.20.14, 9 native fake tests fail exactly as on unchanged main ("read fake TTL: not supported by windows"); CI's Go 1.20 job runs on Linux.

The README paragraph targets the current README; it will be moved into the rewritten one from #3 after that merges.

Options.Random adds opt-in RandomCut ranges for TLS record cuts and TCP
write cuts, anchored like Pos (absolute or SNI-relative), with a bounded
count and minimum piece size. A nonzero seed reproduces the cuts exactly;
otherwise one crypto/rand seed per connection drives splitmix64.
Deterministic options keep their meaning byte for byte.

Options.Key returns a versioned canonical description, including the
randomization policy and seed, for use in cached strategy IDs.

Adds regression, golden, TLS round-trip and FuzzRandomCuts tests and
first-write benchmarks.
@Nemu-x
Nemu-x force-pushed the feat/split-randomization branch from 8029fc8 to 4849150 Compare October 28, 2026 18:06
@Nemu-x
Nemu-x merged commit b278abb into main Oct 28, 2026
18 checks passed
@Nemu-x
Nemu-x deleted the feat/split-randomization branch October 28, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant