Docs / Protocol

The wire

QUIC carries control and derives the media keys. Media rides raw sealed UDP with adaptive Reed-Solomon parity.

ALPN planck-v1 · AES-128-GCM · 1152 B · 36 B HEADER · RS FEC

On this page
  1. Two planes
  2. Control: QUIC
  3. Media keys and sealing
  4. Datagram sizes
  5. Forward error correction
  6. Rate control
  7. Audio
  8. Input and gamepad
  9. Clipboard
  10. Tailscale LocalAPI

Two planes

Planck splits a session into a control plane and a media plane. Control runs over one QUIC connection: pairing, negotiation, stats, key derivation and the clipboard, which gets its own QUIC stream. Media (video, audio, input, gamepad) runs over raw UDP datagrams sealed with AES-128-GCM. Tailscale's LocalAPI carries no traffic: it only supplies discovery, peer identity and path facts. The repo's transport spike chose this split: across 12 wired configurations, raw sealed UDP had a median network p50 of 1.28 ms against 1.75 ms for quic-go datagrams, and quic-go's congestion control stalled on Wi-Fi in 2 of 12 runs (docs/spikes/spike3-transport/RESULTS.md).

PortProtocolCarriesHost setting
47700UDPDiscovery probes and beaconsdiscoveryPort, -discovery-port (0 turns it off)
47701UDP (QUIC)ControlcontrolPort, -listen
47702UDPMediamediaPort, -media-port (0 picks a free port)

The ports sit below 47981 to 48500, the range Sunshine uses. A host refuses a config where the control and media ports are the same.

Control: QUIC

  • ALPN planck-v1, TLS 1.3 only. The control protocol is wire.Version 1.
  • Every host and client has a self-signed ECDSA P-256 certificate. Trust is the SHA-256 fingerprint pinned at pairing, not a certificate authority.
  • The client checks the host against its pinned fingerprint. The host checks the client through its Authorize callback: a paired fingerprint, a PIN proof, or Tailscale WhoIs.
  • A PIN proof is HMAC-SHA256(PIN, role byte ‖ TLS exporter "EXPORTER-planck-pair-v1", 32 bytes), so a proof only works inside the TLS session it was made for.

Media keys and sealing

The media keys come from the TLS 1.3 exporter of the control connection (RFC 8446 §7.5) with the labelEXPORTER-planck-media-v1. The cipher suite byte is bound into the exporter context. The exporter yields one key and one 12-byte IV per direction, client to host and host to client, so the media keys belong to that one control session.

PartBytesNotes
Marker1Cleartext
Sequence number8Cleartext, 64-bit big-endian; a sliding window rejects replays
PayloadnAES-128-GCM ciphertext
Tag16GCM authentication tag
Overhead25AEADOverhead

ChaCha20-Poly1305 is implemented in pkg/transport but the session never selects it.

Datagram sizes

ConstantValueMeaning
wire.MaxDatagram1152BDefault. Fits Tailscale's 1280-byte tunnel MTU.
wire.MaxLANDatagram1452BLAN with a 1500-byte MTU, only when both ends agree (FeatureLANDatagram).
wire.VideoHeaderLen36BPlaintext video shard header.
Video shard payload1091B1152 − 25 (AEAD) − 36 (header).
wire.MaxSlices16Slices per frame.
wire.MaxBlocks32Reed-Solomon blocks per slice.
wire.MaxShards255Data plus parity shards per block.

Media kinds

ByteNameCarries
0x11KindVideoVideo shard
0x12KindAudioOpus packet
0x13KindInputKeyboard, mouse and gamepad input
0x14KindRumbleGamepad rumble
0x15KindPingClock offset probe
0x16KindPongClock offset reply
0x17KindFeedbackClient’s per-frame report: arrival time and shard counts, the host’s loss signal

Video header

Each video shard starts with this 36-byte header (wire.VideoHeader). The client mapsCaptureTS and EncodeTS onto its own clock with the ping and pong offset.

OffsetSizeFieldNotes
01kind0x11, video
11flagsbit 0 is keyframe
21SliceIndex
31SliceCount
41BlockIndex
51BlockCount
61ShardIndex
71DataShards
81ParityShards
91Epoch
102ShardLenbig-endian
124FrameIDbig-endian
164BlockLenbig-endian
208CaptureTSns, host monotonic clock
288EncodeTSns, host monotonic clock

