pub trait Worker: 'static + Send {
    type Message: Message;
    type Context: 'static + Send;

    fn initialize<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 mut Self::Context
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... } fn shutdown<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 mut Self::Context
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... } fn is_authorized<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 mut Self::Context,
        _msg: Routed<Self::Message>
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait, Global>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... } fn handle_message<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        _context: &'life1 mut Self::Context,
        _msg: Routed<Self::Message>
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait, Global>>Notable traits for Pin<P>impl<P> Future for Pin<P> where
    P: DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
, { ... } }
Expand description

Defines the core interface shared by all Ockam Workers.

While all methods do not need to be implemented, at the very least, the Context and Message types need to be specified before a worker can be used in any call to a Context API such as context.start_worker(...).

Required Associated Types

The type of Message the Worker is sent in Self::handle_message.

The API and other resources available for the worker during message processing.

Currently, this should be always ockam::Context or ockam_node::Context (which are the same type), but in the future custom node implementations may use a different context type.

Provided Methods

Override initialisation behaviour.

Override shutdown behaviour.

Try to authorize an incoming message

The authorization flow of an incoming message looks like this:

  1. [WorkerRelay::recv_message] requests the next message from its associated Context.
  2. [Context::receiver_next] pulls the incoming message from its [SmallReceiver] channel.
  3. [Context::receiver_next] then verifies the AccessControl rules associated with its [Mailboxes] are valid before returning the message to WorkerRelay.
  4. [WorkerRelay::recv_message] invokes this is_authorized function and only invokes Worker::handle_message if ockam_core::allowed() is returned.
  5. If the message is not authorized it will be silently dropped and a warning message output to the worker log.

Try to open and handle a typed message.

Implementations on Foreign Types

Implementors