Skip to main content

Module net

Module net 

Source
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§

AdverseDetector
The behavioral adverse detector: a deterministic sliding-window state machine over recent transfer outcomes.
AdverseThresholds
Tunable thresholds for behavioral ConnectionClass::Adverse promotion. Not protocol surface — a client picks values to match its network posture.
ExchangeProgress
The progress of one request, shared between the body that sends it, the code that reads its response, and within_bounds that watches both. Cheap to clone: every clone is the same progress.
LaneRetries
A LaneRetryBudget shared 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.
LaneRetryBudget
One server lane’s shared retry budget (networking doc, Retry Policy Classes: “each server lane holds one shared retry budget”).
PacedBody
A request body sent in PACED_PIECE pieces, recording each piece the HTTP stack pulls in an ExchangeProgress.
PathSignals
The mocked OS path signals a platform samples to classify the current link.
RequestBounds
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.
RetryEngine
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 after max_retries — never an unbounded hot loop.
RetryPolicy
The concrete parameters of a RetryClass: a bounded retry count and the exponential-backoff envelope. max_retries is 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”).
StallConfig
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.
StallDetector
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 (never sleep), so the “cut within its bound” behavior is fully deterministic under test.
SystemClock
The production monotonic clock (a process-relative Instant).
TokioSleeper
The production sleeper (tokio::time::sleep).

Enums§

ConnectionClass
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_effort did to a socket. Every outcome leaves the socket usable: marking is a courtesy to other traffic, never a condition of the transfer.
ReconciliationClass
The size class of a pending reconciliation (sync criteria). Scales with the total upload + download transfer amount.
RequestCut
Why a request was cut.
RetryClass
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.
RetryDecision
The engine’s decision after one failure.
RetryVerdict
What one failed request permits, decided before any retry is taken (networking doc, Retry Policy Classes: “errors are classified before any retry”).
TransferSignal
An observed transfer outcome, fed to the AdverseDetector. A reset, stall, or black-hole counts toward adverse; a clean completion counts toward demotion.

Constants§

ADVERSE_RANGE_WINDOW
The bounded Range window (256 KiB) a blob fetch shrinks to under ConnectionClass::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_DSCP as 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 PacedBody hands the HTTP stack: 16 KiB.

Traits§

MonotonicClock
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 reqwest client 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 ring the 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 reqwest has no default features and only rustls), 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 reqwest client.
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’s rustls would otherwise consult the OS store instead.
within_bounds
Drive exchange while progress keeps moving inside bounds; cut it when it does not.