Trait CustomOnionMessageHandler
pub trait CustomOnionMessageHandler {
type CustomMessage: OnionMessageContents;
// Required methods
fn handle_custom_message(
&self,
msg: Self::CustomMessage,
) -> Option<Self::CustomMessage>;
fn read_custom_message<R>(
&self,
message_type: u64,
buffer: &mut R,
) -> Result<Option<Self::CustomMessage>, DecodeError>
where R: Read;
fn release_pending_custom_messages(
&self,
) -> Vec<PendingOnionMessage<Self::CustomMessage>>;
}
Expand description
Handler for custom onion messages. If you are using SimpleArcOnionMessenger
,
SimpleRefOnionMessenger
, or prefer to ignore inbound custom onion messages,
IgnoringMessageHandler
must be provided to OnionMessenger::new
. Otherwise, a custom
implementation of this trait must be provided, with CustomMessage
specifying the supported
message types.
See OnionMessenger
for example usage.
Required Associated Types§
type CustomMessage: OnionMessageContents
type CustomMessage: OnionMessageContents
The message known to the handler. To support multiple message types, you may want to make this an enum with a variant for each supported message.
Required Methods§
fn handle_custom_message(
&self,
msg: Self::CustomMessage,
) -> Option<Self::CustomMessage>
fn handle_custom_message( &self, msg: Self::CustomMessage, ) -> Option<Self::CustomMessage>
Called with the custom message that was received, returning a response to send, if any.
The returned Self::CustomMessage
, if any, is enqueued to be sent by OnionMessenger
.
fn read_custom_message<R>(
&self,
message_type: u64,
buffer: &mut R,
) -> Result<Option<Self::CustomMessage>, DecodeError>where
R: Read,
fn read_custom_message<R>(
&self,
message_type: u64,
buffer: &mut R,
) -> Result<Option<Self::CustomMessage>, DecodeError>where
R: Read,
Read a custom message of type message_type
from buffer
, returning Ok(None)
if the
message type is unknown.
fn release_pending_custom_messages(
&self,
) -> Vec<PendingOnionMessage<Self::CustomMessage>>
fn release_pending_custom_messages( &self, ) -> Vec<PendingOnionMessage<Self::CustomMessage>>
Releases any Self::CustomMessage
s that need to be sent.
Typically, this is used for messages initiating a message flow rather than in response to
another message. The latter should use the return value of Self::handle_custom_message
.