Status: Accepted
Date: 2026-11-29 (proposed 2026-11-27; verified across LAN and cross-region cloud WAN in v0.1.0-rc.18)
Context
Under the original peer relay design, even when two Agents sat on the same LAN or behind traversable NATs, all peer payloads traversed the Server's data port, bottlenecking high-bandwidth workloads such as RDP or bulk transfers on Server egress and RTT. Conversely, requiring pure direct P2P without fallback would break connectivity behind symmetric NATs, UDP-blocked egresses, or restrictive enterprise firewalls.
Decision
Introduce optional P2P prefer-direct transport with automatic same-mode relay fallback for authorized (authorizedClientsOnly=true) raw TCP and unicast UDP channels (applicationProtocol="raw"):
- Conservative default: Channels default to
peerRoutingPolicy = "relayOnly". Direct candidate discovery and probing run only when an administrator explicitly opts in to"preferDirect"on eligible raw TCP/UDP channels (HTTP/HTTPS and automation loopback channels remain locked to"relayOnly"). - Dual paths preserving channel encryption semantics:
- Encrypted channels (default) establish QUIC 1.3 over the shared UDP socket (0-RTT business data disabled) with pinned target SHA-256 certificate validation and HMAC-SHA256 access proofs; unreachable attempts fall back strictly to inner-TLS relay.
- Explicitly unencrypted channels (
endToEndEncryptionEnabled=false) establish mutually authenticated ICE-TCP direct connections (ephemeral bind-key challenge + channel access proof); unreachable attempts fall back strictly to plaintext relay (ADR-0016).
- Reliable stream contract: Both QUIC and ICE-TCP direct paths carry reliable streams—raw byte streams with half-close for TCP, and 4-byte big-endian length-framed datagrams (
0–65507bytes,32-datagram queue per source,udpIdleTimeoutSecondscleanup) for unicast UDP. Pre-grant fallback is allowed only upon mutually confirmed reachability failure without auth errors; auth or policy errors abort immediately. Bytes or datagrams are never replayed across paths. - Allowlisted probes, cross-session budgets, and suspend-aware lease recovery: Agents validate normalized IP literals (unmapping IPv4-mapped IPv6), site allowlists, and cross-connection peer/destination-IP budgets before sending any probe packet. Ready receipts bind to a single authenticated transport connection, target dials wait for dual lease confirmation and control-TLS readiness, Agents use suspend-inclusive monotonic clocks, and the Server persists
direct_lease_occupancyin SQLite before first-lease grant to enforce conservative full-lease recovery across restarts (DES-011).
Alternatives Considered
| Alternative | Tradeoff |
|---|---|
| Keep Server-only relay everywhere | Maximum compatibility and immediate Server-side socket teardown, but concentrates all peer bandwidth on the relay host; retained as the relayOnly default |
| Require direct P2P with no fallback | Breaks peer access whenever UDP is blocked or both ends sit behind symmetric NATs |
| Force QUIC even for plaintext channels | QUIC mandates transport encryption, contradicting the explicit channel encryption toggle (endToEndEncryptionEnabled=false); supporting ICE-TCP preserves plaintext semantics at the cost of verifying a second direct transport |
| Deploy a separate TURN relay | Adds standard ICE relay candidates, but introduces separate allocation, credential, and ops complexity compared to reusing RelayLink's audited, quota-enforced Server TCP relay |
Use QUIC DATAGRAM frames for unicast UDP |
Avoids intra-stream head-of-line blocking, but .NET 10 System.Net.Quic lacks public DATAGRAM APIs and imposes path-MTU framing limits; reliable streams preserve the existing 65507-byte contract for phase 1 |
| Persist every lease renewal timestamp to SQLite | Could shorten post-restart quota hold times, but adds disk writes on the renewal hot path and cross-clock risks; freezing max lease duration at first grant keeps recovery simple and safe |
Consequences
- Endpoint-enforced teardown: Direct sessions still depend on Server authorization, SQLite audit gating, and control sessions, but active teardown moves from Server sockets to endpoint revocation (
PeerDirectRevoke) bounded by finite lease ceilings (leaseDurationSeconds) during silent control partitions. Direct byte accounting relies on caller-reported deduplicatedreportSeqtelemetry. - Platform and security boundaries: Linux encrypted QUIC direct transport requires native
libmsquic(auto-downgradingpeerDirectQuicReadytofalsewhen absent while leaving relay and plaintext ICE-TCP available). Plaintext direct mode exposes unencrypted payloads to on-path observers and active attackers, inheriting ADR-0016's trusted-network deployment boundary. - Existing invariants remain binding: Governed by connection revocation (ADR-0009), client-level E2E identity pinning (ADR-0011), and the SQLite start-audit gate (ADR-0013).