Prevent disconnect from within handler (and style cleanup)
This commit is contained in:
parent
5eba9078fc
commit
17de29e69a
@ -821,12 +821,15 @@ impl LightProtocol {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
let any_kept = self.handlers.iter().map(
|
let any_kept = self.handlers.iter().map(
|
||||||
|handler|
|
|handler| handler.on_connect(
|
||||||
handler.on_connect(&Ctx {
|
&Ctx {
|
||||||
peer: *peer,
|
peer: *peer,
|
||||||
io: io,
|
io: io,
|
||||||
proto: self,
|
proto: self,
|
||||||
}, &status, &capabilities)
|
},
|
||||||
|
&status,
|
||||||
|
&capabilities
|
||||||
|
)
|
||||||
).fold(PeerStatus::Kept, PeerStatus::bitor);
|
).fold(PeerStatus::Kept, PeerStatus::bitor);
|
||||||
|
|
||||||
if any_kept == PeerStatus::Unkept {
|
if any_kept == PeerStatus::Unkept {
|
||||||
|
@ -30,15 +30,8 @@ use network::PeerId;
|
|||||||
use util::{RwLock, Mutex};
|
use util::{RwLock, Mutex};
|
||||||
|
|
||||||
use net::{
|
use net::{
|
||||||
self,
|
self, Handler, PeerStatus, Status, Capabilities,
|
||||||
Handler,
|
Announcement, EventContext, BasicContext, ReqId,
|
||||||
PeerStatus,
|
|
||||||
Status,
|
|
||||||
Capabilities,
|
|
||||||
Announcement,
|
|
||||||
EventContext,
|
|
||||||
BasicContext,
|
|
||||||
ReqId,
|
|
||||||
};
|
};
|
||||||
use cache::Cache;
|
use cache::Cache;
|
||||||
use request::{self as basic_request, Request as NetworkRequest};
|
use request::{self as basic_request, Request as NetworkRequest};
|
||||||
|
@ -236,6 +236,8 @@ impl<L: AsLightClient + Send + Sync> Handler for LightSync<L> {
|
|||||||
status: &Status,
|
status: &Status,
|
||||||
capabilities: &Capabilities
|
capabilities: &Capabilities
|
||||||
) -> PeerStatus {
|
) -> PeerStatus {
|
||||||
|
use std::cmp;
|
||||||
|
|
||||||
if capabilities.serve_headers {
|
if capabilities.serve_headers {
|
||||||
let chain_info = ChainInfo {
|
let chain_info = ChainInfo {
|
||||||
head_td: status.head_td,
|
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();
|
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)));
|
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
|
PeerStatus::Kept
|
||||||
} else {
|
} else {
|
||||||
trace!(target: "sync", "Disconnecting irrelevant peer: {}", ctx.peer());
|
|
||||||
ctx.disconnect_peer(ctx.peer());
|
|
||||||
|
|
||||||
PeerStatus::Unkept
|
PeerStatus::Unkept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user