Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["server", "sandd"]
members = ["protocol", "server", "sandd"]
resolver = "2"

[workspace.dependencies]
Expand Down
1 change: 1 addition & 0 deletions hack/docker/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN apk add --no-cache \

# Copy workspace files
COPY Cargo.toml Cargo.lock ./
COPY protocol/ ./protocol/
COPY sandd/ ./sandd/
COPY server/ ./server/

Expand Down
1 change: 1 addition & 0 deletions hack/docker/Dockerfile.debian
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y \

# Copy workspace files
COPY Cargo.toml Cargo.lock ./
COPY protocol/ ./protocol/
COPY sandd/ ./sandd/
COPY server/ ./server/

Expand Down
1 change: 1 addition & 0 deletions hack/docker/Dockerfile.rocky
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN apt-get update && apt-get install -y \

# Copy workspace files
COPY Cargo.toml Cargo.lock ./
COPY protocol/ ./protocol/
COPY sandd/ ./sandd/
COPY server/ ./server/

Expand Down
9 changes: 9 additions & 0 deletions protocol/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "sandd-protocol"
version = "0.0.0"
edition = "2021"

[dependencies]
serde = { workspace = true }
serde_json = { workspace = true }
base64 = "0.22"
34 changes: 17 additions & 17 deletions server/src/protocol.rs → protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
// Shared protocol between daemon and server

use serde::{Deserialize, Serialize};

/// Protocol messages exchanged between agent and daemon
/// Snapshot metadata (shared between daemon and server)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotInfo {
pub id: String,
pub created_at: u64, // Unix timestamp in seconds
pub message: String,
pub tags: Vec<String>,
pub file_count: usize,
pub total_size: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Message {
// Connection management
Register {
daemon_id: String,
metadata: DaemonMetadata,
Expand All @@ -15,8 +26,6 @@ pub enum Message {
},
Heartbeat,
Pong,

// Command execution (simple mode)
ExecuteCommand {
request_id: String,
command: String,
Expand All @@ -38,8 +47,6 @@ pub enum Message {
request_id: String,
error: String,
},

// Interactive session (PTY mode)
NewSession {
session_id: String,
rows: u16,
Expand Down Expand Up @@ -74,14 +81,12 @@ pub enum Message {
session_id: String,
exit_code: i32,
},

// File transfer
FileUploadStart {
request_id: String,
path: String,
total_size: u64,
#[serde(default)]
mode: Option<u32>, // Unix file permissions
mode: Option<u32>,
},
FileUploadChunk {
request_id: String,
Expand Down Expand Up @@ -109,7 +114,6 @@ pub enum Message {
request_id: String,
error: String,
},

// Snapshot operations
CreateSnapshot {
request_id: String,
Expand Down Expand Up @@ -138,7 +142,7 @@ pub enum Message {
},
SnapshotList {
request_id: String,
snapshots: Vec<serde_json::Value>,
snapshots: Vec<SnapshotInfo>,
},
FindSnapshotByTag {
request_id: String,
Expand All @@ -150,7 +154,7 @@ pub enum Message {
},
SnapshotDetails {
request_id: String,
snapshot: Option<serde_json::Value>,
snapshot: Option<SnapshotInfo>,
},
DeleteSnapshot {
request_id: String,
Expand All @@ -163,8 +167,6 @@ pub enum Message {
request_id: String,
error: String,
},

// Error handling
Error {
message: String,
#[serde(default)]
Expand All @@ -184,14 +186,13 @@ pub struct DaemonMetadata {
}

fn default_timeout() -> u64 {
300 // 5 minutes
300
}

fn default_term() -> String {
"xterm-256color".to_string()
}

// Base64 encoding for binary data in JSON
mod base64_bytes {
use serde::{Deserialize, Deserializer, Serializer};

Expand All @@ -209,7 +210,6 @@ mod base64_bytes {
.map_err(serde::de::Error::custom)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions sandd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ name = "snapshot_real_project"
path = "../examples/snapshot_real_project.rs"

[dependencies]
sandd-protocol = { path = "../protocol" }
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions sandd/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod executor;
mod protocol;
// Use shared protocol crate
mod session;
pub mod snapshot;

use anyhow::{Context, Result};
use clap::Parser;
use executor::CommandExecutor;
use futures_util::{SinkExt, StreamExt};
use protocol::Message;
use sandd_protocol::Message;
use std::collections::HashMap;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -148,7 +148,7 @@ async fn connect_and_serve(
let (mut ws_tx, mut ws_rx) = ws_stream.split();

// Gather system metadata
let metadata = protocol::DaemonMetadata {
let metadata = sandd_protocol::DaemonMetadata {
hostname: System::host_name().unwrap_or_else(|| "unknown".to_string()),
platform: std::env::consts::OS.to_string(),
arch: std::env::consts::ARCH.to_string(),
Expand Down
Loading
Loading