Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Node table sorting according to last contact data #8541

Merged
merged 6 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions util/network-devp2p/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,13 @@ pub struct NetworkContext<'s> {

impl<'s> NetworkContext<'s> {
/// Create a new network IO access point. Takes references to all the data that can be updated within the IO handler.
fn new(io: &'s IoContext<NetworkIoMessage>,
fn new(
io: &'s IoContext<NetworkIoMessage>,
protocol: ProtocolId,
session: Option<SharedSession>, sessions: Arc<RwLock<Slab<SharedSession>>>,
reserved_peers: &'s HashSet<NodeId>) -> NetworkContext<'s> {
session: Option<SharedSession>,
sessions: Arc<RwLock<Slab<SharedSession>>>,
reserved_peers: &'s HashSet<NodeId>,
) -> NetworkContext<'s> {
let id = session.as_ref().map(|s| s.lock().token());
NetworkContext {
io: io,
Expand Down Expand Up @@ -585,10 +588,8 @@ impl Host {
let address = {
let mut nodes = self.nodes.write();
if let Some(node) = nodes.get_mut(id) {
node.attempts += 1;
node.endpoint.address
}
else {
} else {
debug!(target: "network", "Connection to expired node aborted");
return;
}
Expand All @@ -600,6 +601,7 @@ impl Host {
},
Err(e) => {
debug!(target: "network", "{}: Can't connect to address {:?}: {:?}", id, address, e);
self.nodes.write().note_failure(&id);
return;
}
}
Expand Down Expand Up @@ -685,10 +687,12 @@ impl Host {
Err(e) => {
let s = session.lock();
trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e);
if let ErrorKind::Disconnect(DisconnectReason::IncompatibleProtocol) = *e.kind() {
if let ErrorKind::Disconnect(DisconnectReason::UselessPeer) = *e.kind() {
if let Some(id) = s.id() {
if !self.reserved_nodes.read().contains(id) {
self.nodes.write().mark_as_useless(id);
let mut nodes = self.nodes.write();
nodes.note_failure(&id);
nodes.mark_as_useless(id);
}
}
}
Expand Down Expand Up @@ -754,6 +758,10 @@ impl Host {
}
}
}

// Note connection success
self.nodes.write().note_success(&id);

for (p, _) in self.handlers.read().iter() {
if s.have_capability(*p) {
ready_data.push(*p);
Expand Down Expand Up @@ -1024,7 +1032,9 @@ impl IoHandler<NetworkIoMessage> for Host {
if let Some(session) = session {
session.lock().disconnect(io, DisconnectReason::DisconnectRequested);
if let Some(id) = session.lock().id() {
self.nodes.write().mark_as_useless(id)
let mut nodes = self.nodes.write();
nodes.note_failure(&id);
nodes.mark_as_useless(id);
}
}
trace!(target: "network", "Disabling peer {}", peer);
Expand Down
Loading