lib3h_protocol 0.0.2-alpha1

Lib3h Protocol definition for P2P communication.
Documentation
use crate::{
    protocol_client::Lib3hClientProtocol, protocol_server::Lib3hServerProtocol, DidWork,
    Lib3hResult,
};

/// Common interface for all types of network modules to be used by the Lib3hWorker
pub trait NetworkEngine {
    /// Start network communications
    fn run(&self) -> Lib3hResult<()>;
    /// Stop network communications
    fn stop(&self) -> Lib3hResult<()>;
    /// Terminate module. Perform some cleanup.
    fn terminate(&self) -> Lib3hResult<()>;
    /// Post a protocol message from core -> lib3h
    fn post(&mut self, data: Lib3hClientProtocol) -> Lib3hResult<()>;
    /// A single iteration of the networking process loop
    /// (should be called frequently to not cpu starve networking)
    /// Returns a vector of protocol messages core is required to handle.
    fn process(&mut self) -> Lib3hResult<(DidWork, Vec<Lib3hServerProtocol>)>;
    /// Get qualified transport address
    fn advertise(&self) -> String;
}