summaryrefslogtreecommitdiffstats
path: root/src/sandbox/wire.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sandbox/wire.rs')
-rw-r--r--src/sandbox/wire.rs36
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);