garage44.eu/jeroen/cartopolis

logclone: git clone https://garage44.eu/jeroen/cartopolis.git

.. /docs/adr/008-network-transport-layer.md

raw

ADR-008: Network Transport Layer (v0)


Metadata:


Context

Problem: Client and simulation processes (ADR-007) need a reliable, debuggable byte pipe for application messages (ADR-009).

Requirements:

Decision

Use TCP with length-prefixed frames (little-endian u32 length + payload) as the v0 transport between cartopolis_simulator and cartopolis.

Approach:

Rust ecosystem (preferred stack):

Rationale

Primary Reasoning:

  1. Reliability: World snapshots and ordered setup match TCP semantics for v0.
  2. Simplicity: No custom ACK layer in the first iteration.
  3. Framing: Same spirit as discrete messages in TundraMessages.h (opcode lives inside payload per ADR-009).

Alternatives Considered:

AlternativeProsConsRejected Because
UDP + custom reliabilityLower latencyMore codeDefer until profiling says TCP is bottleneck
QUIC (quinn)Modern, built on tokioHeavier dep for v0Revisit when TLS + NAT traversal matter
WebSocket v0 (tokio-tungstenite)Browser-friendlyExtra framing + deps in simDefer to dedicated gateway ADR

Consequences

Positive:

Negative:

Transport evolution (TCP+TLS → QUIC)

Decided path, so the trigger is on record before auth (ADR-016) builds on it:

  1. v0 — TCP + TLS. tokio-rustls wraps the stream; TLS 1.3 is ~free (1-RTT handshake, ~22 B/record, AES-NI crypto). TLS is not the efficiency cost — TCP head-of-line blocking under packet loss is, and it only bites at entity_count × update_rate × loss_rate, all small for a capacity-bounded sim. Fine for loopback/LAN/healthy internet.
  2. Envelope tags reliability class per message kind (ADR-009) now, at no cost: ClientIntent/WorldSnapshot = unreliable-capable (latest-wins, obsolete on supersede); prim CRUD / chat / textures = reliable-ordered. This is the seam that lets the position stream move off TCP later without touching message defs.
  3. Instrument observed RTT + loss. That measurement — not a guess — is the trigger.
  4. When loss-latency bites → QUIC (quinn). Independent streams (no cross- stream HoL), unreliable datagrams (RFC 9221) for the position stream, TLS 1.3 intrinsic (retires the TLS question) — a standardised transport, so we do not hand-roll UDP reliability.

Bigger efficiency levers come first and are transport-agnostic: AoI (have it), delta/dirty-field updates (ADR-011), position/rotation quantization. Transport is not where the efficiency story starts.

Related