//! Onion message testing and test utilities live here.
use crate::blinded_path::{BlindedPath, EmptyNodeIdLookUp};
+use crate::blinded_path::message::ForwardNode;
use crate::events::{Event, EventsProvider};
use crate::ln::features::{ChannelFeatures, InitFeatures};
use crate::ln::msgs::{self, DecodeError, OnionMessageHandler};
use crate::sign::{NodeSigner, Recipient};
use crate::util::ser::{FixedLengthReader, LengthReadable, Writeable, Writer};
use crate::util::test_utils;
-use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, SendError};
+use super::messenger::{CustomOnionMessageHandler, DefaultMessageRouter, Destination, OnionMessagePath, OnionMessenger, PendingOnionMessage, Responder, ResponseInstruction, SendError};
use super::offers::{OffersMessage, OffersMessageHandler};
use super::packet::{OnionMessageContents, Packet};
struct TestOffersMessageHandler {}
impl OffersMessageHandler for TestOffersMessageHandler {
- fn handle_message(&self, _message: OffersMessage) -> Option<OffersMessage> {
- None
+ fn handle_message(&self, _message: OffersMessage, _responder: Option<Responder>) -> ResponseInstruction<OffersMessage> {
+ ResponseInstruction::NoResponse
}
}
TestCustomMessage::Response => CUSTOM_RESPONSE_MESSAGE_TYPE,
}
}
+ fn msg_type(&self) -> &'static str {
+ "Custom Message"
+ }
}
impl Writeable for TestCustomMessage {
impl CustomOnionMessageHandler for TestCustomMessageHandler {
type CustomMessage = TestCustomMessage;
- fn handle_custom_message(&self, msg: Self::CustomMessage) -> Option<Self::CustomMessage> {
+ fn handle_custom_message(&self, msg: Self::CustomMessage, responder: Option<Responder>) -> ResponseInstruction<Self::CustomMessage> {
match self.expected_messages.lock().unwrap().pop_front() {
Some(expected_msg) => assert_eq!(expected_msg, msg),
None => panic!("Unexpected message: {:?}", msg),
}
-
- match msg {
+ let response_option = match msg {
TestCustomMessage::Request => Some(TestCustomMessage::Response),
TestCustomMessage::Response => None,
+ };
+ if let (Some(response), Some(responder)) = (response_option, responder) {
+ responder.respond(response)
+ } else {
+ ResponseInstruction::NoResponse
}
}
fn read_custom_message<R: io::Read>(&self, message_type: u64, buffer: &mut R) -> Result<Option<Self::CustomMessage>, DecodeError> where Self: Sized {
let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
- let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
+ let blinded_path = BlindedPath::new_for_message(&[], nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
- let blinded_path = BlindedPath::new_for_message(&[nodes[3].node_id, nodes[4].node_id], &*nodes[4].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [ForwardNode { node_id: nodes[3].node_id, short_channel_id: None }];
+ let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[4].node_id, &*nodes[4].entropy_source, &secp_ctx).unwrap();
let path = OnionMessagePath {
intermediate_nodes: vec![nodes[1].node_id, nodes[2].node_id],
destination: Destination::BlindedPath(blinded_path),
let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
- let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id, nodes[3].node_id], &*nodes[3].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [
+ ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+ ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+ ];
+ let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, &*nodes[3].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
- let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [
+ ForwardNode { node_id: nodes[0].node_id, short_channel_id: None },
+ ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+ ];
+ let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
nodes[0].messenger.send_onion_message(test_msg.clone(), destination, None).unwrap();
pass_along_path(&nodes);
// Try with a two-hop blinded path where we are the introduction node.
- let blinded_path = BlindedPath::new_for_message(&[nodes[0].node_id, nodes[1].node_id], &*nodes[1].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [ForwardNode { node_id: nodes[0].node_id, short_channel_id: None }];
+ let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[1].node_id, &*nodes[1].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap();
nodes[1].custom_message_handler.expect_message(TestCustomMessage::Response);
let test_msg = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
- let mut blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
+ let mut blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx).unwrap();
blinded_path.blinded_hops.clear();
let destination = Destination::BlindedPath(blinded_path);
let err = nodes[0].messenger.send_onion_message(test_msg, destination, None).unwrap_err();
destination: Destination::Node(nodes[3].node_id),
first_node_addresses: None,
};
- let reply_path = BlindedPath::new_for_message(&[nodes[2].node_id, nodes[1].node_id, nodes[0].node_id], &*nodes[0].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [
+ ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+ ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+ ];
+ let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
nodes[0].messenger.send_onion_message_using_path(path, test_msg.clone(), Some(reply_path)).unwrap();
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
pass_along_path(&nodes);
pass_along_path(&nodes);
// Destination::BlindedPath
- let blinded_path = BlindedPath::new_for_message(&[nodes[1].node_id, nodes[2].node_id, nodes[3].node_id], &*nodes[3].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [
+ ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+ ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+ ];
+ let blinded_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[3].node_id, &*nodes[3].entropy_source, &secp_ctx).unwrap();
let destination = Destination::BlindedPath(blinded_path);
- let reply_path = BlindedPath::new_for_message(&[nodes[2].node_id, nodes[1].node_id, nodes[0].node_id], &*nodes[0].entropy_source, &secp_ctx).unwrap();
+ let intermediate_nodes = [
+ ForwardNode { node_id: nodes[2].node_id, short_channel_id: None },
+ ForwardNode { node_id: nodes[1].node_id, short_channel_id: None },
+ ];
+ let reply_path = BlindedPath::new_for_message(&intermediate_nodes, nodes[0].node_id, &*nodes[0].entropy_source, &secp_ctx).unwrap();
nodes[0].messenger.send_onion_message(test_msg, destination, Some(reply_path)).unwrap();
nodes[3].custom_message_handler.expect_message(TestCustomMessage::Request);
// Onion message contents must have a TLV >= 64.
63
}
+ fn msg_type(&self) -> &'static str {
+ "Invalid Message"
+ }
}
impl Writeable for InvalidCustomMessage {
let secp_ctx = Secp256k1::new();
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
+ let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let blinded_path = BlindedPath::new_for_message(
- &[nodes[1].node_id, nodes[2].node_id], &*nodes[0].entropy_source, &secp_ctx
+ &intermediate_nodes, nodes[2].node_id, &*nodes[0].entropy_source, &secp_ctx
).unwrap();
let destination = Destination::BlindedPath(blinded_path);
let secp_ctx = Secp256k1::new();
add_channel_to_graph(&nodes[0], &nodes[1], &secp_ctx, 42);
+ let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let blinded_path = BlindedPath::new_for_message(
- &[nodes[1].node_id, nodes[2].node_id], &*nodes[0].entropy_source, &secp_ctx
+ &intermediate_nodes, nodes[2].node_id, &*nodes[0].entropy_source, &secp_ctx
).unwrap();
let destination = Destination::BlindedPath(blinded_path);
let message = TestCustomMessage::Response;
let secp_ctx = Secp256k1::new();
+ let intermediate_nodes = [ForwardNode { node_id: nodes[1].node_id, short_channel_id: None }];
let blinded_path = BlindedPath::new_for_message(
- &[nodes[1].node_id, nodes[2].node_id], &*nodes[2].entropy_source, &secp_ctx
+ &intermediate_nodes, nodes[2].node_id, &*nodes[2].entropy_source, &secp_ctx
).unwrap();
let destination = Destination::BlindedPath(blinded_path);