},
Err(e) => {
mem::drop(channel_state);
- add_pending_event!(events::Event::DisconnectPeer {
+ add_pending_event!(events::Event::HandleError {
node_id: chan.get_their_node_id(),
- msg: if let Some(msgs::ErrorAction::DisconnectPeer { msg } ) = e.action { msg } else { None },
+ action: e.action,
});
-
return;
},
}
}
let mut pending_events = self.pending_events.lock().unwrap();
+ //TODO: replace by HandleError ? UpdateFailHTLC in handle_update_add_htlc need also to build a CommitmentSigned
pending_events.push(events::Event::SendFailHTLC {
node_id,
msg: msg,
});
short_to_id.insert(channel.get_short_channel_id().unwrap(), channel.channel_id());
} else if let Err(e) = chan_res {
- if let Some(msgs::ErrorAction::DisconnectPeer { msg }) = e.action {
- new_events.push(events::Event::DisconnectPeer {
- node_id: channel.get_their_node_id(),
- msg: msg
- });
- } else { unreachable!(); }
+ new_events.push(events::Event::HandleError {
+ node_id: channel.get_their_node_id(),
+ action: e.action,
+ });
if channel.is_shutdown() {
return false;
}
}
continue;
},
- Event::DisconnectPeer { ref node_id, ref msg } => {
- if let Some(mut descriptor) = peers.node_id_to_descriptor.remove(node_id) {
- if let Some(mut peer) = peers.peers.remove(&descriptor) {
- if let Some(ref msg) = *msg {
+ Event::HandleError { ref node_id, ref action } => {
+ if let Some(ref action) = *action {
+ match *action {
+ msgs::ErrorAction::UpdateFailHTLC { ref msg } => {
+ let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
+ //TODO: Do whatever we're gonna do for handling dropped messages
+ });
+ peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 131)));
+ Self::do_attempt_write_data(&mut descriptor, peer);
+
+ },
+ msgs::ErrorAction::DisconnectPeer { ref msg } => {
+ if let Some(mut descriptor) = peers.node_id_to_descriptor.remove(node_id) {
+ if let Some(mut peer) = peers.peers.remove(&descriptor) {
+ if let Some(ref msg) = *msg {
+ peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 17)));
+ // This isn't guaranteed to work, but if there is enough free
+ // room in the send buffer, put the error message there...
+ Self::do_attempt_write_data(&mut descriptor, &mut peer);
+ }
+ }
+ descriptor.disconnect_socket();
+ self.message_handler.chan_handler.peer_disconnected(&node_id, false);
+ }
+ },
+ msgs::ErrorAction::IgnoreError => {
+ continue;
+ },
+ msgs::ErrorAction::SendErrorMessage { ref msg } => {
+ let (mut descriptor, peer) = get_peer_for_forwarding!(node_id, {
+ //TODO: Do whatever we're gonna do for handling dropped messages
+ });
peer.pending_outbound_buffer.push_back(peer.channel_encryptor.encrypt_message(&encode_msg!(msg, 17)));
- // This isn't guaranteed to work, but if there is enough free
- // room in the send buffer, put the error message there...
- Self::do_attempt_write_data(&mut descriptor, &mut peer);
- }
+ Self::do_attempt_write_data(&mut descriptor, peer);
+ },
}
- descriptor.disconnect_socket();
- self.message_handler.chan_handler.peer_disconnected(&node_id, false);
}
continue;
- },
+ }
}
upstream_events.push(event);
#[cfg(test)]
mod tests {
use ln::peer_handler::{PeerManager, MessageHandler, SocketDescriptor};
+ use ln::msgs;
use util::events;
use util::test_utils;
let their_id = PublicKey::from_secret_key(&secp_ctx, &peers[1].our_node_secret).unwrap();
let chan_handler = test_utils::TestChannelMessageHandler::new();
- chan_handler.pending_events.lock().unwrap().push(events::Event::DisconnectPeer {
+ chan_handler.pending_events.lock().unwrap().push(events::Event::HandleError {
node_id: their_id,
- msg: None,
+ action: Some(msgs::ErrorAction::DisconnectPeer { msg: None }),
});
assert_eq!(chan_handler.pending_events.lock().unwrap().len(), 1);
peers[0].message_handler.chan_handler = Arc::new(chan_handler);