microsandbox_protocol/core.rs
1//! Core protocol message payloads.
2
3use serde::{Deserialize, Serialize};
4
5//--------------------------------------------------------------------------------------------------
6// Types
7//--------------------------------------------------------------------------------------------------
8
9/// Payload for `core.ready` messages.
10///
11/// Sent by the guest agent to signal that it has finished initialization
12/// and is ready to receive commands. Includes timing data for boot
13/// performance measurement.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct Ready {
16 /// `CLOCK_BOOTTIME` nanoseconds captured at the start of `main()`.
17 ///
18 /// Represents how long the kernel took to boot before userspace started.
19 pub boot_time_ns: u64,
20
21 /// Nanoseconds spent in `init::init()` (mounting filesystems).
22 pub init_time_ns: u64,
23
24 /// `CLOCK_BOOTTIME` nanoseconds captured just before sending this message.
25 ///
26 /// Represents total time from kernel boot to agent readiness.
27 pub ready_time_ns: u64,
28}
29
30/// Payload for `core.clock.sync` messages.
31///
32/// Sent by the host to ask the guest agent to step `CLOCK_REALTIME` to the
33/// host's current wall-clock time.
34#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct ClockSync {
36 /// Host Unix timestamp in nanoseconds.
37 pub unix_time_nanos: u64,
38}
39
40/// Payload for `core.init.resolved` messages.
41///
42/// Sent by agentd after the guest rootfs is ready to resolve init-time facts,
43/// but before user volume mounts are attached. The host uses this to install
44/// early runtime state that depends on guest-resolved values.
45#[derive(Debug, Clone, Serialize, Deserialize)]
46pub struct InitResolved {
47 /// Default guest user for sandbox commands.
48 pub default_user: ResolvedUser,
49}
50
51/// A guest user and group resolved by agentd.
52#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
53pub struct ResolvedUser {
54 /// Effective default guest user id for sandbox commands.
55 pub uid: u32,
56
57 /// Effective default guest group id for sandbox commands.
58 pub gid: u32,
59}
60
61/// Payload for `core.init.ack` messages.
62///
63/// Sent by the host after it has consumed the init context and completed any
64/// dependent setup.
65#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct InitAck {}
67
68/// Payload for `core.relay.client.disconnected` messages.
69///
70/// Sent by the host relay when one SDK client socket disconnects. The
71/// guest agent uses the assigned correlation ID range to clean up resources
72/// owned by that client, such as open filesystem handles.
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct RelayClientDisconnected {
75 /// First correlation ID assigned to the disconnected client.
76 pub id_start: u32,
77
78 /// Exclusive upper bound of the disconnected client's ID range.
79 pub id_end_exclusive: u32,
80}