($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::UnknownRequiredFeature => {
+ log_debug!(self, "Got a channel/node announcement with an known required feature flag, you may want to udpate!");
+ continue;
+ },
+ 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 }),
+ }
}
};
}
}
},
17 => {
- // Error msg
+ let msg = try_potential_decodeerror!(msgs::ErrorMessage::decode(&msg_data[2..]));
+ let mut data_is_printable = true;
+ for b in msg.data.bytes() {
+ if b < 32 || b > 126 {
+ data_is_printable = false;
+ break;
+ }
+ }
+
+ if data_is_printable {
+ log_debug!(self, "Got Err message from {}: {}", log_pubkey!(peer.their_node_id.unwrap()), msg.data);
+ } else {
+ log_debug!(self, "Got Err message from {} with non-ASCII error message", log_pubkey!(peer.their_node_id.unwrap()));
+ }
+ self.message_handler.chan_handler.handle_error(&peer.their_node_id.unwrap(), &msg);
+ if msg.channel_id == [0; 32] {
+ return Err(PeerHandleError{ no_connection_possible: true });
+ }
},
18 => {
}
},
257 => {
- let msg = try_ignore_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..]));
- try_potential_handleerror!(self.message_handler.route_handler.handle_node_announcement(&msg));
+ let msg = try_potential_decodeerror!(msgs::NodeAnnouncement::decode(&msg_data[2..]));
+ 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 {
};
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!"),
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(),
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;
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 {
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[..]));