pub trait Service: Send {
    fn service_id(&self) -> &str;
    fn service_type(&self) -> &str;
    fn start(
        &mut self,
        service_registry: &dyn ServiceNetworkRegistry
    ) -> Result<(), ServiceStartError>; fn stop(
        &mut self,
        service_registry: &dyn ServiceNetworkRegistry
    ) -> Result<(), ServiceStopError>; fn destroy(self: Box<Self>) -> Result<(), ServiceDestroyError>; fn purge(&mut self) -> Result<(), InternalError>; fn handle_message(
        &self,
        message_bytes: &[u8],
        message_context: &ServiceMessageContext
    ) -> Result<(), ServiceError>; fn as_any(&self) -> &dyn Any; }
Expand description

A Service provides message handling for a given service type.

Required Methods

This service’s ID

This ID must be unique within the context of a circuit, but not necessarily unique within the context of a splinter node, as a whole.

This service’s type

A service type broadly identifies the kinds of messages that this service handles or emits.

Starts the service

At start time, the service should register itself with the network when its ready to receive messages.

Stops Starts the service

The service should unregister itself with the network.

Clean-up any resources before the service is removed. Consumes the service (which, given the use of dyn traits, this must take a boxed Service instance).

Purge any persistent state maintained by this service.

Handle any incoming message intended for this service instance.

Messages recevied by this service are provided in raw bytes. The format of the service

Cast the service as &dyn Any.

This allows for downcasting the Service to a specific implementation.

Implementors