Skip to content

Latest commit

 

History

History
40 lines (34 loc) · 11.2 KB

STATE-MACHINES.md

File metadata and controls

40 lines (34 loc) · 11.2 KB

Wind runtime state machines

This index covers the 13 crates in the Cargo workspace. Each row identifies the component that owns a transition. On a single connection, sending, receiving, and authentication can progress independently. To trace a stalled connection, identify which event the caller is waiting for and which component should produce it.

Connections and streams

Owner Transitions and observable behavior
Bidirectional TCP relay · CopyPhase Each direction cycles independently through Reading → Writing → Reading. A short write preserves the offset for the next write. EOF starts ShuttingDown → Done for that direction. Once either reader sees EOF, the half-close timer covers stalls in both directions. Progress in either direction resets the timer.
quiche handshake · HandshakeState Negotiating owns the connection handle and the one-shot sender that delivers it. The handshake callback runs the configured ECH checks and records the negotiated parameters before entering Established. On close, the driver saves the final traffic counters before waking callers waiting on closed().
quiche receive half · ReceivePhase Open transitions to FinPending or ResetPending(code). The reader receives buffered data before either terminal event. A reset code needs a channel slot, so the driver retains it until the reader frees one. Dropping the sender lets the reader observe EOF.
quiche send half · SendPhase A stream without a local sender starts in Absent. A graceful close follows Open → Draining → Finished, attempting FIN after queued data drains. An explicit RESET goes directly to Failed. A write error enters FailedPendingFin, which permits cleanup and a best-effort FIN. When the buffer fills, the driver pauses polling the receiver and resumes after the buffer drains.
HTTP/3 adapter and prefix replay H3Send.pending holds a partially written frame. The adapter finishes the frame before accepting another and flushes the underlying writer before finishing the stream. Opening unidirectional and bidirectional streams uses separate in-flight futures. On receive, PrefixedRecv replays the bytes consumed during protocol classification before reading the underlying stream.
Quinn shared UDP socket On selected peer network errors, retry holds a timer. The socket resumes receiving when the timer expires. Local socket errors propagate to the caller.
TUIC server authentication · AuthState The connection admits up to three Authenticate commands within the original deadline. In Pending, it checks them in admission order and discards excess commands. An unknown user or wrong token consumes one attempt. The first two failures allow a retry. The third closes the connection. Success publishes Authenticated(user), wakes waiting requests, and discards queued attempts. A new Authenticate after success, a TLS error, or an admission veto closes the connection. On disconnect, Closed preserves any published identity for the disconnect hook and prevents late registration.
TUIC stream classification and shutdown and HTTP/3 masquerade A stream prefix selects TUIC or HTTP/3. Routing the first HTTP/3 stream moves the shared H3Phase from Parked to Active. Both the HTTP/3 service and the authentication timeout check observe this state. Cancelling the connection stops its accept loops and child tasks.
TUIC client session · Quinn and quiche The session starts after the client connects and sends authentication. A successful heartbeat clears the failure count. The third consecutive failure or a closed connection produces Lost. Shutdown ends the supervisor. When reconnection is enabled, the supervisor dials again, applies capped backoff after failures, and publishes the replacement only after a successful dial. quiche also caches session tickets.
SOCKS5 inbound and command replies Socks5ServerProtocol types enforce the order of handshake, authentication, and command parsing. An accepted request starts a TCP relay or a UDP association. Closing the TCP control connection ends the corresponding UDP session.
SOCKS5 inbound UDP peer The client IP is preset or pinned by the first observed datagram. Only a valid, unfragmented datagram within the size limit sets the reply address. Until then, replies have no destination. Later valid datagrams from the same IP can update the port.
SOCKS5 UDP outbound · AssociationState Initial negotiation errors return to the caller. Losing an established association either ends it or enters Reconnecting, according to configuration. Packets arriving during backoff or negotiation are discarded. Successful negotiation returns the association to Relaying. Closing the input ends retries. Cancellation or loss of the reply receiver ends the association.
Naive TCP and UDP over TCP Later connections reuse the first Cronet library the process loads successfully. Each TCP direction forwards data and half-closes independently. UDP over TCP waits for the first datagram before opening CONNECT, then writes the request header and forwards packets. CancelOnDrop propagates cancellation to the native stream. JoinSession hands threads that still need joining to a cleanup task.

