Skip to content

feat(node): QUIC 0-RTT for cdn/probe/v1 (#325, ADR 015) - #576

Merged
thiras merged 5 commits into
mainfrom
feat/325-quic-0rtt-probe
May 18, 2026
Merged

thiras merged 5 commits into
mainfrom
feat/325-quic-0rtt-probe

Conversation

@thiras

@thiras thiras commented May 16, 2026

Copy link
Copy Markdown
Contributor

Closes #325.

Summary

Implements QUIC 0-RTT connection establishment for the cdn/probe/v1 ALPN (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.2 exposes 0-RTT differently than ADR 015's original draft assumed (no connect_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

  • ADR 015 — §Session Ticket Management / §Server-Side Controls / §Observability reconciled with iroh reality; honest "known deviation" (dropped client-side 24h cap) and deferred-histogram notes.
  • Shared const decdn_protocol::SESSION_TICKET_CACHE_SIZE — single source of truth for max_tls_tickets(...) (all sites) and the gauge ceiling, so the gauge's "upper bound" invariant provably matches the real rustls LRU bound.
  • Reusable client helper 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 by decdn probe; structured for the future node cache-miss probe loop.
  • Server — ProbeHandler::on_accepting accepts 0-RTT (gated by the master switch) and feeds the approximate session-ticket gauge; typed ConnectingError chain preserved into AcceptError. Per-ALPN gating is structural (only this handler overrides on_accepting).
  • Config — network.enable_0rtt (default true, restart-required) plumbed through types/resolved/resolve_network.
  • Metrics — 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 own test_0rtt_after_server_restart), and master-switch-off. Plus config-resolution and metrics unit tests. Existing 1-RTT loopback suite preserved by threading enable_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-targets clean · fmt --check clean · 566 tests pass (node/common/cli/protocol) · pre-commit (doc/deny/markdownlint) all green.

Notes

  • Adds a Cargo-permitted dev-dependency cycle (decdn-node dev-deps decdn-cli for the integration test to reuse probe_once; dev-deps are outside the library build graph).
  • decdn probe is 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

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]>
Copilot AI review requested due to automatic review settings May 16, 2026 17:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread crates/node/src/metrics.rs Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_once helper (0-RTT attempt, accepted/rejected classification, 1-RTT fallback, bounded post-exchange linger) and route decdn probe through it.
  • Add ProbeHandler::on_accepting to accept 0-RTT when enable_0rtt is set, and wire the network.enable_0rtt config and decdn_quic_0rtt_* / decdn_quic_session_ticket_cache_size metrics.
  • Rewrite ADR 015 to reflect the real iroh/rustls API; add a shared SESSION_TICKET_CACHE_SIZE = 1000 const and use it for max_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.

@github-actions

github-actions Bot commented May 16, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 89.59% (was 89.02%, ▲ +0.57%) — 15928/17779 lines

File Coverage Lines Δ
crates/cli/src/commands/probe.rs 68.56% 133/194 ▲ +17.99%
crates/cli/src/commands/probe_client.rs 88.89% 104/117 new
crates/common/src/config/mod.rs 96.18% 3855/4008 ▲ +0.03%
crates/node/src/handlers/probe.rs 85.11% 160/188 ▲ +0.19%
crates/node/src/metrics.rs 81.40% 315/387 ▲ +3.84%
crates/node/src/runtime/mod.rs 51.01% 405/794 ▼ 0.63%
crates/node/src/runtime/reload.rs 95.72% 1297/1355 ▲ +0.23%
History
Commit Total Δ vs base
6c6e5fa 89.26% ▲ +0.24%
77b1918 89.27% ▲ +0.25%
bbc2952 89.29% ▲ +0.26%
d16680e 89.59% ▲ +0.57%
b0cda25 (HEAD) 89.59% ▲ +0.57%

thiras and others added 2 commits May 16, 2026 20:45
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]>
@thiras

thiras commented May 16, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up from a second review pass (commit bbc2952).

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 on_accepting override exposes early data; the QUIC stack drops it for non-overriding handlers). It is false — iroh sets crypto.max_early_data_size = u32::MAX on every server TLS config, so 0-RTT is accepted at the TLS layer for any ALPN regardless of handler. The feature is still correct/safe, but the mechanism is client-side: probe_once is the only code that calls into_0rtt()/emits early data and it is hard-wired to ALPN_PROBE (idempotent, replay-safe per ADR 015 §Replay Safety). No cdn/client/v1/cdn/dht/v1 client sends early data, so none can be replayed.

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 probe.rs/types.rs comments corrected. A pinned characterization test (default_on_accepting_still_accepts_0rtt_safety_is_client_side) now locks iroh's real behavior so the model can't silently drift.

