Plug a KCP session in front of the VP8 wire so the upper layer (mux/curl
tunnels) gets reliable, ordered, message-oriented delivery on top of an
otherwise unreliable carrier.
Why this fixes the random 0 B/s stalls
--------------------------------------
The previous design had no retransmits and no ACKs. A single dropped
VP8 frame (from drainOutbound on micro-reconnect, the inbound 'default:'
overflow drop, or RTP loss invalidating a partial assembly) created a
hole in mux.Stream.nextSeq that would never be filled: the receiver
parked all subsequent frames in outOfOrder forever and curl read 0 B/s
until a brand new mux stream id was opened.
KCP layer details
-----------------
* Stream mode + 4-byte big-endian length prefix. Message mode would be
ideal but UDPSession.Write fragments anything > MSS *outside* of
kcp.Send, leaving every fragment with frg=0 and breaking PeekSize-based
reassembly. Length-prefix framing under stream mode is the canonical
workaround.
* nodelay(1, 10ms, fast-resend=2, no congestion control) — KCP turbo
preset, identical to kcptun/shadowsocks tuning. Recovers from burst
losses in tens of ms instead of seconds.
* SndWnd/RcvWnd 4096 segments to absorb the multi-segment burst that
a single VP8 sample can carry.
* MTU 1400 (kcp-go hardcodes mtuLimit=1500).
Wire compatibility with VP8 keepalives
--------------------------------------
KCP packets always start with the LE conv id (0x01 0xEE 0xFF 0xC0). VP8
keepalive frames start with 0x30. The receive path filters by the magic
byte before handing the buffer to KCP, so keepalives never poison the
KCP state machine.
Features() now advertises Reliable+Ordered. Drop-on-overflow paths in
the carrier are kept — KCP detects the loss via SACK and retransmits.
Refs: transport/vp8-kcp