Repository navigation
feat(node): QUIC 0-RTT for cdn/probe/v1 (#325, ADR 015) - #576
Conversation
Implements 0-RTT connection establishment for the cdn/probe/v1 ALPN so a
warm probe skips the TLS 1.3 handshake round trip, per ADR 015.
iroh 0.98.2 differs from ADR 015's original assumptions, so the ADR was
rewritten to match reality (CLAUDE.md: ADRs are source of truth):
- Session-ticket storage is iroh/rustls-owned, sized via
Endpoint::builder().max_tls_tickets(SESSION_TICKET_CACHE_SIZE) — no
hand-rolled (node_id, ALPN) LRU. New shared const in decdn-protocol is
the single source of truth for the cache size and the gauge ceiling.
- Per-ALPN 0-RTT gating is structural: only ProbeHandler overrides
on_accepting; cdn/client/v1 and cdn/dht/v1 keep the default
full-handshake path. Master switch network.enable_0rtt (default true,
restart-required) falls back to the pre-ADR-015 1-RTT path.
Components:
- Reusable client helper crates/cli/src/commands/probe_client.rs
(connect_with_opts → into_0rtt → accepted/rejected fallback + bounded
ticket linger), consumed by `decdn probe`; structured for the future
node cache-miss probe loop to reuse.
- ProbeHandler.on_accepting accepts 0-RTT (gated) and feeds the
approximate decdn_quic_session_ticket_cache_size gauge.
- Metrics: decdn_quic_0rtt_{attempts,accepted,rejected}_total counters +
the session-ticket gauge (distinct-peer upper bound, saturating).
- Config: network.enable_0rtt plumbed through types/resolved/resolver.
Tests: deterministic 0-RTT accepted, rejected-fallback (same-key server
restart), master-switch-off, config resolution, metrics. Existing 1-RTT
loopback suite preserved (enable_0rtt=false). Typed AcceptError chain
preserved on the server 0-RTT path. 566 tests pass; clippy/fmt/deny/doc
clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements QUIC 0-RTT support for the cdn/probe/v1 protocol as specified in ADR 015. The changes introduce a reusable probe client with 0-RTT attempt and fallback logic, update the probe handler to support early data, and add a master configuration switch to enable or disable the feature. Additionally, new metrics have been added to track 0-RTT success rates and approximate session ticket cache size. Feedback was provided regarding a potential memory leak in the metrics tracking logic, where the set of unique peers could grow without bound; a suggestion was made to cap the set size to prevent resource exhaustion.
There was a problem hiding this comment.
Pull request overview
Implements ADR 015's QUIC 0-RTT path for cdn/probe/v1. A reusable client helper attempts 0-RTT early-data when a TLS session ticket is cached and falls back transparently to 1-RTT on rejection; the probe handler opts in server-side via on_accepting → into_0rtt, gated by a new network.enable_0rtt master switch. ADR 015 is rewritten to match iroh 0.98's actual API (no connect_with_0rtt, rustls-owned ticket store), and four new metrics surface 0-RTT activity.
Changes:
- Add
probe_client::probe_oncehelper (0-RTT attempt, accepted/rejected classification, 1-RTT fallback, bounded post-exchange linger) and routedecdn probethrough it. - Add
ProbeHandler::on_acceptingto accept 0-RTT whenenable_0rttis set, and wire thenetwork.enable_0rttconfig anddecdn_quic_0rtt_*/decdn_quic_session_ticket_cache_sizemetrics. - Rewrite ADR 015 to reflect the real iroh/rustls API; add a shared
SESSION_TICKET_CACHE_SIZE = 1000const and use it formax_tls_tickets(..)and the gauge ceiling.
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/protocol/src/lib.rs | New shared SESSION_TICKET_CACHE_SIZE constant. |
| crates/cli/src/commands/probe_client.rs | New reusable 0-RTT probe client (probe_once, ProbeMetrics). |
| crates/cli/src/commands/probe.rs | decdn probe now delegates to probe_once; sizes endpoint ticket cache. |
| crates/cli/src/commands/mod.rs | Export the new probe_client module. |
| crates/cli/tests/config_validate.rs | Include enable_0rtt in test fixtures. |
| crates/common/src/config/types.rs | Add enable_0rtt: Option<bool> to NetworkConfig. |
| crates/common/src/config/resolved.rs | Add enable_0rtt: bool to ResolvedNetwork. |
| crates/common/src/config/mod.rs | Default + resolution for enable_0rtt; unit tests. |
| crates/node/src/handlers/probe.rs | Add enable_0rtt field and on_accepting 0-RTT override. |
| crates/node/src/metrics.rs | New 0-RTT counters + distinct-peer gauge with saturation. |
| crates/node/src/runtime/mod.rs | Pass enable_0rtt into ProbeHandler; size endpoint ticket cache. |
| crates/node/src/runtime/reload.rs | SIGHUP message mentions enable_0rtt; test fixtures updated. |
| crates/node/tests/probe_0rtt.rs | New 0-RTT integration tests (accepted/disabled/rejected-fallback). |
| crates/node/tests/probe_loopback.rs | Thread enable_0rtt = false into existing 1-RTT harnesses. |
| crates/node/tests/sighup_signal.rs | Include enable_0rtt in seeded ResolvedConfig. |
| crates/node/Cargo.toml | Add decdn-cli dev-dependency (cycle is dev-only). |
| Cargo.toml / Cargo.lock | Workspace dep entry for decdn-cli. |
| adr/015-zero-rtt.md | Rewritten to match iroh 0.98 API; deferred-histogram + known-deviation notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 89.59% (was 89.02%, ▲ +0.57%) — 15928/17779 lines
History
|
note_session_ticket_peer is driven by the unauthenticated probe handler; the prior `.min(CEILING)` only saturated the gauge while the underlying HashSet grew per distinct node id — a slow memory-exhaustion vector since node ids are cheap to generate (Sybil). Cap the set itself at SESSION_TICKET_CACHE_CEILING: once full, new peers are no longer tracked and the gauge sits at the ceiling, still a valid upper bound on the rustls LRU (also capped there). Adds a regression test asserting the set length stays bounded under CEILING+50 distinct peers. Addresses gemini-code-assist review on #576. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Review round 2 surfaced findings; an added test empirically disproved a claim this PR introduced. - ADR/comment truth (CRITICAL): the "per-ALPN 0-RTT gating is structural via on_accepting / the QUIC stack drops early data for non-overriding handlers" claim is FALSE. iroh sets crypto.max_early_data_size=u32::MAX on every server TLS config, so 0-RTT is accepted for any ALPN regardless of handler. Real replay safety is client-side: probe_once is the only into_0rtt/early-data path and is hard-wired to ALPN_PROBE (idempotent). Rewrote ADR 015 §Server-Side Controls -> §"Replay Safety Is Client-Side", added a Consequences defense-in-depth-gap note, and corrected probe.rs/types.rs comments. New characterization test default_on_accepting_still_accepts_0rtt_safety_is_client_side pins iroh's real behavior so the model can't silently drift. - Cache conflation (multi-agent): max_tls_tickets sizes only the client-side rustls ClientSessionMemoryCache; the server store is rustls-internal default. Removed false "gauge is an upper bound on the real rustls LRU capped at CEILING" claims from metrics.rs, protocol const, runtime builder comment, ADR §Session Ticket Mgmt + §Observ. - Observability (silent-failure): added decdn_quic_session_ticket_peers_dropped_total so a Sybil-style saturation of the bounded peer set is distinguishable from organic growth; regression test asserts 50 drops at CEILING+50. 568 tests pass; clippy/fmt/doc/deny/markdownlint clean. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Follow-up from a second review pass (commit Security-model correction (important). An added test empirically disproved a claim this PR's ADR rewrite introduced: that per-ALPN 0-RTT gating is structural (only an ADR 015 §Server-Side Controls was rewritten to §"Replay Safety Is Client-Side", a defense-in-depth-gap note added to Consequences (no server-side barrier if a future non-probe client misbehaves), and Also fixed this round:
568 tests pass; clippy/fmt/cargo-doc/deny/markdownlint clean. |
Independent review — recommend approveDid a fresh deep review focused on the 0-RTT replay-safety model plus the config/reload plumbing. The hard part — reconciling ADR 015's draft assumptions with the real iroh 0.98.2 API — was handled honestly rather than papered over. The prior automated thread (unbounded Verified directly:
Findings — all explicitly non-blocking
None of these block merge. Clean code, honest ADR reconciliation, 568 tests green (+0.26% coverage). Generated by Claude Code |
# Conflicts: # crates/cli/src/commands/probe.rs # crates/node/src/handlers/probe.rs # crates/node/src/metrics.rs # crates/node/src/runtime/mod.rs # crates/node/tests/probe_loopback.rs
Address PR review of the #569↔#576 merge resolution: - probe_0rtt.rs: add warm_0rtt_serves_signed_has_blob_true, closing the one real coverage seam — the 0-RTT-accepted early-data response path carrying a verified EIP-712 slash_sig and has_blob:true was previously unexercised (every 0-RTT test used an empty cache + throwaway signer). Refactor spawn_server onto a shared spawn_core so the new test can use a blob-backed cache + known signer. - probe_client.rs: correct the probe_once / module docs — the response is returned without correlation/slash_sig validation (caller's job), but the Response-vs-Request variant check IS performed internally; note the reused mechanism is transport-only. - probe.rs: drop the misleading MAX_RATE_PER_MB parenthetical (that validate() branch is dead for wire-decoded responses; the serde hook enforces it at decode time) — slash_sig length is the only live check. - probe_0rtt.rs: spawn_server doc now documents the TempDir return guard; PROBE_HASH doc scoped to the empty-cache tests. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Closes #325.
Summary
Implements QUIC 0-RTT connection establishment for the
cdn/probe/v1ALPN (ADR 015) so a warm probe skips the TLS 1.3 handshake round trip on the cache-miss latency path. Payment (cdn/client/v1) and DHT (cdn/dht/v1) stay 1-RTT.iroh 0.98.2exposes 0-RTT differently than ADR 015's original draft assumed (noconnect_with_0rtt(), no per-ALPN TLS knob, rustls-owned ticket store). Per CLAUDE.md (ADRs are the source of truth), ADR 015 was rewritten to match the real iroh API rather than papering over the gap.What changed
decdn_protocol::SESSION_TICKET_CACHE_SIZE— single source of truth formax_tls_tickets(...)(all sites) and the gauge ceiling, so the gauge's "upper bound" invariant provably matches the real rustls LRU bound.crates/cli/src/commands/probe_client.rs::probe_once—connect_with_opts→into_0rtt→ accepted/rejected classification → 1-RTT fallback re-send → bounded post-exchange ticket linger. Consumed bydecdn probe; structured for the future node cache-miss probe loop.ProbeHandler::on_acceptingaccepts 0-RTT (gated by the master switch) and feeds the approximate session-ticket gauge; typedConnectingErrorchain preserved intoAcceptError. Per-ALPN gating is structural (only this handler overrideson_accepting).network.enable_0rtt(defaulttrue, restart-required) plumbed throughtypes/resolved/resolve_network.decdn_quic_0rtt_{attempts,accepted,rejected}_total+decdn_quic_session_ticket_cache_size(distinct-peer upper bound, saturating; rustls exposes no size API).Tests
New
crates/node/tests/probe_0rtt.rs: deterministic 0-RTT accepted, rejected-fallback (same-key server-restart, the technique from iroh's owntest_0rtt_after_server_restart), and master-switch-off. Plus config-resolution and metrics unit tests. Existing 1-RTT loopback suite preserved by threadingenable_0rtt=false.A multi-agent review (code, tests, comments, error-handling, type-design) was run and its Critical + Important findings addressed (deterministic rejection test, SIGHUP message, typed-error preservation, ADR/comment accuracy, const hoist).
Verification
cargo build✓ ·clippy --all-targetsclean ·fmt --checkclean · 566 tests pass (node/common/cli/protocol) · pre-commit (doc/deny/markdownlint) all green.Notes
decdn-nodedev-depsdecdn-clifor the integration test to reuseprobe_once; dev-deps are outside the library build graph).decdn probeis one-shot so its in-process ticket cache never warms across invocations — the mechanism exists for the node's future long-lived reuse and is exercised end-to-end by the integration tests.🤖 Generated with Claude Code