]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Also fwd channel_update and node_announcement immediately 2018-08-excess-signed-data-bolt-7
authorMatt Corallo <git@bluematt.me>
Wed, 29 Aug 2018 21:53:11 +0000 (17:53 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 29 Aug 2018 22:07:56 +0000 (18:07 -0400)
Not really sure why the API was different for channel_announcement,
but this brings everything in sync.

src/ln/msgs.rs
src/ln/peer_handler.rs
src/ln/router.rs
src/util/test_utils.rs

index 072383c11cab4a1670e0dfe322a0315d5daebe1c..034a580c018aa727e50d29292aaea8d9e5bca4e5 100644 (file)
@@ -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<bool, HandleError>;
        /// 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<bool, HandleError>;
-       fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<(), HandleError>;
+       fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<bool, HandleError>;
        fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate);
 }
 
index 9d5f58d7fb861b5898a08b331ccf2b1680acef21..3122e572e57fafcbd90e1c08c6c10b146d152c29 100644 (file)
@@ -579,11 +579,19 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                                        },
                                                                                        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 {
index 5f0cff3cdcff00b943d9232990a5d236fe8b0390..a71eb913ce521c1765087ba27a79b2bf8b2a293e 100644 (file)
@@ -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<bool, HandleError> {
                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<bool, HandleError> {
                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())
        }
 }
 
index dc158230fad812acb467fcc05f08487f34d2c936..52e44f92abca02f5fa14e77dc97ecf3b21f728de 100644 (file)
@@ -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<bool, HandleError> {
                Err(HandleError { err: "", action: None })
        }
        fn handle_channel_announcement(&self, _msg: &msgs::ChannelAnnouncement) -> Result<bool, HandleError> {
                Err(HandleError { err: "", action: None })
        }
-       fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<(), HandleError> {
+       fn handle_channel_update(&self, _msg: &msgs::ChannelUpdate) -> Result<bool, HandleError> {
                Err(HandleError { err: "", action: None })
        }
        fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}