Forward error correction

Each slice is protected with Reed-Solomon (klauspost/reedsolomon). A block holds at most 128 data shards; a larger slice splits into up to 32 blocks.

  • Target: the smallest parity count k for which the chance of losing more than k shards in a block, at the smoothed loss estimate, is under 10−3. Parity is capped at 100% of data.
  • Tracking: loss is averaged over a 2,000-shard window and tracked rising four times faster than falling. Below 0.1% loss a path counts as clean, and the first loss on a clean path sets the estimate at once.
  • Floor: FECMinLoss keeps some parity on clean paths, and keyframes always carry at least one parity shard.

In the transport spike (240 fps, 100 Mbps, wired LAN), 1% loss with no FEC delivered 66 to 70% of frames; 20% parity delivered all of them. At 5% loss small per-slice blocks needed about 40% parity, and the adaptive policy chose 39.6% and delivered 99.8 to 99.9%. On a clean link it used 2.6 to 10%.

Rate control

Planck runs its own delay-based controller (pkg/ratectl), close to Google Congestion Control: a trendline over one-way delay, plus a loss-based cut only above 10% loss, at most once per 300 ms or one RTT. It starts at 20 Mbps with a 1 Mbps floor.

PathHow it is detectedCeilingWhere
LANLoopback, private or link-local address300Mbpsratectl.MaxKbps, defaults LAN ceiling
LAN, discovery hintHost found by LAN discovery150Mbpsdiscovery.LANMaxBitrateKbps: the most spike 3 sustained on wired LAN
Tailscale direct100.64.0.0/10 or fd7a:115c:a1e0::/48100Mbpstailscale.DirectMaxBitrateKbps
Tailscale relay (DERP)Tailscale reports a relayed path20Mbpstailscale.RelayMaxBitrateKbps, defaults WAN rate

On the LAN, video goes out in one burst per frame; there is no video pacer on that path. On Windows, timestamps and pacing use QueryPerformanceCounter, because Go's monotonic clock advances in about 0.5 ms steps on the test host.

Audio

  • 48 kHz stereo, encoded with Opus (thesyncim/gopus, pure Go): 10 ms frames by default, 20 ms allowed, 128 kbps.
  • Playback through ebitengine/oto/v3 with a 20 ms device buffer and 20 ms read-ahead.
  • The host captures with ScreenCaptureKit on macOS and WASAPI loopback on Windows. The microphone goes the other way, in mono, to a virtual input device on the host.

Input and gamepad

  • Input rides the media plane as KindInput. The host drops duplicate sequence numbers; for 2 s after a frame loss, the client resends the previous event.
  • Windows hosts inject keys by US-layout scan code (the physical key position), not virtual-key code, with SendInput. macOS hosts post CGEvents.
  • Gamepads become virtual pads through ViGEmBus on Windows; rumble returns as KindRumble.
  • planck-host -no-input ignores keyboard, mouse and gamepad from clients.

Clipboard

The clipboard syncs both ways by default; host-to-client,client-to-host and off are the other settings. Windows carriesCF_UNICODETEXT, PNG and CF_DIB; macOS carries plain text, PNG and TIFF. Items go over a one-way QUIC stream on the control connection, not the media plane, so a large image never holds up video or input.

Tailscale LocalAPI

Planck talks to the local Tailscale daemon through its LocalAPI rather than embedding a tailnet node. LocalAPI is for discovery, identity and path metadata only; control and media go over the tailnet as ordinary QUIC and UDP.

  • Discovery: clients probe tailnet addresses as well as the LAN.
  • Identity: WhoIs reports whether a peer belongs to the host's own Tailscale user, which lets it pair with no PIN.
  • Path: the path info reports direct or relayed, the MTU, and a recommended bitrate of 100 Mbps direct or 20 Mbps relayed.
  • Sizing: Tailscale's tunnel MTU is 1280 bytes, which is why the default datagram is 1152. Over a tailnet each media packet costs 60 bytes more on the wire than over the LAN.