Merge pull request #1074 from p2pderivatives/add-node-id-to-custom-msg-cb
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Wed, 15 Sep 2021 18:54:15 +0000 (18:54 +0000)
committerGitHub <noreply@github.com>
Wed, 15 Sep 2021 18:54:15 +0000 (18:54 +0000)
Add node id to custom message callback

1  2 
lightning/src/ln/peer_handler.rs

index 60d7a8750d84eea4b2bebe54a9c63771fc275a46,3c6e6b191aae71b095c53f0b843858b6d90122db..2470058f58960378f199a3e02e5703d22feb92e2
@@@ -47,7 -47,7 +47,7 @@@ use bitcoin::hashes::{HashEngine, Hash}
  pub trait CustomMessageHandler: wire::CustomMessageReader {
        /// Called with the message type that was received and the buffer to be read.
        /// Can return a `MessageHandlingError` if the message could not be handled.
-       fn handle_custom_message(&self, msg: Self::CustomMessage) -> Result<(), LightningError>;
+       fn handle_custom_message(&self, msg: Self::CustomMessage, sender_node_id: &PublicKey) -> Result<(), LightningError>;
  
        /// Gets the list of pending messages which were generated by the custom message
        /// handler, clearing the list in the process. The first tuple element must
@@@ -66,6 -66,7 +66,6 @@@ impl RoutingMessageHandler for Ignoring
        fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<bool, LightningError> { Ok(false) }
        fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
        fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<bool, LightningError> { Ok(false) }
 -      fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}
        fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) ->
                Vec<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> { Vec::new() }
        fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<msgs::NodeAnnouncement> { Vec::new() }
@@@ -101,7 -102,7 +101,7 @@@ impl wire::CustomMessageReader for Igno
  }
  
  impl CustomMessageHandler for IgnoringMessageHandler {
-       fn handle_custom_message(&self, _msg: Self::CustomMessage) -> Result<(), LightningError> {
+       fn handle_custom_message(&self, _msg: Self::CustomMessage, _sender_node_id: &PublicKey) -> Result<(), LightningError> {
                // Since we always return `None` in the read the handle method should never be called.
                unreachable!();
        }
@@@ -1086,7 -1087,7 +1086,7 @@@ impl<Descriptor: SocketDescriptor, CM: 
                                log_trace!(self.logger, "Received unknown odd message of type {}, ignoring", type_id);
                        },
                        wire::Message::Custom(custom) => {
-                               self.custom_message_handler.handle_custom_message(custom)?;
+                               self.custom_message_handler.handle_custom_message(custom, &peer.their_node_id.unwrap())?;
                        },
                };
                Ok(should_forward)
                                                let peer = get_peer_for_forwarding!(node_id);
                                                peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg)));
                                        },
 -                                      MessageSendEvent::PaymentFailureNetworkUpdate { ref update } => {
 -                                              self.message_handler.route_handler.handle_htlc_fail_channel_update(update);
 -                                      },
                                        MessageSendEvent::HandleError { ref node_id, ref action } => {
                                                match *action {
                                                        msgs::ErrorAction::DisconnectPeer { ref msg } => {