#[allow(unused_imports)]
use crate::prelude::*;
-use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
+use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
use crate::blinded_path::utils;
use crate::io;
use crate::io::Cursor;
/// route, they are encoded into [`BlindedHop::encrypted_payload`].
pub(crate) struct ForwardTlvs {
/// The next hop in the onion message's path.
- pub(crate) next_hop: NextHop,
+ pub(crate) next_hop: NextMessageHop,
/// Senders to a blinded path use this value to concatenate the route they find to the
/// introduction node with the blinded path.
pub(crate) next_blinding_override: Option<PublicKey>,
pub(crate) path_id: Option<[u8; 32]>,
}
-/// The next hop to forward the onion message along its path.
-#[derive(Debug)]
-pub enum NextHop {
- /// The node id of the next hop.
- NodeId(PublicKey),
- /// The short channel id leading to the next hop.
- ShortChannelId(u64),
-}
-
impl Writeable for ForwardTlvs {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
let (next_node_id, short_channel_id) = match self.next_hop {
- NextHop::NodeId(pubkey) => (Some(pubkey), None),
- NextHop::ShortChannelId(scid) => (None, Some(scid)),
+ NextMessageHop::NodeId(pubkey) => (Some(pubkey), None),
+ NextMessageHop::ShortChannelId(scid) => (None, Some(scid)),
};
// TODO: write padding
encode_tlv_stream!(writer, {
) -> Result<Vec<BlindedHop>, secp256k1::Error> {
let blinded_tlvs = unblinded_path.iter()
.skip(1) // The first node's TLVs contains the next node's pubkey
- .map(|pk| ForwardTlvs { next_hop: NextHop::NodeId(*pk), next_blinding_override: None })
+ .map(|pk| ForwardTlvs { next_hop: NextMessageHop::NodeId(*pk), next_blinding_override: None })
.map(|tlvs| ControlTlvs::Forward(tlvs))
.chain(core::iter::once(ControlTlvs::Receive(ReceiveTlvs { path_id: None })));
readable: ControlTlvs::Forward(ForwardTlvs { next_hop, next_blinding_override })
}) => {
let next_node_id = match next_hop {
- NextHop::NodeId(pubkey) => pubkey,
- NextHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
+ NextMessageHop::NodeId(pubkey) => pubkey,
+ NextMessageHop::ShortChannelId(scid) => match node_id_lookup.next_node_id(scid) {
Some(pubkey) => pubkey,
None => return Err(()),
},
use crate::io;
use crate::prelude::*;
+/// The next hop to forward an onion message along its path.
+///
+/// Note that payment blinded paths always specify their next hop using an explicit node id.
+#[derive(Debug)]
+pub enum NextMessageHop {
+ /// The node id of the next hop.
+ NodeId(PublicKey),
+ /// The short channel id leading to the next hop.
+ ShortChannelId(u64),
+}
+
/// Onion messages and payments can be sent and received to blinded paths, which serve to hide the
/// identity of the recipient.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
use bitcoin::hashes::sha256::Hash as Sha256;
use bitcoin::secp256k1::{self, PublicKey, Scalar, Secp256k1, SecretKey};
-use crate::blinded_path::{BlindedPath, IntroductionNode, NodeIdLookUp};
-use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, NextHop, ReceiveTlvs};
+use crate::blinded_path::{BlindedPath, IntroductionNode, NextMessageHop, NodeIdLookUp};
+use crate::blinded_path::message::{advance_path_by_one, ForwardTlvs, ReceiveTlvs};
use crate::blinded_path::utils;
use crate::events::{Event, EventHandler, EventsProvider};
use crate::sign::{EntropySource, NodeSigner, Recipient};
#[derive(Debug)]
pub enum PeeledOnion<T: OnionMessageContents> {
/// Forwarded onion, with the next node id and a new onion
- Forward(NextHop, OnionMessage),
+ Forward(NextMessageHop, OnionMessage),
/// Received onion message, with decrypted contents, path_id, and reply path
Receive(ParsedOnionMessageContents<T>, Option<[u8; 32]>, Option<BlindedPath>)
}
},
Ok(PeeledOnion::Forward(next_hop, onion_message)) => {
let next_node_id = match next_hop {
- NextHop::NodeId(pubkey) => pubkey,
- NextHop::ShortChannelId(scid) => match self.node_id_lookup.next_node_id(scid) {
+ NextMessageHop::NodeId(pubkey) => pubkey,
+ NextMessageHop::ShortChannelId(scid) => match self.node_id_lookup.next_node_id(scid) {
Some(pubkey) => pubkey,
None => {
log_trace!(self.logger, "Dropping forwarded onion messager: unable to resolve next hop using SCID {}", scid);
if let Some(ss) = prev_control_tlvs_ss.take() {
payloads.push((Payload::Forward(ForwardControlTlvs::Unblinded(
ForwardTlvs {
- next_hop: NextHop::NodeId(unblinded_pk_opt.unwrap()),
+ next_hop: NextMessageHop::NodeId(unblinded_pk_opt.unwrap()),
next_blinding_override: None,
}
)), ss));
} else if let Some((intro_node_id, blinding_pt)) = intro_node_id_blinding_pt.take() {
if let Some(control_tlvs_ss) = prev_control_tlvs_ss.take() {
payloads.push((Payload::Forward(ForwardControlTlvs::Unblinded(ForwardTlvs {
- next_hop: NextHop::NodeId(intro_node_id),
+ next_hop: NextMessageHop::NodeId(intro_node_id),
next_blinding_override: Some(blinding_pt),
})), control_tlvs_ss));
}
use bitcoin::secp256k1::PublicKey;
use bitcoin::secp256k1::ecdh::SharedSecret;
-use crate::blinded_path::BlindedPath;
-use crate::blinded_path::message::{ForwardTlvs, NextHop, ReceiveTlvs};
+use crate::blinded_path::{BlindedPath, NextMessageHop};
+use crate::blinded_path::message::{ForwardTlvs, ReceiveTlvs};
use crate::blinded_path::utils::Padding;
use crate::ln::msgs::DecodeError;
use crate::ln::onion_utils;
let next_hop = match (short_channel_id, next_node_id) {
(Some(_), Some(_)) => return Err(DecodeError::InvalidValue),
- (Some(scid), None) => Some(NextHop::ShortChannelId(scid)),
- (None, Some(pubkey)) => Some(NextHop::NodeId(pubkey)),
+ (Some(scid), None) => Some(NextMessageHop::ShortChannelId(scid)),
+ (None, Some(pubkey)) => Some(NextMessageHop::NodeId(pubkey)),
(None, None) => None,
};