Prevent disconnect from within handler (and style cleanup)

This commit is contained in:
Vurich 2017-06-30 12:10:12 +02:00
parent 5eba9078fc
commit 17de29e69a
3 changed files with 14 additions and 19 deletions

View File

@ -821,12 +821,15 @@ impl LightProtocol {
}));
let any_kept = self.handlers.iter().map(
|handler|
handler.on_connect(&Ctx {
|handler| handler.on_connect(
&Ctx {
peer: *peer,
io: io,
proto: self,
}, &status, &capabilities)
},
&status,
&capabilities
)
).fold(PeerStatus::Kept, PeerStatus::bitor);
if any_kept == PeerStatus::Unkept {

View File

@ -30,15 +30,8 @@ use network::PeerId;
use util::{RwLock, Mutex};
use net::{
self,
Handler,
PeerStatus,
Status,
Capabilities,
Announcement,
EventContext,
BasicContext,
ReqId,
self, Handler, PeerStatus, Status, Capabilities,
Announcement, EventContext, BasicContext, ReqId,
};
use cache::Cache;
use request::{self as basic_request, Request as NetworkRequest};

View File

@ -236,6 +236,8 @@ impl<L: AsLightClient + Send + Sync> Handler for LightSync<L> {
status: &Status,
capabilities: &Capabilities
) -> PeerStatus {
use std::cmp;
if capabilities.serve_headers {
let chain_info = ChainInfo {
head_td: status.head_td,
@ -245,7 +247,7 @@ impl<L: AsLightClient + Send + Sync> Handler for LightSync<L> {
{
let mut best = self.best_seen.lock();
*best = ::std::cmp::max(best.clone(), Some(chain_info.clone()));
*best = cmp::max(best.clone(), Some(chain_info.clone()));
}
self.peers.write().insert(ctx.peer(), Mutex::new(Peer::new(chain_info)));
@ -253,9 +255,6 @@ impl<L: AsLightClient + Send + Sync> Handler for LightSync<L> {
PeerStatus::Kept
} else {
trace!(target: "sync", "Disconnecting irrelevant peer: {}", ctx.peer());
ctx.disconnect_peer(ctx.peer());
PeerStatus::Unkept
}
}