Skip to main content

Module io

Module io 

Source
Expand description

Typestate request/response pipeline (see docs/typestate_plan.md).

This is the live dispatch path: every SMB2 command the server answers is decoded into a typed request (SmbRequest), moved into its owning Command handler, and resolved to an Outcome. smb2::process_single routes each command code here through via_typestate and then applies the shared framing/crypto stage (pre-auth hash, signing, sealing) common to all commands.

Dispatch is static (a concrete match + monomorphic calls); the only dynamic seam in the server is the transport, deliberately (see the plan’s §12/§13).

Modules§

context 🔒
The IoContext typestate and the Command handler trait.
decode 🔒
Decode adapters over the existing smb-server-proto-smb2 request parsers. Each is a thin, zero-copy bridge: the frame is borrowed and the parser’s None (malformed) becomes STATUS_INVALID_PARAMETER.
origin 🔒
Origin of an IoContext: whether it was triggered by a client request or by a server event, which decides if it carries a request payload and how its reply header is filled.
request 🔒
The command table (single source of truth) and the commands migrated onto the typestate pipeline so far. Phase 0 wires only ECHO end to end to prove the machinery; later phases add one line per command here.
state 🔒
Lifecycle states of an IoContext.
wire 🔒
Wire codecs and the response value: Decode (frame → typed request), Encode (typed body → bytes), and the SmbResponse/ReplyHeader a handler produces. Every response — solicited, interim, or unsolicited — is serialized through one place so signing/sealing lives in a single site.

Macros§

io_states 🔒
Generate the data-less lifecycle state markers: a zero-sized struct plus its sealed IoState impls. States that carry data (e.g. Pending) are written by hand because they have fields.
smb_dispatch 🔒
Static, monomorphic dispatch to command handlers. Generated separately from the request table so the two concerns stay decoupled; the _ arm is unreachable now that every decodable command has a handler, but is kept so a future table-only addition still compiles.
smb_request_table 🔒
The command table: the single source of truth mapping an SMB2 command code to its request type. Generates SmbRequest, SmbRequest::command, and SmbRequest::parse, so a decodable command is one line and cannot desync.

Structs§

Accepted
Accepted request-lifecycle state marker (zero-sized).
Bare
A request-neutral context: the request has been split out to its handler, so the context carries only the shared bits and the reply header.
Completed
Completed request-lifecycle state marker (zero-sized).
EchoCmd
ECHO handler: a keep-alive, always answered SUCCESS ([MS-SMB2] §3.3.5.17).
EchoReq
SMB2 ECHO request ([MS-SMB2] §2.2.28): no meaningful body.
IoContext
The server’s work item for one request (or one server event). Owns the reply header and — while Solicited — the parsed request; parameterized by the lifecycle state S and origin O.
Pending
Deferred (STATUS_PENDING) state: an interim reply was sent and the final reply is owed. Carries the async correlation id so it is only reachable once a request has actually been deferred — you cannot complete work that was never parked.
ReplyHeader
The header fields a reply echoes or sets, captured when the context is built.
Resources
Per-request access to the mutable connection and shared server state a handler needs. Borrowed for the duration of one dispatch on the connection’s single thread, so no locking is required for the per-connection half.
SealIntent
Whether a response must be signed and/or sealed. Computed once at accept from the session/request so it is never threaded by hand.
SmbResponse
A finished response: the status, the header it replies under, and the encoded body. Solicited, interim, and unsolicited replies all converge on this type.
Solicited
Triggered by a client frame; carries the parsed SmbRequest and echoes the client’s MessageId/SessionId/TreeId on reply.
Unsolicited
Triggered by a server event (oplock/lease break, CHANGE_NOTIFY cleanup); has no request, and header fields are server-chosen ([MS-SMB2] §3.3.4.6).

Enums§

Outcome
The result of serving one accepted request. Encodes the final-vs-interim distinction in the type system.
SmbRequest
Sum type over every client request the server decodes (generated).

Traits§

Command
One command’s server-side behaviour: map its owned request to an Outcome, using the connection/server Resources. Dispatched by a concrete match (never as a trait object), so it uses native async fn and needs no boxed future.
Decode
Decode one single-command SMB2 frame into a typed request. Implemented per command; dispatched statically by SmbRequest::parse.
Encode
Serialize a typed response body against a reply header.
IoState
A lifecycle state marker for an IoContext. Sealed: the set of states is closed to this crate.
Origin
Where an IoContext came from. Sealed: the set of origins is closed to this crate. Request is the owned payload the context carries (() when there is none).

Functions§

dispatch
Serve a request by moving it into its owning handler (generated).