Simplified Disconnect struct

This commit is contained in:
arkpar 2016-02-02 21:10:16 +01:00
parent 6e717c017f
commit da52fee2b3

View File

@ -110,10 +110,7 @@ pub enum NetworkIoMessage<Message> where Message: Send + Sync + Clone {
delay: u64, delay: u64,
}, },
/// Disconnect a peer /// Disconnect a peer
Disconnect { Disconnect(PeerId),
/// Peer Id
peer: PeerId,
},
/// User message /// User message
User(Message), User(Message),
} }
@ -194,9 +191,7 @@ impl<'s, Message> NetworkContext<'s, Message> where Message: Send + Sync + Clone
/// Disconnect peer. Reconnect can be attempted later. /// Disconnect peer. Reconnect can be attempted later.
pub fn disconnect_peer(&self, peer: PeerId) { pub fn disconnect_peer(&self, peer: PeerId) {
self.io.message(NetworkIoMessage::Disconnect { self.io.message(NetworkIoMessage::Disconnect(peer));
peer: peer,
});
} }
/// Register a new IO timer. 'IoHandler::timeout' will be called with the token. /// Register a new IO timer. 'IoHandler::timeout' will be called with the token.
@ -714,9 +709,7 @@ impl<Message> IoHandler<NetworkIoMessage<Message>> for Host<Message> where Messa
self.timers.write().unwrap().insert(handler_token, ProtocolTimer { protocol: protocol, token: *token }); self.timers.write().unwrap().insert(handler_token, ProtocolTimer { protocol: protocol, token: *token });
io.register_timer(handler_token, *delay).expect("Error registering timer"); io.register_timer(handler_token, *delay).expect("Error registering timer");
}, },
NetworkIoMessage::Disconnect { NetworkIoMessage::Disconnect(ref peer) => {
ref peer,
} => {
if let Some(connection) = self.connections.read().unwrap().get(*peer).cloned() { if let Some(connection) = self.connections.read().unwrap().get(*peer).cloned() {
match *connection.lock().unwrap().deref_mut() { match *connection.lock().unwrap().deref_mut() {
ConnectionEntry::Handshake(_) => {}, ConnectionEntry::Handshake(_) => {},