Support ignoring some errors, deserialize empty flags types
authorMatt Corallo <git@bluematt.me>
Sat, 16 Jun 2018 23:04:42 +0000 (19:04 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 16 Jun 2018 23:45:32 +0000 (19:45 -0400)
src/ln/msgs.rs
src/ln/peer_handler.rs
src/ln/router.rs

index 0a86b031eb1755401337fcf21ee051075536414e..f0f1d4890e13370f83cc3c8c633da57f7b03ce20 100644 (file)
@@ -357,7 +357,9 @@ pub enum ErrorAction {
                msg: UpdateFailHTLC
        },
        /// The peer took some action which made us think they were useless. Disconnect them.
-       DisconnectPeer {},
+       DisconnectPeer,
+       /// The peer did something harmless that we weren't able to process, just log and ignore
+       IgnoreError,
 }
 
 pub struct HandleError { //TODO: rename me
@@ -506,7 +508,7 @@ macro_rules! secp_signature {
 
 impl MsgDecodable for LocalFeatures {
        fn decode(v: &[u8]) -> Result<Self, DecodeError> {
-               if v.len() < 3 { return Err(DecodeError::WrongLength); }
+               if v.len() < 2 { return Err(DecodeError::WrongLength); }
                let len = byte_utils::slice_to_be16(&v[0..2]) as usize;
                if v.len() < len + 2 { return Err(DecodeError::WrongLength); }
                let mut flags = Vec::with_capacity(len);
@@ -528,7 +530,7 @@ impl MsgEncodable for LocalFeatures {
 
 impl MsgDecodable for GlobalFeatures {
        fn decode(v: &[u8]) -> Result<Self, DecodeError> {
-               if v.len() < 3 { return Err(DecodeError::WrongLength); }
+               if v.len() < 2 { return Err(DecodeError::WrongLength); }
                let len = byte_utils::slice_to_be16(&v[0..2]) as usize;
                if v.len() < len + 2 { return Err(DecodeError::WrongLength); }
                let mut flags = Vec::with_capacity(len);
index 7b140b0797284f04ca55d993b75a45f53be5069a..bccfe5a03b0256b365b6ad5f6d65ecbedf500db8 100644 (file)
@@ -272,16 +272,19 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                        match $thing {
                                                                                Ok(x) => x,
                                                                                Err(e) => {
-                                                                                       // TODO: Log e.err
+                                                                                       println!("Got error handling message: {}!", e.err);
                                                                                        if let Some(action) = e.msg {
                                                                                                match action {
                                                                                                        msgs::ErrorAction::UpdateFailHTLC { msg } => {
                                                                                                                encode_and_send_msg!(msg, 131);
                                                                                                                continue;
                                                                                                        },
-                                                                                                       msgs::ErrorAction::DisconnectPeer {} => {
+                                                                                                       msgs::ErrorAction::DisconnectPeer => {
                                                                                                                return Err(PeerHandleError{ no_connection_possible: false });
                                                                                                        },
+                                                                                                       msgs::ErrorAction::IgnoreError => {
+                                                                                                               continue;
+                                                                                                       },
                                                                                                }
                                                                                        } else {
                                                                                                return Err(PeerHandleError{ no_connection_possible: false });
@@ -296,6 +299,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                                                                        match $thing {
                                                                                Ok(x) => x,
                                                                                Err(_e) => {
+                                                                                       println!("Error decoding message");
                                                                                        //TODO: Handle e?
                                                                                        return Err(PeerHandleError{ no_connection_possible: false });
                                                                                }
index 19a677580a5c101fe08e78d52ac17dbee4dc0ffe..e4473fa41838d87072d87cb13747c24f984cc442 100644 (file)
@@ -3,7 +3,7 @@ use secp256k1::{Secp256k1,Message};
 
 use bitcoin::util::hash::Sha256dHash;
 
-use ln::msgs::{HandleError,RoutingMessageHandler,MsgEncodable,NetAddress,GlobalFeatures};
+use ln::msgs::{ErrorAction,HandleError,RoutingMessageHandler,MsgEncodable,NetAddress,GlobalFeatures};
 use ln::msgs;
 
 use std::cmp;
@@ -122,10 +122,10 @@ impl RoutingMessageHandler for Router {
 
                let mut network = self.network_map.write().unwrap();
                match network.nodes.get_mut(&msg.contents.node_id) {
-                       None => Err(HandleError{err: "No existing channels for node_announcement", msg: None}),
+                       None => Err(HandleError{err: "No existing channels for node_announcement", msg: Some(ErrorAction::IgnoreError)}),
                        Some(node) => {
                                if node.last_update >= msg.contents.timestamp {
-                                       return Err(HandleError{err: "Update older than last processed update", msg: None});
+                                       return Err(HandleError{err: "Update older than last processed update", msg: Some(ErrorAction::IgnoreError)});
                                }
 
                                node.features = msg.contents.features.clone();
@@ -159,7 +159,7 @@ impl RoutingMessageHandler for Router {
                                //TODO: because asking the blockchain if short_channel_id is valid is only optional
                                //in the blockchain API, we need to handle it smartly here, though its unclear
                                //exactly how...
-                               return Err(HandleError{err: "Already have knowledge of channel", msg: None})
+                               return Err(HandleError{err: "Already have knowledge of channel", msg: Some(ErrorAction::IgnoreError)})
                        },
                        Entry::Vacant(entry) => {
                                entry.insert(ChannelInfo {
@@ -233,12 +233,12 @@ impl RoutingMessageHandler for Router {
                let chan_was_enabled;
 
                match network.channels.get_mut(&NetworkMap::get_key(msg.contents.short_channel_id, msg.contents.chain_hash)) {
-                       None => return Err(HandleError{err: "Couldn't find channel for update", msg: None}),
+                       None => return Err(HandleError{err: "Couldn't find channel for update", msg: Some(ErrorAction::IgnoreError)}),
                        Some(channel) => {
                                macro_rules! maybe_update_channel_info {
                                        ( $target: expr) => {
                                                if $target.last_update >= msg.contents.timestamp {
-                                                       return Err(HandleError{err: "Update older than last processed update", msg: None});
+                                                       return Err(HandleError{err: "Update older than last processed update", msg: Some(ErrorAction::IgnoreError)});
                                                }
                                                chan_was_enabled = $target.enabled;
                                                $target.last_update = msg.contents.timestamp;