]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Ensure we never send messages prior to Init for BOLT 1 compliance
authorMatt Corallo <git@bluematt.me>
Sat, 25 Aug 2018 18:32:02 +0000 (14:32 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 25 Aug 2018 18:49:18 +0000 (14:49 -0400)
src/ln/peer_handler.rs

index 4ab039741565521c3813c0d93980f8b834e29d15..53788b3f265bf53b3505c4b10adc8d372ba1bfc2 100644 (file)
@@ -621,6 +621,10 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                        };
                                                        match peers.peers.get_mut(&descriptor) {
                                                                Some(peer) => {
+                                                                       if peer.their_global_features.is_none() {
+                                                                               $handle_no_such_peer;
+                                                                               continue;
+                                                                       }
                                                                        (descriptor, peer)
                                                                },
                                                                None => panic!("Inconsistent peers set state!"),
@@ -717,7 +721,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                        let encoded_update_msg = encode_msg!(update_msg, 258);
 
                                                        for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
-                                                               if !peer.channel_encryptor.is_ready_for_encryption() {
+                                                               if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_global_features.is_none() {
                                                                        continue
                                                                }
                                                                match peer.their_node_id {
@@ -741,7 +745,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                        let encoded_msg = encode_msg!(msg, 258);
 
                                                        for (ref descriptor, ref mut peer) in peers.peers.iter_mut() {
-                                                               if !peer.channel_encryptor.is_ready_for_encryption() {
+                                                               if !peer.channel_encryptor.is_ready_for_encryption() || peer.their_global_features.is_none() {
                                                                        continue
                                                                }
                                                                peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encoded_msg[..]));