use routing::network_graph::NetGraphMsgHandler;
use prelude::*;
+use io;
use alloc::collections::LinkedList;
use alloc::fmt::Debug;
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;
formatter.write_str("Peer Sent Invalid Data")
}
}
+
+#[cfg(feature = "std")]
impl error::Error for PeerHandleError {
fn description(&self) -> &str {
"Peer Sent Invalid Data"
match self.do_read_event(peer_descriptor, data) {
Ok(res) => Ok(res),
Err(e) => {
+ log_trace!(self.logger, "Peer sent invalid data or we decided to disconnect due to a protocol error");
self.disconnect_event_internal(peer_descriptor, e.no_connection_possible);
Err(e)
}
},
}
}
- };
+ }
}
}
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,
Some(peer) => {
match peer.their_node_id {
Some(node_id) => {
+ log_trace!(self.logger,
+ "Handling disconnection of peer {}, with {}future connection to the peer possible.",
+ log_pubkey!(node_id), if no_connection_possible { "no " } else { "" });
peers.node_id_to_descriptor.remove(&node_id);
self.message_handler.chan_handler.peer_disconnected(&node_id, no_connection_possible);
},
}
}
- /// 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!