Expand description
Connection-class and retry-policy contract types (SSoT: the Network
Resilience design doc). Detection (OS signals + behavioral promotion to
ConnectionClass::Adverse) and the per-class retry engines
live here: class detection feeds the sync and cache budgets, and the adverse class hardens
the network behaviour.
This module fills the capsule-sdk::net seam named by the networking doc:
it maps mocked OS path signals (PathSignals) to a base
ConnectionClass, layers the behavioral adverse promotion/demotion
(AdverseDetector) on top, and exposes the two gate surfaces the class
feeds — the staged-upload tier gates (ConnectionClass::permits_tier,
over the canonical UploadTier) and the cache-eviction byte budget
(ConnectionClass::cache_retention_budget, which crate::cache_budget feeds to the
eviction sweep). Detection is signal-driven,
never a live NIC probe, so every rule is a deterministic unit test.
Modules§
- h3
- The opportunistic HTTP/3 policy (networking doc, HTTP Transport).
- negotiation
- The response half of the protocol handshake, read on every call (issue #674).
- path
- The normalized path snapshot and the pure transfer plan (networking doc, Path Snapshot).
Structs§
- Adverse
Detector - The behavioral
adversedetector: a deterministic sliding-window state machine over recent transfer outcomes. - Adverse
Thresholds - Tunable thresholds for behavioral
ConnectionClass::Adversepromotion. Not protocol surface — a client picks values to match its network posture. - Exchange
Progress - The progress of one request, shared between the body that sends it, the code that reads its
response, and
within_boundsthat watches both. Cheap to clone: every clone is the same progress. - Lane
Retries - A
LaneRetryBudgetshared by everything that retries against one server: every clone is the same budget. The upload queue holds one per lane and hands it to the upload client that drives the lane’s sessions, so the queue’s requeues and the client’s request retries spend from one pool. - Lane
Retry Budget - One server lane’s shared retry budget (networking doc, Retry Policy Classes: “each server lane holds one shared retry budget”).
- Paced
Body - A request body sent in
PACED_PIECEpieces, recording each piece the HTTP stack pulls in anExchangeProgress. - Path
Signals - The mocked OS path signals a platform samples to classify the current link.
- Request
Bounds - The two bounds every request runs under: the stall bound while bytes should be moving — sending the request body, or receiving the response body — and the longer response-wait bound between the last request byte and the response head.
- Retry
Engine - The one shared retry engine every retrying surface instantiates
(
RetryClass::engine). It owns the universal rules so no surface re-derives them: exponential backoff with full jitter, honoring a server backoff signal (Retry-After/ 429 / 503) as a floor, and a bounded give-up aftermax_retries— never an unbounded hot loop. - Retry
Policy - The concrete parameters of a
RetryClass: a bounded retry count and the exponential-backoff envelope.max_retriesis finite by type, so no policy — and therefore no surface instantiating one — can ever hot-loop (networking doc: “every retry loop has a bounded give-up”; “no surface ever hot-loops”). - Stall
Config - The stall bound: bulk transfers cut on no-bytes-for-T, not on a total duration (networking doc, “Stall detection over total timeouts”). Client-tunable.
- Stall
Detector - The no-bytes-for-T stall detector: tracks the last time bytes arrived and
reports when the gap since then has crossed the stall bound. Event-driven over
an injected
MonotonicClock(neversleep), so the “cut within its bound” behavior is fully deterministic under test. - System
Clock - The production monotonic clock (a process-relative
Instant). - Tokio
Sleeper - The production sleeper (
tokio::time::sleep).
Enums§
- Connection
Class - The closed connection-class enum, evaluated continuously on-device. Consumers: sync criteria (small/large reconciliation), staged-upload tier gates, the cache-eviction byte budget, prefetch, adaptive chunk sizing.
- Marking
- What
mark_lower_effortdid to a socket. Every outcome leaves the socket usable: marking is a courtesy to other traffic, never a condition of the transfer. - Reconciliation
Class - The size class of a pending reconciliation (sync criteria). Scales with the total upload + download transfer amount.
- Request
Cut - Why a request was cut.
- Retry
Class - The three retry policy classes every retrying surface instantiates. Universal rules (owned by the Network Resilience doc): exponential backoff with full jitter, honor server backoff signals, bounded give-up surfaced to the user, never hot-loop.
- Retry
Decision - The engine’s decision after one failure.
- Retry
Verdict - What one failed request permits, decided before any retry is taken (networking doc, Retry Policy Classes: “errors are classified before any retry”).
- Transfer
Signal - An observed transfer outcome, fed to the
AdverseDetector. A reset, stall, or black-hole counts towardadverse; a clean completion counts toward demotion.
Constants§
- ADVERSE_
RANGE_ WINDOW - The bounded
Rangewindow (256 KiB) a blob fetch shrinks to underConnectionClass::Adverse. Small enough that a single window usually completes between the mid-transfer resets that define an adverse path; client-tunable policy, not protocol surface. - DEFAULT_
LANE_ RETRY_ BUDGET - The retries one server lane may take while nothing succeeds. Twice an upload’s own recovery cap, so a single item’s attempt cap binds before the lane’s budget does and the budget only bites when several items fail against the same server.
- DEFAULT_
RESPONSE_ WAIT - How long a request waits for its response once its body is fully sent: one minute.
- DIAL_
CONNECT_ TIMEOUT - A bounded per-address TCP connect timeout applied at dial. Keeps a dead path from hanging a connect indefinitely on an adverse network.
- LANE_
SUCCESSES_ PER_ RETRY - Successes that earn one retry back, up to the budget’s capacity. Two bounds the retries a steadily working lane adds to half its successful requests.
- LOWER_
EFFORT_ DSCP - The Lower Effort per-hop behaviour’s DSCP (RFC 8622),
000001: traffic that yields to every other class wherever a network honours the field (networking doc, Packet Marking). - LOWER_
EFFORT_ TRAFFIC_ CLASS LOWER_EFFORT_DSCPas the whole IPv4 TOS / IPv6 traffic-class octet: the six DSCP bits above the two ECN bits, which stay clear for the kernel’s TCP to manage.- PACED_
PIECE - The size of one piece a
PacedBodyhands the HTTP stack: 16 KiB.
Traits§
- Monotonic
Clock - A monotonic millisecond clock, injectable so the stall detector’s cut is a deterministic test (a mock clock the test advances) rather than a wall-clock sleep.
- Sleeper
- How a retry/stall loop performs its backoff wait. Abstracted so the wait is
real in production (
TokioSleeper) but a deterministic no-op in tests — the stall-cut-resume smoke asserts zero duplicate bytes with no wall-clock sleep.
Functions§
- dial_
client - Build the
reqwestclient the upload/fetch paths dial with: rustls, a bounded connect timeout, and the HTTP stack’s built-in Happy Eyeballs v2 at dial. - ensure_
crypto_ provider - Make
ringthe process’s rustls crypto provider, unless the embedding application already installed one — which is then respected. - http_
builder - The builder every SDK transport starts from: rustls only (the SDK’s
reqwesthas no default features and onlyrustls), the bundled webpki roots as the only trust anchors (trust_roots), and the protocol handshake as default headers. - http_
client - The plain SDK client:
http_builder, built. - mark_
lower_ effort - Mark a bulk-transfer socket the SDK holds with the Lower Effort DSCP, best effort.
- protocol_
headers - The request half of the protocol handshake, as default headers for a
reqwestclient. - trust_
roots - The trust anchors every SDK reqwest client verifies a server against: the bundled Mozilla
root set (
webpki-root-certs), the same release of the same bundle the HTTP/3 leg trusts, so a server is trusted or refused alike over TCP and QUIC. reqwest 0.13’srustlswould otherwise consult the OS store instead. - within_
bounds - Drive
exchangewhileprogresskeeps moving insidebounds; cut it when it does not.