Skip to content

feat: platform capabilities and an ACK-observed split wait - #5

Merged
Nemu-x merged 5 commits into
mainfrom
feat/platform-ack
Oct 29, 2026
Merged

Nemu-x merged 5 commits into
mainfrom
feat/platform-ack

Conversation

@Nemu-x

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

Copy link
Copy Markdown
Owner

Milestone 1 of docs/vnext.md: honest platform capabilities and a split wait that observes the socket instead of guessing with a sleep. Plus the Go 1.20 Windows fix.

caps := desync.PlatformCapabilities() // OS, FakeTCP, FakeUDP, TTLControl, Ack{Mechanism, Sent, Acked, Reliable}
probe, err := desync.ProbeConn(conn)  // TTL, Ack and the current Unacked/Unsent/InFlight of a TCP socket
opts := desync.Options{
    Split:            []desync.Pos{{Offset: 1, FromSNI: true}},
    SplitWait:        desync.SplitWaitAcked, // None | Sent | Acked; ParseSplitWait("acked")
    SplitWaitTimeout: time.Second,           // per wait; default 2 s, max 1 min
}

What each OS observes on the socket:

OS mechanism sent acked reliable
Linux / Android ioctl SIOCOUTQ / SIOCOUTQNSD (tcp(7)) ✓ ✓ yes
macOS SO_NWRITE = so_snd.sb_cc (xnu), same value as TCP_CONNECTION_INFO.tcpi_snd_sbbytes — ✓ yes
Windows 10 1703+ SIO_TCP_INFO → TCP_INFO_v0 (BytesOut, BytesRetrans, BytesInFlight) ✓ ✓ no: under window pressure BytesOut overcounts (measured), so the wait can end early
  • Unsupported modes fail in Validate or before the first byte (ErrSplitWaitUnsupported, ErrSplitWaitRequiresTCP); a wait that times out is terminal (ErrSplitWaitTimeout). No sleep is ever substituted; SplitDelay stays a separate option and runs after the wait.
  • The wait polls (Gosched, then 50 µs doubling to 1 ms) and wakes on Close and deadline changes; it leaves no goroutines, timers or native resources.
  • Key() gains ;wait=... only when set, so existing keys and golden tests are unchanged. desync-socks: -split-wait, -split-wait-timeout.
  • Go 1.20 on Windows: syscall.GetsockoptInt is a stub there, so the native fake failed with "read fake TTL: not supported by windows". A getsockoptInt helper over syscall.Getsockopt (ws2_32) fixes it; 7 fake tests that failed on 1.20.14 pass, plus a round-trip test.
  • CI: new "Go 1.20 compatibility · Windows" job (in the CI aggregate); the test matrix prints the native capability report on Linux, macOS and Windows.

Measured on loopback (517-byte hello, 4 pieces, 1,000 connections), first Write p50: none 40 µs → acked 49 µs on Windows, 18 → 21 µs on Linux; the query costs about 3–10 µs per write. Tables in docs/validation.md (DESYNC_MEASURE=1 re-runs them).

Checks: gofmt, go mod tidy -diff, vet for windows/linux/darwin on Go 1.26.10 and 1.20.14; tests on Windows (1.26.10 and 1.20.14) and Linux in Docker (1.26.9 with -race, 1.20.14); cross builds for freebsd, android, linux/arm and 386, windows/386 and arm64, darwin/arm64, js/wasm. Not verified: macOS at runtime (first run is this PR's CI), Android, Windows before 1703, real networks, Windows retransmission accounting.

syscall.GetsockoptInt is a stub returning EWINDOWS on Windows before
Go 1.21, so the native fake TCP and UDP backends failed on the module's
minimum Go with "read fake TTL: not supported by windows". Read integer
options through syscall.Getsockopt (ws2_32 getsockopt), which exists on
every supported Go version, and cover it with a round-trip test.
PlatformCapabilities reports fake TCP/UDP, TTL control and send-queue
observation for the current OS; ProbeConn checks an actual socket.
Options.SplitWait waits before each further Split piece until the kernel
reports the previous bytes as sent or acknowledged:

- Linux/Android: SIOCOUTQ and SIOCOUTQNSD byte counts (reliable)
- macOS: SO_NWRITE send-buffer bytes, acknowledged mode only (reliable)
- Windows: SIO_TCP_INFO counters, reported as not reliable

Unsupported modes fail Validate or the first Write with an explicit
error before anything is sent; no delay is substituted. Waits are bounded
by Close, write deadline changes and SplitWaitTimeout. Options without
SplitWait keep their Key(). desync-socks gains -split-wait flags.
On BSD kernels getsockopt(IPV6_UNICAST_HOPS) returns -1 while a socket uses the system default, so ProbeConn reported TTL -1 without an error for IPv6 connections on macOS. -1 is now resolved through sysctl net.inet6.ip6.hlim, the value the kernel applies.
@Nemu-x
Nemu-x merged commit 958efba into main Oct 29, 2026
19 checks passed
@Nemu-x
Nemu-x deleted the feat/platform-ack branch October 29, 2026 16:01
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