From c56cd1ef3a6e9dc586ac6eb60d438e6b2e88ee7c Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 10 Jun 2021 18:20:16 +0000 Subject: [PATCH] Forward gossip msgs --- lightning/src/ln/peer_handler.rs | 48 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 0497fae15..d7d52a058 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -658,6 +658,8 @@ impl PeerManager panic!("Descriptor for read_event is not already known to PeerManager"), Some(peer) => { @@ -793,13 +795,18 @@ impl PeerManager match handling_error { MessageHandlingError::PeerHandleError(e) => { return Err(e) }, MessageHandlingError::LightningError(e) => { try_potential_handleerror!(Err(e)); }, - } + }, + Ok(Some(msg)) => { + peer_node_id = Some(peer.their_node_id.expect("After noise is complete, their_node_id is always set")); + msgs_to_forward.push(msg); + }, + Ok(None) => {}, } } } @@ -811,6 +818,10 @@ impl PeerManager PeerManager, peer: &mut Peer, peer_descriptor: Descriptor, message: wire::Message) -> Result<(), MessageHandlingError> { + /// Returns the message back if it needs to be broadcasted to all other peers. + fn handle_message(&self, peers_needing_send: &mut HashSet, peer: &mut Peer, peer_descriptor: Descriptor, message: wire::Message) -> Result, MessageHandlingError> { log_trace!(self.logger, "Received message of type {} from {}", message.type_id(), log_pubkey!(peer.their_node_id.unwrap())); // Need an Init as first message @@ -828,6 +840,8 @@ impl PeerManager { @@ -950,34 +964,28 @@ impl PeerManager { - let should_forward = match self.message_handler.route_handler.handle_channel_announcement(&msg) { + if match self.message_handler.route_handler.handle_channel_announcement(&msg) { Ok(v) => v, Err(e) => { return Err(e.into()); }, - }; - - if should_forward { - // TODO: forward msg along to all our other peers! + } { + should_forward = Some(wire::Message::ChannelAnnouncement(msg)); } }, wire::Message::NodeAnnouncement(msg) => { - let should_forward = match self.message_handler.route_handler.handle_node_announcement(&msg) { + if match self.message_handler.route_handler.handle_node_announcement(&msg) { Ok(v) => v, Err(e) => { return Err(e.into()); }, - }; - - if should_forward { - // TODO: forward msg along to all our other peers! + } { + should_forward = Some(wire::Message::NodeAnnouncement(msg)); } }, wire::Message::ChannelUpdate(msg) => { self.message_handler.chan_handler.handle_channel_update(&peer.their_node_id.unwrap(), &msg); - let should_forward = match self.message_handler.route_handler.handle_channel_update(&msg) { + if match self.message_handler.route_handler.handle_channel_update(&msg) { Ok(v) => v, Err(e) => { return Err(e.into()); }, - }; - - if should_forward { - // TODO: forward msg along to all our other peers! + } { + should_forward = Some(wire::Message::ChannelUpdate(msg)); } }, wire::Message::QueryShortChannelIds(msg) => { @@ -1006,7 +1014,7 @@ impl PeerManager, msg: &wire::Message, except_node: Option<&PublicKey>) { -- 2.39.5