pub trait Handler {
    // Required methods
    fn do_handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>;
    fn client_id(&self) -> u64;
    fn for_new_client(
        &self,
        client_id: u64,
        peer_id: PubKey,
        dbid: u64
    ) -> ChannelHandler;
    fn node(&self) -> &Arc<Node>;
    fn lss_state(&self) -> Arc<Mutex<BTreeMap<String, (u64, Vec<u8>)>>>;

    // Provided methods
    fn handle(&self, msg: Message) -> Result<(Box<dyn SerBolt>, Mutations)> { ... }
    fn with_persist(
        &self,
        f: impl FnOnce(&Node) -> Result<()>
    ) -> Result<Mutations> { ... }
}
Expand description

A protocol handler The handle function takes an incoming message, handles it and returns a response.

There are two implementations of this trait - RootHandler for node level messages and ChannelHandler for channel level messages.

Required Methods§

source

fn do_handle(&self, msg: Message) -> Result<Box<dyn SerBolt>>

Actual handling

source

fn client_id(&self) -> u64

Unused

source

fn for_new_client( &self, client_id: u64, peer_id: PubKey, dbid: u64 ) -> ChannelHandler

Create a channel handler

source

fn node(&self) -> &Arc<Node>

Get the associated signing node. Note that if you want to perform an operation that can result in a mutation of the node state requiring a persist, and your persister writes to the cloud, you must use Handler::with_persist instead.

source

fn lss_state(&self) -> Arc<Mutex<BTreeMap<String, (u64, Vec<u8>)>>>

Get the LSS state. This will be empty if we are not persisting to the cloud

Provided Methods§

source

fn handle(&self, msg: Message) -> Result<(Box<dyn SerBolt>, Mutations)>

Handle a message

source

fn with_persist(&self, f: impl FnOnce(&Node) -> Result<()>) -> Result<Mutations>

Perform an operation on the Node that requires persistence. The operation must not mutate if it fails (returns an error).

Implementors§