From: Matt Corallo Date: Thu, 10 Jun 2021 18:20:16 +0000 (+0000) Subject: Forward gossip msgs X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=38732ab41de1948e6c03db963f0e7bae7a521004;p=rust-lightning Forward gossip msgs --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index f03cfbea5..c7300aed3 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -659,6 +659,8 @@ impl PeerManager panic!("Descriptor for read_event is not already known to PeerManager"), Some(peer) => { @@ -794,13 +796,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) => {}, } } } @@ -812,6 +819,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 @@ -829,6 +841,8 @@ impl PeerManager { @@ -951,34 +965,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) => { @@ -1007,7 +1015,7 @@ impl PeerManager, msg: &wire::Message, except_node: Option<&PublicKey>) {