Skip to main content

Module protocol_server

Module protocol_server 

Source
Expand description

Protocol server lifecycle trait for uniform server startup and shutdown Protocol server lifecycle trait for uniform server startup and shutdown.

This module provides the [MockProtocolServer] trait, which abstracts the lifecycle management of mock protocol servers. Each protocol crate (gRPC, FTP, TCP, SMTP, etc.) can implement this trait to provide a uniform startup interface, enabling the CLI to launch all protocols through a single, consistent code path.

§Design

The trait is intentionally minimal — it covers the core lifecycle operations (start, shutdown, identification) without imposing protocol-specific details. Protocol crates wrap their existing server startup logic in a struct that implements this trait; the actual server code remains unchanged.

§Example

use mockforge_core::protocol_server::MockProtocolServer;
use mockforge_core::protocol_abstraction::Protocol;
use async_trait::async_trait;

struct MyServer { port: u16 }

#[async_trait]
impl MockProtocolServer for MyServer {
    fn protocol(&self) -> Protocol { Protocol::Tcp }
    async fn start(
        &self,
        shutdown: tokio::sync::watch::Receiver<()>,
    ) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
        // Run until shutdown signal
        let _ = shutdown;
        Ok(())
    }
    fn port(&self) -> u16 { self.port }
    fn description(&self) -> String {
        format!("TCP server on port {}", self.port)
    }
}

Traits§

MockProtocolServer
Trait for mock protocol server lifecycle management.