Skip to main content

Mode

Trait Mode 

Source
pub trait Mode: Send + Sync {
    // Required methods
    fn on_session_start(
        &self,
        session: &Session,
        env: &Envelope,
    ) -> Result<ModeResponse, MacpError>;
    fn on_message(
        &self,
        session: &Session,
        env: &Envelope,
    ) -> Result<ModeResponse, MacpError>;

    // Provided methods
    fn on_message_at(
        &self,
        session: &Session,
        env: &Envelope,
        ctx: &MessageContext,
    ) -> Result<ModeResponse, MacpError> { ... }
    fn authorize_sender(
        &self,
        session: &Session,
        env: &Envelope,
    ) -> Result<(), MacpError> { ... }
}
Expand description

Trait that coordination modes implement. Modes receive immutable session references and return a ModeResponse. The runtime kernel is responsible for applying the response.

Required Methods§

Source

fn on_session_start( &self, session: &Session, env: &Envelope, ) -> Result<ModeResponse, MacpError>

Source

fn on_message( &self, session: &Session, env: &Envelope, ) -> Result<ModeResponse, MacpError>

Provided Methods§

Source

fn on_message_at( &self, session: &Session, env: &Envelope, ctx: &MessageContext, ) -> Result<ModeResponse, MacpError>

Kernel entry point: on_message plus the runtime’s macp_core::mode::MessageContext (acceptance clock). Defaulted to plain on_message so most modes ignore it; modes that need a trustworthy time source (Handoff) override this instead of reading the forgeable Envelope.timestamp_unix_ms. The runtime and replay always call this, with the same clock value that the log entry records.

Source

fn authorize_sender( &self, session: &Session, env: &Envelope, ) -> Result<(), MacpError>

Authorize the sender for this message. Modes can override to customize authorization (e.g., allowing orchestrator bypass for Commitment messages).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§