//! Iroh protocol constants and stream helpers. /// ALPN for git-remote-iroh connections. pub const GIT_IROH_ALPN: &[u8] = b"git/iroh/0"; /// Stream header sent at the start of a git stream. /// Identifies whether this is a push (receive-pack) or fetch (upload-pack). #[derive(Debug, Clone, Copy, PartialEq)] pub enum GitOp { /// Client wants to push (server runs git-receive-pack) Push, /// Client wants to fetch (server runs git-upload-pack) Fetch, } impl GitOp { pub fn to_byte(self) -> u8 { match self { GitOp::Push => 1, GitOp::Fetch => 2, } } pub fn from_byte(b: u8) -> Option { match b { 1 => Some(GitOp::Push), 2 => Some(GitOp::Fetch), _ => None, } } /// The git command to run on the server side. pub fn server_command(self) -> &'static str { match self { GitOp::Push => "git-receive-pack", GitOp::Fetch => "git-upload-pack", } } }