X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Fmessenger.rs;h=1a6e2614b72910976e8aef5ff434dc10eff495bf;hb=d5925f210ed9820ace75c5c1af6c43473ec6892b;hp=7c259113934ca797ec211dd1bb33b8bd2f0f0d74;hpb=c17c2ae3c02487c41e9be8bc507656e43878bb3f;p=rust-lightning diff --git a/lightning/src/onion_message/messenger.rs b/lightning/src/onion_message/messenger.rs index 7c259113..1a6e2614 100644 --- a/lightning/src/onion_message/messenger.rs +++ b/lightning/src/onion_message/messenger.rs @@ -15,7 +15,9 @@ use bitcoin::hashes::hmac::{Hmac, HmacEngine}; use bitcoin::hashes::sha256::Hash as Sha256; use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey}; -use crate::blinded_path::{BlindedPath, ForwardTlvs, ReceiveTlvs, utils}; +use crate::blinded_path::BlindedPath; +use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs}; +use crate::blinded_path::utils; use crate::sign::{EntropySource, KeysManager, NodeSigner, Recipient}; use crate::events::OnionMessageProvider; use crate::ln::features::{InitFeatures, NodeFeatures}; @@ -152,6 +154,17 @@ pub trait MessageRouter { ) -> Result; } +/// A [`MessageRouter`] that always fails. +pub struct DefaultMessageRouter; + +impl MessageRouter for DefaultMessageRouter { + fn find_path( + &self, _sender: PublicKey, _peers: Vec, _destination: Destination + ) -> Result { + Err(()) + } +} + /// A path for sending an [`msgs::OnionMessage`]. #[derive(Clone)] pub struct OnionMessagePath { @@ -286,7 +299,7 @@ where let our_node_id = self.node_signer.get_node_id(Recipient::Node) .map_err(|()| SendError::GetNodeIdFailed)?; if blinded_path.introduction_node_id == our_node_id { - blinded_path.advance_message_path_by_one(&self.node_signer, &self.secp_ctx) + advance_path_by_one(blinded_path, &self.node_signer, &self.secp_ctx) .map_err(|()| SendError::BlindedPathAdvanceFailed)?; } } @@ -416,7 +429,7 @@ where L::Target: Logger, MR::Target: MessageRouter, OMH::Target: OffersMessageHandler, - CMH::Target: CustomOnionMessageHandler + Sized, + 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 @@ -452,7 +465,7 @@ where Ok((Payload::Receive::<<::Target as CustomOnionMessageHandler>::CustomMessage> { message, control_tlvs: ReceiveControlTlvs::Unblinded(ReceiveTlvs { path_id }), reply_path, }, None)) => { - log_info!(self.logger, + log_trace!(self.logger, "Received an onion message with path_id {:02x?} and {} reply_path", path_id, if reply_path.is_some() { "a" } else { "no" }); @@ -479,7 +492,7 @@ where // unwrapping the onion layers to get to the final payload. Since we don't have the option // of creating blinded paths with dummy hops currently, we should be ok to not handle this // for now. - let new_pubkey = match onion_utils::next_hop_packet_pubkey(&self.secp_ctx, msg.onion_routing_packet.public_key, &onion_decode_ss) { + let new_pubkey = match onion_utils::next_hop_pubkey(&self.secp_ctx, msg.onion_routing_packet.public_key, &onion_decode_ss) { Ok(pk) => pk, Err(e) => { log_trace!(self.logger, "Failed to compute next hop packet pubkey: {}", e); @@ -496,21 +509,16 @@ where blinding_point: match next_blinding_override { Some(blinding_point) => blinding_point, None => { - let blinding_factor = { - let mut sha = Sha256::engine(); - sha.input(&msg.blinding_point.serialize()[..]); - sha.input(control_tlvs_ss.as_ref()); - Sha256::from_engine(sha).into_inner() - }; - let next_blinding_point = msg.blinding_point; - match next_blinding_point.mul_tweak(&self.secp_ctx, &Scalar::from_be_bytes(blinding_factor).unwrap()) { + match onion_utils::next_hop_pubkey( + &self.secp_ctx, msg.blinding_point, control_tlvs_ss.as_ref() + ) { Ok(bp) => bp, Err(e) => { log_trace!(self.logger, "Failed to compute next blinding point: {}", e); return } } - }, + } }, onion_routing_packet: outgoing_packet, }; @@ -598,11 +606,11 @@ where /// /// [`SimpleArcChannelManager`]: crate::ln::channelmanager::SimpleArcChannelManager /// [`SimpleArcPeerManager`]: crate::ln::peer_handler::SimpleArcPeerManager -pub type SimpleArcOnionMessenger = OnionMessenger< +pub type SimpleArcOnionMessenger = OnionMessenger< Arc, Arc, Arc, - Arc, + Arc, IgnoringMessageHandler, IgnoringMessageHandler >; @@ -614,11 +622,11 @@ pub type SimpleArcOnionMessenger = OnionMessenger< /// /// [`SimpleRefChannelManager`]: crate::ln::channelmanager::SimpleRefChannelManager /// [`SimpleRefPeerManager`]: crate::ln::peer_handler::SimpleRefPeerManager -pub type SimpleRefOnionMessenger<'a, 'b, 'c, L, R> = OnionMessenger< +pub type SimpleRefOnionMessenger<'a, 'b, 'c, L> = OnionMessenger< &'a KeysManager, &'a KeysManager, &'b L, - &'c R, + &'c DefaultMessageRouter, IgnoringMessageHandler, IgnoringMessageHandler >; @@ -642,46 +650,48 @@ fn packet_payloads_and_keys