Skip to content

Commit 4bb5fa9

Browse files
committed
Use the shared protocol
Signed-off-by: kerthcet <kerthcet@gmail.com>
1 parent b3d8c9a commit 4bb5fa9

13 files changed

Lines changed: 52 additions & 239 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["server", "sandd"]
2+
members = ["protocol", "server", "sandd"]
33
resolver = "2"
44

55
[workspace.dependencies]

protocol/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "sandd-protocol"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
serde = { workspace = true }
8+
serde_json = { workspace = true }
9+
base64 = "0.22"
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
// Shared protocol between daemon and server
2+
13
use serde::{Deserialize, Serialize};
24

3-
/// Protocol messages exchanged between agent and daemon
5+
/// Snapshot metadata (shared between daemon and server)
6+
#[derive(Debug, Clone, Serialize, Deserialize)]
7+
pub struct SnapshotInfo {
8+
pub id: String,
9+
pub created_at: u64, // Unix timestamp in milliseconds
10+
pub message: String,
11+
pub tags: Vec<String>,
12+
pub file_count: usize,
13+
pub total_size: u64,
14+
}
15+
416
#[derive(Debug, Clone, Serialize, Deserialize)]
517
#[serde(tag = "type", rename_all = "snake_case")]
618
pub enum Message {
7-
// Connection management
819
Register {
920
daemon_id: String,
1021
metadata: DaemonMetadata,
@@ -15,8 +26,6 @@ pub enum Message {
1526
},
1627
Heartbeat,
1728
Pong,
18-
19-
// Command execution (simple mode)
2029
ExecuteCommand {
2130
request_id: String,
2231
command: String,
@@ -38,8 +47,6 @@ pub enum Message {
3847
request_id: String,
3948
error: String,
4049
},
41-
42-
// Interactive session (PTY mode)
4350
NewSession {
4451
session_id: String,
4552
rows: u16,
@@ -74,14 +81,12 @@ pub enum Message {
7481
session_id: String,
7582
exit_code: i32,
7683
},
77-
78-
// File transfer
7984
FileUploadStart {
8085
request_id: String,
8186
path: String,
8287
total_size: u64,
8388
#[serde(default)]
84-
mode: Option<u32>, // Unix file permissions
89+
mode: Option<u32>,
8590
},
8691
FileUploadChunk {
8792
request_id: String,
@@ -109,7 +114,6 @@ pub enum Message {
109114
request_id: String,
110115
error: String,
111116
},
112-
113117
// Snapshot operations
114118
CreateSnapshot {
115119
request_id: String,
@@ -138,7 +142,7 @@ pub enum Message {
138142
},
139143
SnapshotList {
140144
request_id: String,
141-
snapshots: Vec<serde_json::Value>,
145+
snapshots: Vec<SnapshotInfo>,
142146
},
143147
FindSnapshotByTag {
144148
request_id: String,
@@ -150,7 +154,7 @@ pub enum Message {
150154
},
151155
SnapshotDetails {
152156
request_id: String,
153-
snapshot: Option<serde_json::Value>,
157+
snapshot: Option<SnapshotInfo>,
154158
},
155159
DeleteSnapshot {
156160
request_id: String,
@@ -163,8 +167,6 @@ pub enum Message {
163167
request_id: String,
164168
error: String,
165169
},
166-
167-
// Error handling
168170
Error {
169171
message: String,
170172
#[serde(default)]
@@ -184,14 +186,13 @@ pub struct DaemonMetadata {
184186
}
185187

186188
fn default_timeout() -> u64 {
187-
300 // 5 minutes
189+
300
188190
}
189191

190192
fn default_term() -> String {
191193
"xterm-256color".to_string()
192194
}
193195

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

@@ -209,7 +210,6 @@ mod base64_bytes {
209210
.map_err(serde::de::Error::custom)
210211
}
211212
}
212-
213213
#[cfg(test)]
214214
mod tests {
215215
use super::*;

sandd/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ name = "snapshot_real_project"
2828
path = "../examples/snapshot_real_project.rs"
2929

3030
[dependencies]
31+
sandd-protocol = { path = "../protocol" }
3132
tokio = { workspace = true }
3233
serde = { workspace = true }
3334
serde_json = { workspace = true }

sandd/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
mod executor;
2-
mod protocol;
2+
// Use shared protocol crate
33
mod session;
44
pub mod snapshot;
55

66
use anyhow::{Context, Result};
77
use clap::Parser;
88
use executor::CommandExecutor;
99
use futures_util::{SinkExt, StreamExt};
10-
use protocol::Message;
10+
use sandd_protocol::Message;
1111
use std::collections::HashMap;
1212
use std::sync::Arc;
1313
use std::time::Duration;
@@ -148,7 +148,7 @@ async fn connect_and_serve(
148148
let (mut ws_tx, mut ws_rx) = ws_stream.split();
149149

150150
// Gather system metadata
151-
let metadata = protocol::DaemonMetadata {
151+
let metadata = sandd_protocol::DaemonMetadata {
152152
hostname: System::host_name().unwrap_or_else(|| "unknown".to_string()),
153153
platform: std::env::consts::OS.to_string(),
154154
arch: std::env::consts::ARCH.to_string(),

0 commit comments

Comments
 (0)