Ok(OnionMessagePath {
intermediate_nodes: vec![],
destination,
+ addresses: None,
})
}
}
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::Node(nodes[1].get_node_pk()),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
let path = OnionMessagePath {
intermediate_nodes: vec![nodes[1].get_node_pk()],
destination: Destination::Node(nodes[2].get_node_pk()),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
nodes[2].custom_message_handler.expect_message(TestCustomMessage::Response);
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
let path = OnionMessagePath {
intermediate_nodes: vec![nodes[1].get_node_pk(), nodes[2].get_node_pk()],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
let path = OnionMessagePath {
intermediate_nodes: hops,
destination: Destination::Node(hop_node_id),
+ addresses: None,
};
let err = nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap_err();
assert_eq!(err, SendError::TooBigPacket);
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), None).unwrap();
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
let err = nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), None).unwrap_err();
assert_eq!(err, SendError::TooFewBlindedHops);
let path = OnionMessagePath {
intermediate_nodes: vec![nodes[1].get_node_pk(), nodes[2].get_node_pk()],
destination: Destination::Node(nodes[3].get_node_pk()),
+ addresses: None,
};
let reply_path = BlindedPath::new_for_message(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap();
nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), Some(reply_path)).unwrap();
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::BlindedPath(blinded_path),
+ addresses: None,
};
let reply_path = BlindedPath::new_for_message(&[nodes[2].get_node_pk(), nodes[1].get_node_pk(), nodes[0].get_node_pk()], &*nodes[0].keys_manager, &secp_ctx).unwrap();
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::Node(nodes[1].get_node_pk()),
+ addresses: None,
};
let err = nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap_err();
assert_eq!(err, SendError::InvalidMessage);
let path = OnionMessagePath {
intermediate_nodes: vec![],
destination: Destination::Node(nodes[1].get_node_pk()),
+ addresses: None,
};
for _ in 0..188 { // Based on MAX_PER_PEER_BUFFER_SIZE in OnionMessenger
nodes[0].messenger.send_onion_message_using_path(path.clone(), test_msg.clone(), None).unwrap();
let path = OnionMessagePath {
intermediate_nodes,
destination: Destination::Node(nodes[num_nodes-1].get_node_pk()),
+ addresses: None,
};
nodes[0].messenger.send_onion_message_using_path(path, test_msg, None).unwrap();
nodes[num_nodes-1].custom_message_handler.expect_message(TestCustomMessage::Response);
#[cfg(not(c_bindings))]
use crate::ln::channelmanager::{SimpleArcChannelManager, SimpleRefChannelManager};
use crate::ln::features::{InitFeatures, NodeFeatures};
-use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler};
+use crate::ln::msgs::{self, OnionMessage, OnionMessageHandler, SocketAddress};
use crate::ln::onion_utils;
use crate::ln::peer_handler::IgnoringMessageHandler;
use crate::routing::gossip::NetworkGraph;
/// # Ok(OnionMessagePath {
/// # intermediate_nodes: vec![hop_node_id1, hop_node_id2],
/// # destination,
+/// # addresses: None,
/// # })
/// # }
/// # }
&self, _sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
) -> Result<OnionMessagePath, ()> {
if peers.contains(&destination.first_node()) {
- Ok(OnionMessagePath { intermediate_nodes: vec![], destination })
+ Ok(OnionMessagePath { intermediate_nodes: vec![], destination, addresses: None })
} else {
Err(())
}
/// The recipient of the message.
pub destination: Destination,
+
+ /// Addresses that may be used to connect to [`OnionMessagePath::first_node`].
+ ///
+ /// Only needs to be set if a connection to the node is required. [`OnionMessenger`] may use
+ /// this to initiate such a connection.
+ pub addresses: Option<Vec<SocketAddress>>,
+}
+
+impl OnionMessagePath {
+ /// Returns the first node in the path.
+ pub fn first_node(&self) -> PublicKey {
+ self.intermediate_nodes
+ .first()
+ .copied()
+ .unwrap_or_else(|| self.destination.first_node())
+ }
}
/// The destination of an onion message.
ES::Target: EntropySource,
NS::Target: NodeSigner,
{
- let OnionMessagePath { intermediate_nodes, mut destination } = path;
+ let OnionMessagePath { intermediate_nodes, mut destination, .. } = path;
if let Destination::BlindedPath(BlindedPath { ref blinded_hops, .. }) = destination {
if blinded_hops.is_empty() {
return Err(SendError::TooFewBlindedHops);