Also fixed this round:

  • Client/server cache conflation (raised by multiple review agents): max_tls_tickets sizes only the client-side rustls cache; removed false "gauge is a provable upper bound on the real rustls LRU" claims from metrics.rs, the protocol const, the runtime builder comment, and ADR §Session Ticket Mgmt/§Observability.
  • Added decdn_quic_session_ticket_peers_dropped_total so a Sybil-style saturation of the bounded peer set is distinguishable from organic growth (the bound fix from 77b1918 was otherwise silent); regression test asserts it.

568 tests pass; clippy/fmt/cargo-doc/deny/markdownlint clean.

@thiras
thiras requested a review from alpergundogdu May 16, 2026 19:01

Copy link
Copy Markdown
Contributor

Independent review — recommend approve

Did 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 session_ticket_peers) is resolved correctly (set bounded at the ceiling + a *_dropped_total counter so Sybil saturation stays visible).

Verified directly:

  • Replay-safety model is correctly analyzed. iroh sets max_early_data_size = u32::MAX on every server TLS config, so the server accepts 0-RTT at the TLS layer for any ALPN regardless of handler. The real boundary is client-side: probe_once is the only code that calls into_0rtt(), hard-wired to ALPN_PROBE, sending an idempotent probe. Locked by the default_on_accepting_still_accepts_0rtt_safety_is_client_side characterization test, which breaks if iroh changes or a non-probe client starts emitting early data — the right tripwire.
  • Config/reload plumbing correct. enable_0rtt defaults true, file-only (intentional), and network.* changes (incl. enable_0rtt) are reported restart-required on SIGHUP.
  • Anti-panic clean — typed ConnectingError preserved into AcceptError (no to_string() flatten); no unwrap/expect/indexing.
  • Good test matrix: accepted, rejected-fallback (same-key server restart), switch-off, characterization.

Findings — all explicitly non-blocking

  1. Defense-in-depth gap for cdn/client/v1 / cdn/dht/v1 (non-blocking; out of this PR's probe-only scope). No server-side barrier against 0-RTT early data on the payment/DHT ALPNs — safety rests entirely on the convention that no non-probe client ever calls into_0rtt(). For the payment ALPN a future violation would be financially serious (replayed early-data). Honestly documented in ADR 015 Consequences and tripwire-tested, so fine here — recommend a tracked follow-up issue and considering a cheap shared on_accepting guard for non-probe handlers before payment 0-RTT is ever contemplated.

  2. Cross-PR collision with feat(probe): cdn/probe/v1 content-availability + EIP-712 slash_sig (#318) #569 (non-blocking; merge coordination). This PR builds on the old nonce ProbeRequest; feat(probe): cdn/probe/v1 content-availability + EIP-712 slash_sig (#318) #569 rewrites the same protocol to {hash, timestamp_us} + EIP-712 slash_sig + a cache eviction-hold side effect. Whoever merges second needs a non-trivial rebase of probe_client.rs/probe.rs/handlers/probe.rs. More substantively: ADR 015's "probe is idempotent / replay-safe" premise should be re-validated under feat(probe): cdn/probe/v1 content-availability + EIP-712 slash_sig (#318) #569 — a replayed 0-RTT probe would re-trigger an eviction hold and re-emit a signed slash_sig. It still looks safe (holds are budget-bounded/self-expiring; the signature is deterministic over client-supplied fields, so a replay yields identical bytes and grants no advantage), but the ADR 015 §Replay Safety argument should explicitly cover the post-feat(probe): cdn/probe/v1 content-availability + EIP-712 slash_sig (#318) #569 side effects rather than "read-only query."

  3. Gauge semantics (non-blocking; no action). note_session_ticket_peer counts distinct handshaked peers (cold included), not actual resumptions — a deliberate upper-bound approximation, now honestly documented after the earlier "provable upper bound on the rustls LRU" overclaim was removed. Sound as-is.

None of these block merge. Clean code, honest ADR reconciliation, 568 tests green (+0.26% coverage).


Generated by Claude Code

thiras and others added 2 commits May 19, 2026 00:57
# 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]>
@thiras
thiras merged commit e3a7cff into main May 18, 2026
13 checks passed
@thiras
thiras deleted the feat/325-quic-0rtt-probe branch May 18, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement QUIC 0-RTT for cdn/probe/v1 (ADR 015)

3 participants