/// Because implementations such as Eclair will drop onion messages where the message packet
/// exceeds 32834 bytes, we refuse to send messages where the packet exceeds this size.
TooBigPacket,
- /// The provided [`Destination`] was an invalid [`BlindedPath`], due to having fewer than two
- /// blinded hops.
+ /// The provided [`Destination`] was an invalid [`BlindedPath`] due to not having any blinded
+ /// hops.
TooFewBlindedHops,
/// Our next-hop peer was offline or does not support onion message forwarding.
InvalidFirstHop,
{
let OnionMessagePath { intermediate_nodes, mut destination } = path;
if let Destination::BlindedPath(BlindedPath { ref blinded_hops, .. }) = destination {
- if blinded_hops.len() < 2 {
+ if blinded_hops.is_empty() {
return Err(SendError::TooFewBlindedHops);
}
}
}))
}
-/// Decode one layer of an incoming onion message
-/// Returns either a Forward (another onion message), or Receive (decrypted content)
-pub fn peel_onion<NS: Deref, L: Deref, CMH: Deref>(
- node_signer: NS, secp_ctx: &Secp256k1<secp256k1::All>, logger: L, custom_handler: CMH,
- msg: &OnionMessage,
+/// Decode one layer of an incoming [`OnionMessage`].
+///
+/// Returns either the next layer of the onion for forwarding or the decrypted content for the
+/// receiver.
+pub fn peel_onion_message<NS: Deref, L: Deref, CMH: Deref>(
+ msg: &OnionMessage, secp_ctx: &Secp256k1<secp256k1::All>, node_signer: NS, logger: L,
+ custom_handler: CMH,
) -> Result<PeeledOnion<<<CMH>::Target as CustomOnionMessageHandler>::CustomMessage>, ()>
where
NS::Target: NodeSigner,
OMH::Target: OffersMessageHandler,
CMH::Target: CustomOnionMessageHandler,
{
- /// Handle an incoming onion message. Currently, if a message was destined for us we will log, but
- /// soon we'll delegate the onion message to a handler that can generate invoices or send
- /// payments.
fn handle_onion_message(&self, _peer_node_id: &PublicKey, msg: &OnionMessage) {
- match peel_onion(
- &*self.node_signer, &self.secp_ctx, &*self.logger, &*self.custom_handler, msg
+ match peel_onion_message(
+ msg, &self.secp_ctx, &*self.node_signer, &*self.logger, &*self.custom_handler
) {
Ok(PeeledOnion::Receive(message, path_id, reply_path)) => {
log_trace!(self.logger,