diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
| commit | e757979f1a2afdbe7146066345bb9acd19d3b151 (patch) | |
| tree | 30d5f5fbccd25ea7bf01c5202684af463b74e7d3 /src/sandbox/wire.rs | |
| parent | 94c318f13264bb3c00a9f3057ba2e1aafb57c9e4 (diff) | |
| download | aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.tar.gz aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.zip | |
comments: say why, not what
Every module-level `//!` header is gone, and the comments that remained
either re-explained the line below them or had grown into paragraphs.
Density went from one comment line per 6.7 lines of code to one per 10.
827 insertions against 2194 deletions across 86 files.
What survived: the invariants (I1-I12), the design cross-references into
DESIGN.md, and the notes recording a bug that was found and fixed — those
are the comments that carry weight, because they answer a question the
code cannot answer about itself. What did not: restating a function
signature in prose, and narration of the statement underneath.
Diffstat (limited to 'src/sandbox/wire.rs')
| -rw-r--r-- | src/sandbox/wire.rs | 36 |
1 files changed, 7 insertions, 29 deletions
diff --git a/src/sandbox/wire.rs b/src/sandbox/wire.rs index 4ea1c74..8f03063 100644 --- a/src/sandbox/wire.rs +++ b/src/sandbox/wire.rs @@ -1,19 +1,3 @@ -//! The hub↔sandbox wire protocol: length-prefixed JSON frames over a plain -//! socket, payloads hex-encoded. -//! -//! Deliberately boring, and deliberately dependency-free: one frame is a 4-byte -//! big-endian length followed by one JSON object. Binary payloads ride inside -//! the JSON as hex — twice the bytes of base64, but `hex` is already a -//! dependency and blobs (recipes, pinned packages) are small. A frame is -//! self-delimiting, so a reader that times out mid-frame cannot silently -//! desynchronize: the connection is dead, and a dead sandbox is a lease -//! expiry, which the reaper already knows how to handle (I5). -//! -//! The direction of connection matters: the *agent dials the hub*, never the -//! reverse. A sandbox is untrusted the moment it boots; the hub must never need -//! a route into it. Everything the hub wants — runs, blobs, teardown — is a -//! frame on the connection the agent initiated (outbound rendezvous). - use std::io::{self, BufRead, Write}; use serde::{Deserialize, Serialize}; @@ -33,18 +17,16 @@ pub enum Frame { /// hub → agent: rendezvous accepted; `ttl_secs` arms the agent's watchdog. HelloAck { ttl_secs: u64 }, /// hub → agent: run argv. `blob:<digest>` argv elements name blobs the - /// agent must have received via `Put`. `env` is the hub's child - /// environment (the §16a shim protocol rides on it in tests). + /// agent must already have via `Put`; `env` is the hub's child environment. Run { req: u64, argv: Vec<String>, cwd: Option<String>, env: Vec<(String, String)> }, /// agent → hub: a chunk of the running child's output, hex-encoded. Log { req: u64, stream: String, data: String }, /// agent → hub: the child finished. `code` is None when it died by signal. Exit { req: u64, code: Option<i32> }, - /// hub → agent: stage this content-addressed blob. The agent verifies - /// `data` hashes to `digest` before writing — the same posture the local - /// pacman fake enforces. + /// hub → agent: stage this blob. The agent verifies `data` hashes to + /// `digest` before writing. Put { req: u64, digest: String, data: String }, - /// hub → agent: pull this blob back out (artifacts come home by digest). + /// hub → agent: pull this blob back out. Get { req: u64, digest: String }, /// agent → hub: reply to `Get`. Blob { req: u64, data: String }, @@ -54,8 +36,7 @@ pub enum Frame { Err { req: u64, msg: String }, /// hub → agent: keepalive; resets the agent's TTL watchdog. Ping {}, - /// hub → agent: tear down now. The agent would also die on its own when - /// the connection drops — destroy is courtesy, TTL is the guarantee. + /// hub → agent: tear down now. TTL is the guarantee, this is courtesy. Destroy {}, } @@ -70,9 +51,8 @@ pub fn write_frame(w: &mut impl Write, f: &Frame) -> io::Result<()> { w.flush() } -/// Read one frame. `Ok(None)` means the peer closed the connection cleanly — -/// which, for a sandbox, is indistinguishable from "the sandbox is gone" and -/// therefore means the same thing to the hub: lease expired, requeue. +/// Read one frame. `Ok(None)` means a clean close, which for a sandbox means +/// the lease expired and the build should requeue. pub fn read_frame(r: &mut impl BufRead) -> io::Result<Option<Frame>> { let mut len = [0u8; 4]; match r.read_exact(&mut len) { @@ -130,8 +110,6 @@ mod tests { #[test] fn a_truncated_frame_is_an_error_not_a_silent_none() { - // Half a frame on the wire must read as a dead connection through an - // error path, never as a parsed frame. let mut buf = Vec::new(); write_frame(&mut buf, &Frame::Ping {}).unwrap(); buf.truncate(3); |