Application, routing, and resources

Owner Transitions and observable behavior
Application configuration and plugin construction Wind resolves the persisted configuration into its runtime form. A load-balancing group enters the build queue once its dependencies are ready. A missing dependency or a cycle fails startup. The first outbound in declaration order is the default.
Application and inbound lifecycle and RunningInbound After building and starting the inbounds, the application waits for a signal or cancellation. It then cancels child tasks and waits up to the shutdown deadline. Each listener has an owner as soon as it starts, so an interrupted build releases listeners already running.
Traffic reporting and FlushOutcome A reporter atomically claims the right to drain the counters. An empty batch yields Idle. A successful submission yields Delivered. A failed submission restores the batch and yields Restored. During shutdown, the reporter makes a bounded number of attempts to submit a restored batch.
Active connections Registration increments the user's connection count. Kicking a connection requests cancellation. The count drops when the connection deregisters. Reusing a connection ID transfers the count to the new registration.
UDP dispatch, tunnel, and direct outbound The dispatcher waits for the first packet, selects an outbound, and replays that packet before forwarding subsequent traffic. The tunnel uses a fixed peer or maintains per-peer sessions according to its binding mode. The direct outbound's send and receive loops share a session lifetime. Either loop exiting stops the other.
Lazy outbound and load balancing LazyState holds the initialization future, the ready outbound, or a permanent failure. If the first caller cancels, the next caller can resume the same future. HealthChecks records whether checks are enabled. The first start creates a single probe task. Dropping the outbound cancels the task and any active probes. If all children are unhealthy, routing falls back to the full set.
TUIC server UDP sessions and fragment reassembly The cache owns each new association. Dissociation, eviction, or connection shutdown cancels its tasks. A FragmentGroup is keyed by association ID and packet ID. Only a previously unseen fragment index reduces the missing count. A duplicate replaces the contents of its slot. Once complete, the group is removed under the lock and assembled outside it. Expiry or capacity pressure can evict an incomplete group.
TUIC client UDP association and transport selection RegisteredAssociation atomically reserves an unused 16-bit ID and retains the connection on which it registered. Channel closure, a send error, or cancellation ends forwarding. Cleanup attempts to send Dissociate on the original connection before releasing the ID. If the caller goes away, cleanup allows up to five seconds for the notification. Global shutdown can end the wait immediately. The relay mode and peer capabilities determine whether packets use datagrams or unidirectional streams.
ACME resolver and file-backed HTTP-01 The resolver follows rustls-acme events. File-backed consumers can provision once with ensure_acme_cert or subscribe with watch_acme_cert. The watcher supplies an initial pair, checks daily, renews within 30 days of expiry, and retries errors after one hour. Only complete, matching pairs are published. Dropping the last receiver stops the watcher and closes any pending HTTP challenge listener.
quiche certificate rotation CertStore::update parses the new certificate and key before publishing them atomically. If parsing fails, handshakes continue using the previous certificate.
ACL evaluation and rules Resolution distinguishes forwarding, rejecting, dropping, returning from a chain, and exhausting its rules. The calling chain uses the result to continue evaluation or select a final route. Rule matching reads the current request's context.
DNS and geodata snapshots Hickory drives DNS queries. Wind handles IP literals and address-family selection. The geodata builder writes a separate temporary file, renames it, maps it into memory, and validates it before making the snapshot available for queries.

Cross-crate data-plane tests live in wind-test. Individual transitions have regression tests alongside their implementations, including SOCKS5 reply address selection and closing the input during UDP reconnection.