Peer sync timeouts
This commit is contained in:
@@ -5,17 +5,17 @@ use rlp::*;
|
||||
pub enum DisconnectReason
|
||||
{
|
||||
DisconnectRequested,
|
||||
//TCPError,
|
||||
//BadProtocol,
|
||||
_TCPError,
|
||||
_BadProtocol,
|
||||
UselessPeer,
|
||||
//TooManyPeers,
|
||||
//DuplicatePeer,
|
||||
//IncompatibleProtocol,
|
||||
//NullIdentity,
|
||||
//ClientQuit,
|
||||
//UnexpectedIdentity,
|
||||
//LocalIdentity,
|
||||
//PingTimeout,
|
||||
_TooManyPeers,
|
||||
_DuplicatePeer,
|
||||
_IncompatibleProtocol,
|
||||
_NullIdentity,
|
||||
_ClientQuit,
|
||||
_UnexpectedIdentity,
|
||||
_LocalIdentity,
|
||||
_PingTimeout,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -18,6 +18,7 @@ use io::*;
|
||||
use network::NetworkProtocolHandler;
|
||||
use network::node::*;
|
||||
use network::stats::NetworkStats;
|
||||
use network::error::DisconnectReason;
|
||||
|
||||
type Slab<T> = ::slab::Slab<T, usize>;
|
||||
|
||||
@@ -107,6 +108,11 @@ pub enum NetworkIoMessage<Message> where Message: Send + Sync + Clone {
|
||||
/// Timer delay in milliseconds.
|
||||
delay: u64,
|
||||
},
|
||||
/// Disconnect a peer
|
||||
Disconnect {
|
||||
/// Peer Id
|
||||
peer: PeerId,
|
||||
},
|
||||
/// User message
|
||||
User(Message),
|
||||
}
|
||||
@@ -180,8 +186,16 @@ impl<'s, Message> NetworkContext<'s, Message> where Message: Send + Sync + Clone
|
||||
}
|
||||
|
||||
/// Disable current protocol capability for given peer. If no capabilities left peer gets disconnected.
|
||||
pub fn disable_peer(&self, _peer: PeerId) {
|
||||
pub fn disable_peer(&self, peer: PeerId) {
|
||||
//TODO: remove capability, disconnect if no capabilities left
|
||||
self.disconnect_peer(peer);
|
||||
}
|
||||
|
||||
/// Disconnect peer. Reconnect can be attempted later.
|
||||
pub fn disconnect_peer(&self, peer: PeerId) {
|
||||
self.io.message(NetworkIoMessage::Disconnect {
|
||||
peer: peer,
|
||||
});
|
||||
}
|
||||
|
||||
/// Register a new IO timer. 'IoHandler::timeout' will be called with the token.
|
||||
@@ -683,6 +697,17 @@ impl<Message> IoHandler<NetworkIoMessage<Message>> for Host<Message> where Messa
|
||||
self.timers.write().unwrap().insert(handler_token, ProtocolTimer { protocol: protocol, token: *token });
|
||||
io.register_timer(handler_token, *delay).expect("Error registering timer");
|
||||
},
|
||||
NetworkIoMessage::Disconnect {
|
||||
ref peer,
|
||||
} => {
|
||||
if let Some(connection) = self.connections.read().unwrap().get(*peer).cloned() {
|
||||
match *connection.lock().unwrap().deref_mut() {
|
||||
ConnectionEntry::Handshake(_) => {},
|
||||
ConnectionEntry::Session(ref mut s) => { s.disconnect(DisconnectReason::DisconnectRequested); }
|
||||
}
|
||||
}
|
||||
self.kill_connection(*peer, io);
|
||||
},
|
||||
NetworkIoMessage::User(ref message) => {
|
||||
for (p, h) in self.handlers.read().unwrap().iter() {
|
||||
h.message(&NetworkContext::new(io, p, None, self.connections.clone()), &message);
|
||||
|
||||
@@ -21,7 +21,7 @@ impl<Message> NetworkService<Message> where Message: Send + Sync + Clone + 'stat
|
||||
let host = Arc::new(Host::new(config));
|
||||
let stats = host.stats().clone();
|
||||
let host_info = host.client_version();
|
||||
info!("NetworkService::start(): id={:?}", host.client_id());
|
||||
info!("Host ID={:?}", host.client_id());
|
||||
try!(io_service.register_handler(host));
|
||||
Ok(NetworkService {
|
||||
io_service: io_service,
|
||||
|
||||
@@ -263,7 +263,8 @@ impl Session {
|
||||
self.send(try!(Session::prepare(PACKET_PONG)))
|
||||
}
|
||||
|
||||
fn disconnect(&mut self, reason: DisconnectReason) -> NetworkError {
|
||||
/// Disconnect this session
|
||||
pub fn disconnect(&mut self, reason: DisconnectReason) -> NetworkError {
|
||||
let mut rlp = RlpStream::new();
|
||||
rlp.append(&(PACKET_DISCONNECT as u32));
|
||||
rlp.begin_list(1);
|
||||
|
||||
Reference in New Issue
Block a user