gitmesh_core/lib.rs
1//! # Git Mesh Core
2//!
3//! This crate contains shared types, protocol definitions, and configuration logic
4//! used by both the Git Mesh daemon and CLI.
5
6use serde::{Deserialize, Serialize};
7
8/// Requests sent from the CLI tool to the Daemon via the local IPC pipe.
9#[derive(Debug, Serialize, Deserialize, Clone)]
10pub enum IpcRequest {
11 /// Ping the daemon to check connectivity.
12 Ping,
13 /// Request the current status of the daemon.
14 Status,
15 /// Instruct the daemon to fetch updates for a specific repository.
16 Fetch { repo: String },
17 /// Instruct the daemon to announce a new push for a repository.
18 Push {
19 /// The repository name.
20 repo: String,
21 /// The branch being pushed.
22 branch: String,
23 /// The new commit hash.
24 commit: String,
25 },
26}
27
28/// Responses sent from the Daemon back to the CLI over the IPC pipe.
29#[derive(Debug, Serialize, Deserialize)]
30pub enum IpcResponse {
31 /// Response to a Ping request.
32 Pong,
33 /// Indicates a successful operation with an optional message.
34 Success(String),
35 /// Indicates a failed operation with an error message.
36 Error(String),
37}
38
39/// A request sent over the P2P network using the libp2p RequestResponse protocol.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct GitSyncRequest {
42 /// The repository name requested.
43 pub repo: String,
44 /// The specific command/operation requested.
45 pub command: GitSyncCommand,
46}
47
48/// Commands supported by the Git Push/Pull synchronization protocol.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub enum GitSyncCommand {
51 /// Request a list of all refs (branches/tags) from the remote peer.
52 ListRefs,
53 /// Request specific objects/packfiles from the remote peer.
54 FetchObjects {
55 /// Commit hashes the requester already has.
56 have: Vec<String>,
57 /// Commit hashes the requester wants to receive.
58 want: Vec<String>,
59 },
60}
61
62/// A response sent over the P2P network in response to a `GitSyncRequest`.
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub enum GitSyncResponse {
65 /// A list of refs available on the peer.
66 Refs(Vec<(String, String)>), // (ref_name, commit_hash)
67 /// A binary packfile containing the requested Git objects.
68 Objects(Vec<u8>),
69}