capsid-protocol 0.1.0-alpha.1

Versioned, size-bounded messages between the Capsid host and its guest agent.
Documentation
mod agent;
pub mod boot;
pub mod builder;
pub mod checkpoint;
pub mod console;
pub mod copy;
mod digest;
pub mod encoding;
mod error;
pub mod forwarding;
mod frame;
pub mod guest;
mod ids;
pub mod image;
mod names;
pub mod network;
pub mod path;
pub mod ports;
mod process;
pub mod readiness;
pub mod reason;
mod report;
pub mod session;
#[cfg(test)]
mod testing;
pub mod volume;
pub mod workspace;

use std::time::Duration;

use serde::Deserialize;

pub use agent::{
    ExecState, ExitOutcome, GuestAction, GuestRequest, GuestResponse, GuestResult, GuestState,
    LOG_RETENTION_BYTES, MAX_EXEC_OUTPUT, MAX_LOG_CHUNK, MAX_RESULT_CHUNK,
};
pub use digest::{ContentDigest, DigestError, Hasher, HashingReader, HashingWriter};
pub use error::{Error, Result};
pub use frame::{
    FRAME_HEADER_BYTES, FrameDecoder, MAX_FRAME_BYTES, decode_frame, encode_frame, frame_length,
    read_bounded, read_frame, read_frame_body, write_frame,
};
pub use ids::{
    AgentId, AgentTag, AttemptId, BackupId, CheckpointId, ClusterId, DiskStagingId, EgressGrantId,
    InstanceId, JobGroupId, JobRunId, LeaseId, LeaseToken, LedgerId, NetworkId, NodeId, ObserverId,
    OperationId, PoolId, PreparationId, ProjectId, RelocationId, ReplicaId, ReporterEpoch,
    ReporterId, RequestId, RevisionId, ServiceId, TemplateId, TicketId, TokenId, TransferId,
    VolumeId, WorkloadId, WorkspaceAttachmentId, WorkspaceGrantId, WorkspaceId,
};
pub use process::{
    ExecOverrides, HttpProbe, MAX_ARG_BYTES, MAX_ARGS, MAX_ENVIRONMENT, MAX_ENVIRONMENT_NAME_BYTES,
    MAX_ENVIRONMENT_VALUE_BYTES, MAX_USER_BYTES, ProcessSettings, ReadinessProbe, StopSignal,
    validate_process_input,
};
pub use report::{ErrorReport, Report, truncate};

pub const VERSION: u32 = 6;

// Every guest request and response of every version starts with its version.
// A peer reads it alone first, so it can name a mismatch instead of failing to
// parse a message whose shape changed.
#[derive(Debug, Clone, Copy, Deserialize)]
pub struct Versioned {
    pub version: u32,
}

// Milliseconds for a record or wire field, saturating at `u64::MAX`.
pub fn duration_ms(duration: Duration) -> u64 {
    u64::try_from(duration.as_millis()).unwrap_or(u64::MAX)
}