ADR-0014: Bulk transfer over secondary TLS connections
- Status: accepted
- Date: 2026-11-08
- Deciders: maintainer
- Tags:
protocol,files,messages,photos
Context
ADR-0002 fixed a single framed control connection with a 4 MiB frame cap and
reserved StreamOpen for bulk data without specifying it. Milestone 2 needs
MMS attachments (both directions), file transfer (both directions) and photo
originals (phone → desktop), from a few KiB to several GiB. Options:
- Chunk bulk data into control frames (
Chunk{ref_id, offset, bytes}). Simple, but head-of-line blocking stalls notifications and media controls during a transfer, and every chunk is re-serialised. - One secondary TLS connection per stream carrying a
StreamOpenheader and raw bytes. Parallel to the control connection, no framing cost, cancellation by closing, backpressure from TCP. Costs one TLS handshake per stream. - A multiplexed secondary connection (HTTP/2-like). Most efficient, most code.
Decision
Option 2, as specified in docs/reference/protocol.md “Secondary streams”: the side that
has the bytes dials, sends one Envelope{StreamOpen} (no Hello), then exactly
size raw bytes and half-closes. The receiver verifies the peer is paired, maps
(peer, ref_id, index) to a pending request (waiting up to 10 s for the control
frame if it arrived first), enforces the announced size, writes to a temporary
file and renames on completion. At most four concurrent streams per peer;
TransferProgress for UI; TransferCancel for reasons. StreamOpen gains
name and mime hints and a new purpose MEDIA. Both implementations expose a
small “stream manager” (Rust tether-core::streams, Kotlin
transport/StreamManager.kt) used by messages, files and photos alike.
Consequences
Positive
- Control traffic stays responsive during transfers; a stalled transfer cannot kill the session.
- Zero extra framing; GiB-scale files are fine.
- Cancelling is closing a socket; resumption can be added later with an offset field without breaking receivers.
Negative / risks
- One TLS handshake per file (≈ 2 round trips on LAN); negligible for the file counts involved.
- Both sides must accept connections while running; the phone’s listener is already up with the foreground service, so phone → desktop and desktop → phone both work. Behind a relay (M5) streams will need the same path the control connection uses; ADR-0010 keeps transport path-agnostic.
- The out-of-order arrival window (10 s) is a small amount of state per peer.
Alternatives considered
Options 1 and 3 above. Option 1 was rejected for head-of-line blocking; option 3 for complexity that Milestone 2 does not need.