X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fpeer_handler.rs;h=d3ac2ebe9a39bf2e918f58dbf4d012ac0434ae99;hb=996d3d8058f2342b9e23d53f9dd81ae472822120;hp=6607d986affd062eee04fb987256d571cec88bb4;hpb=1b3249a1929929170bba9d2553d7a9c8670193e5;p=rust-lightning diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 6607d986..d3ac2ebe 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -307,12 +307,12 @@ const OUTBOUND_BUFFER_LIMIT_DROP_GOSSIP: usize = OUTBOUND_BUFFER_LIMIT_READ_PAUS /// Thus, to avoid needlessly disconnecting a peer, we allow a peer to take this many timer ticks /// per connected peer to respond to a ping, as long as they send us at least one message during /// each tick, ensuring we aren't actually just disconnected. -/// With a timer tick interval of five seconds, this translates to about 30 seconds per connected +/// With a timer tick interval of ten seconds, this translates to about 40 seconds per connected /// peer. /// /// When we improve parallelism somewhat we should reduce this to e.g. this many timer ticks per /// two connected peers, assuming most LDK-running systems have at least two cores. -const MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER: i8 = 6; +const MAX_BUFFER_DRAIN_TICK_INTERVALS_PER_PEER: i8 = 4; /// This is the minimum number of messages we expect a peer to be able to handle within one timer /// tick. Once we have sent this many messages since the last ping, we send a ping right away to @@ -902,25 +902,40 @@ impl P Ok(x) => x, Err(e) => { match e { - msgs::DecodeError::UnknownVersion => return Err(PeerHandleError { no_connection_possible: false }), - msgs::DecodeError::UnknownRequiredFeature => { + // Note that to avoid recursion we never call + // `do_attempt_write_data` from here, causing + // the messages enqueued here to not actually + // be sent before the peer is disconnected. + (msgs::DecodeError::UnknownRequiredFeature, Some(ty)) if is_gossip_msg(ty) => { log_gossip!(self.logger, "Got a channel/node announcement with an unknown required feature flag, you may want to update!"); continue; } - msgs::DecodeError::InvalidValue => { + (msgs::DecodeError::UnsupportedCompression, _) => { + log_gossip!(self.logger, "We don't support zlib-compressed message fields, sending a warning and ignoring message"); + self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: "Unsupported message compression: zlib".to_owned() }); + continue; + } + (_, Some(ty)) if is_gossip_msg(ty) => { + log_gossip!(self.logger, "Got an invalid value while deserializing a gossip message"); + self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: "Unreadable/bogus gossip message".to_owned() }); + continue; + } + (msgs::DecodeError::UnknownRequiredFeature, ty) => { + log_gossip!(self.logger, "Received a message with an unknown required feature flag or TLV, you may want to update!"); + self.enqueue_message(peer, &msgs::WarningMessage { channel_id: [0; 32], data: format!("Received an unknown required feature/TLV in message type {:?}", ty) }); + return Err(PeerHandleError { no_connection_possible: false }); + } + (msgs::DecodeError::UnknownVersion, _) => return Err(PeerHandleError { no_connection_possible: false }), + (msgs::DecodeError::InvalidValue, _) => { log_debug!(self.logger, "Got an invalid value while deserializing message"); return Err(PeerHandleError { no_connection_possible: false }); } - msgs::DecodeError::ShortRead => { + (msgs::DecodeError::ShortRead, _) => { log_debug!(self.logger, "Deserialization failed due to shortness of message"); return Err(PeerHandleError { no_connection_possible: false }); } - msgs::DecodeError::BadLengthDescriptor => return Err(PeerHandleError { no_connection_possible: false }), - msgs::DecodeError::Io(_) => return Err(PeerHandleError { no_connection_possible: false }), - msgs::DecodeError::UnsupportedCompression => { - log_gossip!(self.logger, "We don't support zlib-compressed message fields, ignoring message"); - continue; - } + (msgs::DecodeError::BadLengthDescriptor, _) => return Err(PeerHandleError { no_connection_possible: false }), + (msgs::DecodeError::Io(_), _) => return Err(PeerHandleError { no_connection_possible: false }), } } }; @@ -1557,9 +1572,9 @@ impl P /// Send pings to each peer and disconnect those which did not respond to the last round of /// pings. /// - /// This may be called on any timescale you want, however, roughly once every five to ten - /// seconds is preferred. The call rate determines both how often we send a ping to our peers - /// and how much time they have to respond before we disconnect them. + /// This may be called on any timescale you want, however, roughly once every ten seconds is + /// preferred. The call rate determines both how often we send a ping to our peers and how much + /// time they have to respond before we disconnect them. /// /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy /// issues!