+ /// Our next-hop peer was offline or does not support onion message forwarding.
+ InvalidFirstHop,
+ /// Onion message contents must have a TLV type >= 64.
+ InvalidMessage,
+ /// Our next-hop peer's buffer was full or our total outbound buffer was full.
+ BufferFull,
+ /// Failed to retrieve our node id from the provided [`NodeSigner`].
+ ///
+ /// [`NodeSigner`]: crate::sign::NodeSigner
+ GetNodeIdFailed,
+ /// We attempted to send to a blinded path where we are the introduction node, and failed to
+ /// advance the blinded path to make the second hop the new introduction node. Either
+ /// [`NodeSigner::ecdh`] failed, we failed to tweak the current blinding point to get the
+ /// new blinding point, or we were attempting to send to ourselves.
+ BlindedPathAdvanceFailed,
+}
+
+/// 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.
+///
+/// [`IgnoringMessageHandler`]: crate::ln::peer_handler::IgnoringMessageHandler
+/// [`CustomMessage`]: Self::CustomMessage
+pub trait CustomOnionMessageHandler {
+ /// 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.
+ type CustomMessage: CustomOnionMessageContents;
+
+ /// Called with the custom message that was received, returning a response to send, if any.
+ fn handle_custom_message(&self, msg: Self::CustomMessage) -> Option<Self::CustomMessage>;
+
+ /// Read a custom message of type `message_type` from `buffer`, returning `Ok(None)` if the
+ /// message type is unknown.
+ fn read_custom_message<R: io::Read>(&self, message_type: u64, buffer: &mut R) -> Result<Option<Self::CustomMessage>, msgs::DecodeError>;