Split routing from getting network messages
[rust-lightning] / lightning / src / ln / peer_handler.rs
index 9399cfecf69f890cbcf5b96c033c66b7b04945d5..de0d50c7f8e4daa0298ed15bbb4c26f39a164ead 100644 (file)
@@ -6,7 +6,7 @@
 //! call into the provided message handlers (probably a ChannelManager and Router) with messages
 //! they should handle, and encoding/sending response messages.
 
-use secp256k1::key::{SecretKey,PublicKey};
+use bitcoin::secp256k1::key::{SecretKey,PublicKey};
 
 use ln::features::InitFeatures;
 use ln::msgs;
@@ -26,9 +26,9 @@ use std::sync::atomic::{AtomicUsize, Ordering};
 use std::{cmp,error,hash,fmt};
 use std::ops::Deref;
 
-use bitcoin_hashes::sha256::Hash as Sha256;
-use bitcoin_hashes::sha256::HashEngine as Sha256Engine;
-use bitcoin_hashes::{HashEngine, Hash};
+use bitcoin::hashes::sha256::Hash as Sha256;
+use bitcoin::hashes::sha256::HashEngine as Sha256Engine;
+use bitcoin::hashes::{HashEngine, Hash};
 
 /// Provides references to trait impls which handle different types of messages.
 pub struct MessageHandler<CM: Deref> where CM::Target: msgs::ChannelMessageHandler {
@@ -36,7 +36,7 @@ pub struct MessageHandler<CM: Deref> where CM::Target: msgs::ChannelMessageHandl
        /// ChannelManager object.
        pub chan_handler: CM,
        /// A message handler which handles messages updating our knowledge of the network channel
-       /// graph. Usually this is just a Router object.
+       /// graph. Usually this is just a NetGraphMsgHandlerMonitor object.
        pub route_handler: Arc<msgs::RoutingMessageHandler>,
 }
 
@@ -548,7 +548,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
 
                                                                        peer.their_node_id = Some(their_node_id);
                                                                        insert_node_id!();
-                                                                       let mut features = InitFeatures::supported();
+                                                                       let mut features = InitFeatures::known();
                                                                        if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
                                                                                features.clear_initial_routing_sync();
                                                                        }
@@ -629,10 +629,11 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
                                                                                                        return Err(PeerHandleError{ no_connection_possible: false });
                                                                                                }
 
-                                                                                               log_info!(self, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, unkown local flags: {}, unknown global flags: {}",
+                                                                                               log_info!(self, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, static_remote_key: {}, unkown local flags: {}, unknown global flags: {}",
                                                                                                        if msg.features.supports_data_loss_protect() { "supported" } else { "not supported"},
                                                                                                        if msg.features.initial_routing_sync() { "requested" } else { "not requested" },
                                                                                                        if msg.features.supports_upfront_shutdown_script() { "supported" } else { "not supported"},
+                                                                                                       if msg.features.supports_static_remote_key() { "supported" } else { "not supported"},
                                                                                                        if msg.features.supports_unknown_bits() { "present" } else { "none" },
                                                                                                        if msg.features.supports_unknown_bits() { "present" } else { "none" });
 
@@ -640,9 +641,13 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
                                                                                                        peer.sync_status = InitSyncTracker::ChannelsSyncing(0);
                                                                                                        peers.peers_needing_send.insert(peer_descriptor.clone());
                                                                                                }
+                                                                                               if !msg.features.supports_static_remote_key() {
+                                                                                                       log_debug!(self, "Peer {} does not support static remote key, disconnecting with no_connection_possible", log_pubkey!(peer.their_node_id.unwrap()));
+                                                                                                       return Err(PeerHandleError{ no_connection_possible: true });
+                                                                                               }
 
                                                                                                if !peer.outbound {
-                                                                                                       let mut features = InitFeatures::supported();
+                                                                                                       let mut features = InitFeatures::known();
                                                                                                        if !self.message_handler.route_handler.should_request_full_sync(&peer.their_node_id.unwrap()) {
                                                                                                                features.clear_initial_routing_sync();
                                                                                                        }
@@ -1153,7 +1158,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
 
 #[cfg(test)]
 mod tests {
-       use secp256k1::Signature;
+       use bitcoin::secp256k1::Signature;
        use bitcoin::BitcoinHash;
        use bitcoin::network::constants::Network;
        use bitcoin::blockdata::constants::genesis_block;
@@ -1164,8 +1169,8 @@ mod tests {
        use util::test_utils;
        use util::logger::Logger;
 
-       use secp256k1::Secp256k1;
-       use secp256k1::key::{SecretKey, PublicKey};
+       use bitcoin::secp256k1::Secp256k1;
+       use bitcoin::secp256k1::key::{SecretKey, PublicKey};
 
        use rand::{thread_rng, Rng};
 
@@ -1350,7 +1355,7 @@ mod tests {
        }
 
        fn get_dummy_channel_announcement(short_chan_id: u64) -> msgs::ChannelAnnouncement {
-               use secp256k1::ffi::Signature as FFISignature;
+               use bitcoin::secp256k1::ffi::Signature as FFISignature;
                let secp_ctx = Secp256k1::new();
                let network = Network::Testnet;
                let node_1_privkey = SecretKey::from_slice(&[42; 32]).unwrap();
@@ -1358,7 +1363,7 @@ mod tests {
                let node_1_btckey = SecretKey::from_slice(&[40; 32]).unwrap();
                let node_2_btckey = SecretKey::from_slice(&[39; 32]).unwrap();
                let unsigned_ann = msgs::UnsignedChannelAnnouncement {
-                       features: ChannelFeatures::supported(),
+                       features: ChannelFeatures::known(),
                        chain_hash: genesis_block(network).header.bitcoin_hash(),
                        short_channel_id: short_chan_id,
                        node_id_1: PublicKey::from_secret_key(&secp_ctx, &node_1_privkey),
@@ -1378,7 +1383,7 @@ mod tests {
        }
 
        fn get_dummy_channel_update(short_chan_id: u64) -> msgs::ChannelUpdate {
-               use secp256k1::ffi::Signature as FFISignature;
+               use bitcoin::secp256k1::ffi::Signature as FFISignature;
                let network = Network::Testnet;
                msgs::ChannelUpdate {
                        signature: Signature::from(FFISignature::new()),