From: Matt Corallo Date: Wed, 29 Aug 2018 21:53:11 +0000 (-0400) Subject: Also fwd channel_update and node_announcement immediately X-Git-Tag: v0.0.12~334^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=f78d7299d66387dbb531cf925483e2f826fdb910;p=rust-lightning Also fwd channel_update and node_announcement immediately Not really sure why the API was different for channel_announcement, but this brings everything in sync. --- diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index 072383c11..034a580c0 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -462,11 +462,11 @@ pub trait ChannelMessageHandler : events::EventsProvider + Send + Sync { } pub trait RoutingMessageHandler : Send + Sync { - fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result<(), HandleError>; + fn handle_node_announcement(&self, msg: &NodeAnnouncement) -> Result; /// Handle a channel_announcement message, returning true if it should be forwarded on, false /// or returning an Err otherwise. fn handle_channel_announcement(&self, msg: &ChannelAnnouncement) -> Result; - fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<(), HandleError>; + fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result; fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate); } diff --git a/src/ln/peer_handler.rs b/src/ln/peer_handler.rs index 9d5f58d7f..3122e572e 100644 --- a/src/ln/peer_handler.rs +++ b/src/ln/peer_handler.rs @@ -579,11 +579,19 @@ impl PeerManager { }, 257 => { let msg = try_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..])); - try_potential_handleerror!(self.message_handler.route_handler.handle_node_announcement(&msg)); + let should_forward = try_potential_handleerror!(self.message_handler.route_handler.handle_node_announcement(&msg)); + + if should_forward { + // TODO: forward msg along to all our other peers! + } }, 258 => { let msg = try_potential_decodeerror!(msgs::ChannelUpdate::decode(&msg_data[2..])); - try_potential_handleerror!(self.message_handler.route_handler.handle_channel_update(&msg)); + let should_forward = try_potential_handleerror!(self.message_handler.route_handler.handle_channel_update(&msg)); + + if should_forward { + // TODO: forward msg along to all our other peers! + } }, _ => { if (msg_type & 1) == 0 { diff --git a/src/ln/router.rs b/src/ln/router.rs index 5f0cff3cd..a71eb913c 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -168,7 +168,7 @@ macro_rules! secp_verify_sig { } impl RoutingMessageHandler for Router { - fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result<(), HandleError> { + fn handle_node_announcement(&self, msg: &msgs::NodeAnnouncement) -> Result { let msg_hash = Message::from_slice(&Sha256dHash::from_data(&msg.contents.encode()[..])[..]).unwrap(); secp_verify_sig!(self.secp_ctx, &msg_hash, &msg.signature, &msg.contents.node_id); @@ -189,7 +189,7 @@ impl RoutingMessageHandler for Router { node.rgb = msg.contents.rgb; node.alias = msg.contents.alias; node.addresses = msg.contents.addresses.clone(); - Ok(()) + Ok(msg.contents.excess_data.is_empty() && msg.contents.excess_address_data.is_empty() && !msg.contents.features.supports_unknown_bits()) } } } @@ -289,7 +289,7 @@ impl RoutingMessageHandler for Router { } } - fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result<(), HandleError> { + fn handle_channel_update(&self, msg: &msgs::ChannelUpdate) -> Result { let mut network = self.network_map.write().unwrap(); let dest_node_id; let chan_enabled = msg.contents.flags & (1 << 1) != (1 << 1); @@ -355,7 +355,7 @@ impl RoutingMessageHandler for Router { mut_node.lowest_inbound_channel_fee_proportional_millionths = lowest_inbound_channel_fee_proportional_millionths; } - Ok(()) + Ok(msg.contents.excess_data.is_empty()) } } diff --git a/src/util/test_utils.rs b/src/util/test_utils.rs index dc158230f..52e44f92a 100644 --- a/src/util/test_utils.rs +++ b/src/util/test_utils.rs @@ -136,13 +136,13 @@ impl TestRoutingMessageHandler { } impl msgs::RoutingMessageHandler for TestRoutingMessageHandler { - fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result<(), HandleError> { + fn handle_node_announcement(&self, _msg: &msgs::NodeAnnouncement) -> Result { Err(HandleError { err: "", action: None }) } fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result { Err(HandleError { err: "", action: None }) } - fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<(), HandleError> { + fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result { Err(HandleError { err: "", action: None }) } fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}