Suggest faster ping in `PeerManager::timer_tick_occurred` docs
[rust-lightning] / lightning / src / ln / peer_handler.rs
index 96ec31c98ee1b4aa289f2ba78ee32c76a4e5f22d..42b2694111f1c27764a0dc78b150178d5cb14458 100644 (file)
@@ -31,13 +31,14 @@ use util::logger::Logger;
 use routing::network_graph::NetGraphMsgHandler;
 
 use prelude::*;
+use io;
 use alloc::collections::LinkedList;
 use alloc::fmt::Debug;
-use std::sync::{Arc, Mutex};
+use sync::{Arc, Mutex};
 use core::sync::atomic::{AtomicUsize, Ordering};
 use core::{cmp, hash, fmt, mem};
 use core::ops::Deref;
-use std::error;
+#[cfg(feature = "std")] use std::error;
 
 use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hashes::sha256::HashEngine as Sha256Engine;
@@ -230,6 +231,8 @@ impl fmt::Display for PeerHandleError {
                formatter.write_str("Peer Sent Invalid Data")
        }
 }
+
+#[cfg(feature = "std")]
 impl error::Error for PeerHandleError {
        fn description(&self) -> &str {
                "Peer Sent Invalid Data"
@@ -801,7 +804,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                                                                                peer.pending_read_buffer = [0; 18].to_vec();
                                                                                peer.pending_read_is_header = true;
 
-                                                                               let mut reader = ::std::io::Cursor::new(&msg_data[..]);
+                                                                               let mut reader = io::Cursor::new(&msg_data[..]);
                                                                                let message_result = wire::read(&mut reader);
                                                                                let message = match message_result {
                                                                                        Ok(x) => x,
@@ -888,15 +891,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                                        return Err(PeerHandleError{ no_connection_possible: false }.into());
                                }
 
-                               log_info!(
-                                       self.logger, "Received peer Init message: data_loss_protect: {}, initial_routing_sync: {}, upfront_shutdown_script: {}, gossip_queries: {}, static_remote_key: {}, unknown flags (local and global): {}",
-                                       if msg.features.supports_data_loss_protect() { "supported" } else { "not supported"},
-                                       if msg.features.initial_routing_sync() { "requested" } else { "not requested" },
-                                       if msg.features.supports_upfront_shutdown_script() { "supported" } else { "not supported"},
-                                       if msg.features.supports_gossip_queries() { "supported" } else { "not supported" },
-                                       if msg.features.supports_static_remote_key() { "supported" } else { "not supported"},
-                                       if msg.features.supports_unknown_bits() { "present" } else { "none" }
-                               );
+                               log_info!(self.logger, "Received peer Init message: {}", msg.features);
 
                                if msg.features.initial_routing_sync() {
                                        peer.sync_status = InitSyncTracker::ChannelsSyncing(0);
@@ -1377,9 +1372,12 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, L: Deref> PeerManager<D
                }
        }
 
-       /// This function should be called roughly once every 30 seconds.
-       /// It will send pings to each peer and disconnect those which did not respond to the last
-       /// round of pings.
+       /// 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.
        ///
        /// May call [`send_data`] on all [`SocketDescriptor`]s. Thus, be very careful with reentrancy
        /// issues!
@@ -1447,7 +1445,7 @@ mod tests {
        use bitcoin::secp256k1::key::{SecretKey, PublicKey};
 
        use prelude::*;
-       use std::sync::{Arc, Mutex};
+       use sync::{Arc, Mutex};
        use core::sync::atomic::Ordering;
 
        #[derive(Clone)]