Skip to main content

Module protocol

Module protocol 

Source
Expand description

Typed request/response protocol for the node-local cache daemon.

Deliberately not REST/format!()-built URLs: every message is a serde-serializable Rust enum. The wire framing is a small length-prefixed envelope ([len: u32 LE][body: JSON bytes]) over whatever AsyncRead/AsyncWrite transport the caller supplies (a UnixStream in production, an in-memory duplex pipe in tests) — the same “transport-agnostic frame, JSON/CBOR body” shape sui-protocol already established for the graph daemon, kept independent here so this crate has zero dependency on that daemon’s graph-specific wire types.

JSON (not bincode) was chosen for the body encoding: this crate adds no new workspace dependency (serde_json is already pulled in by every consumer of this protocol), the messages are small and infrequent (one per cache lookup, not a hot inner loop), and JSON’s self-describing shape makes sui-dockerfile-node-cache-daemon --version-style debugging trivial with nc/socat during incident response.

Structs§

CachedArtifact
The cache payload: today, an image reference string — the same shape sui_cache::storage::StorageBackend::get_narinfo already returns for a Dockerfile-graph node hit. Kept as its own typed struct (rather than a bare String) so a future phase can widen it (e.g. add a size_bytes or built_at) without an incompatible wire break at the enum level.

Enums§

DaemonRequest
A request from a client (the daemon-aware wrapper client, or any other same-node caller) to the node cache daemon.
DaemonResponse
A response from the node cache daemon.
WarmStatus
Outcome of a Warm request — never blocks the caller on the network fetch; reports only what could be determined synchronously.

Constants§

MAX_MESSAGE_BYTES
Maximum body length a single frame may declare. 8 MiB is generously larger than any CachedArtifact this daemon stores (an image reference string), catching a desynchronized or hostile peer before it forces a runaway allocation.

Functions§

read_message
Read one length-prefixed JSON message from r.
write_message
Write one length-prefixed JSON message to w.