gitmesh-core 0.1.0

Shared types and protocol definitions for Git Mesh.
Documentation
//! # Git Mesh Core
//!
//! This crate contains shared types, protocol definitions, and configuration logic
//! used by both the Git Mesh daemon and CLI.

use serde::{Deserialize, Serialize};

/// Requests sent from the CLI tool to the Daemon via the local IPC pipe.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum IpcRequest {
    /// Ping the daemon to check connectivity.
    Ping,
    /// Request the current status of the daemon.
    Status,
    /// Instruct the daemon to fetch updates for a specific repository.
    Fetch { repo: String },
    /// Instruct the daemon to announce a new push for a repository.
    Push {
        /// The repository name.
        repo: String,
        /// The branch being pushed.
        branch: String,
        /// The new commit hash.
        commit: String,
    },
}

/// Responses sent from the Daemon back to the CLI over the IPC pipe.
#[derive(Debug, Serialize, Deserialize)]
pub enum IpcResponse {
    /// Response to a Ping request.
    Pong,
    /// Indicates a successful operation with an optional message.
    Success(String),
    /// Indicates a failed operation with an error message.
    Error(String),
}

/// A request sent over the P2P network using the libp2p RequestResponse protocol.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GitSyncRequest {
    /// The repository name requested.
    pub repo: String,
    /// The specific command/operation requested.
    pub command: GitSyncCommand,
}

/// Commands supported by the Git Push/Pull synchronization protocol.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GitSyncCommand {
    /// Request a list of all refs (branches/tags) from the remote peer.
    ListRefs,
    /// Request specific objects/packfiles from the remote peer.
    FetchObjects {
        /// Commit hashes the requester already has.
        have: Vec<String>,
        /// Commit hashes the requester wants to receive.
        want: Vec<String>,
    },
}

/// A response sent over the P2P network in response to a `GitSyncRequest`.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum GitSyncResponse {
    /// A list of refs available on the peer.
    Refs(Vec<(String, String)>), // (ref_name, commit_hash)
    /// A binary packfile containing the requested Git objects.
    Objects(Vec<u8>),
}