Merge pull request #3038 from TheBlueMatt/2024-05-no-dir-with-on-side-offline
[rust-lightning] / lightning / src / onion_message / functional_tests.rs
index eb0b17246c3f2eac9f8c93afd5857235adf0e973..764a2bdcbdcd198f901e722e388d3d3bcc4e86b6 100644 (file)
@@ -18,7 +18,7 @@ use crate::routing::test_utils::{add_channel, add_or_update_node};
 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};
 
@@ -73,8 +73,8 @@ impl Drop for MessengerNode {
 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
        }
 }
 
@@ -96,6 +96,9 @@ impl OnionMessageContents for TestCustomMessage {
                        TestCustomMessage::Response => CUSTOM_RESPONSE_MESSAGE_TYPE,
                }
        }
+       fn msg_type(&self) -> &'static str {
+               "Custom Message"
+       }
 }
 
 impl Writeable for TestCustomMessage {
@@ -134,15 +137,19 @@ impl Drop for TestCustomMessageHandler {
 
 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 {
@@ -461,6 +468,9 @@ fn invalid_custom_message_type() {
                        // Onion message contents must have a TLV >= 64.
                        63
                }
+               fn msg_type(&self) -> &'static str {
+                       "Invalid Message"
+               }
        }
 
        impl Writeable for InvalidCustomMessage {