Update msg_targets with new, must-roundtrip, and hole messages
[rust-lightning] / src / ln / peer_handler.rs
index f941f47dc10e5c99f13460b5aa82b96fba3a13c4..7af4c0e29f2c1f36f38f71237b01ae5e0fb91a20 100644 (file)
@@ -331,21 +331,19 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                ($thing: expr) => {
                                                                        match $thing {
                                                                                Ok(x) => x,
-                                                                               Err(_e) => {
-                                                                                       //TODO: Handle e?
-                                                                                       return Err(PeerHandleError{ no_connection_possible: false });
-                                                                               }
-                                                                       };
-                                                               }
-                                                       }
-
-                                                       macro_rules! try_ignore_potential_decodeerror {
-                                                               ($thing: expr) => {
-                                                                       match $thing {
-                                                                               Ok(x) => x,
-                                                                               Err(_e) => {
-                                                                                       log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407");
-                                                                                       continue;
+                                                                               Err(e) => {
+                                                                                       match e {
+                                                                                               msgs::DecodeError::UnknownRealmByte => return Err(PeerHandleError{ no_connection_possible: false }),
+                                                                                               msgs::DecodeError::BadPublicKey => return Err(PeerHandleError{ no_connection_possible: false }),
+                                                                                               msgs::DecodeError::BadSignature => return Err(PeerHandleError{ no_connection_possible: false }),
+                                                                                               msgs::DecodeError::BadText => return Err(PeerHandleError{ no_connection_possible: false }),
+                                                                                               msgs::DecodeError::ShortRead => return Err(PeerHandleError{ no_connection_possible: false }),
+                                                                                               msgs::DecodeError::ExtraAddressesPerType => {
+                                                                                                       log_debug!(self, "Error decoding message, ignoring due to lnd spec incompatibility. See https://github.com/lightningnetwork/lnd/issues/1407");
+                                                                                                       continue;
+                                                                                               },
+                                                                                               msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError{ no_connection_possible: false }),
+                                                                                       }
                                                                                }
                                                                        };
                                                                }
@@ -576,7 +574,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                                                }
                                                                                        },
                                                                                        257 => {
-                                                                                               let msg = try_ignore_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..]));
+                                                                                               let msg = try_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..]));
                                                                                                try_potential_handleerror!(self.message_handler.route_handler.handle_node_announcement(&msg));
                                                                                        },
                                                                                        258 => {
@@ -697,7 +695,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                Self::do_attempt_write_data(&mut descriptor, peer);
                                                continue;
                                        },
-                                       Event::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref commitment_signed } } => {
+                                       Event::UpdateHTLCs { ref node_id, updates: msgs::CommitmentUpdate { ref update_add_htlcs, ref update_fulfill_htlcs, ref update_fail_htlcs, ref update_fail_malformed_htlcs, ref commitment_signed } } => {
                                                log_trace!(self, "Handling UpdateHTLCs event in peer_handler for node {} with {} adds, {} fulfills, {} fails for channel {}",
                                                                log_pubkey!(node_id),
                                                                update_add_htlcs.len(),
@@ -716,6 +714,9 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                for msg in update_fail_htlcs {
                                                        peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 131)));
                                                }
+                                               for msg in update_fail_malformed_htlcs {
+                                                       peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 135)));
+                                               }
                                                peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(commitment_signed, 132)));
                                                Self::do_attempt_write_data(&mut descriptor, peer);
                                                continue;