Attempt to eliminate stale peers.
This commit is contained in:
+3
-3
@@ -268,18 +268,18 @@ impl Peers {
|
|||||||
registry.reregister(stream, *token, Interest::WRITABLE | Interest::READABLE).unwrap();
|
registry.reregister(stream, *token, Interest::WRITABLE | Interest::READABLE).unwrap();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if matches!(peer.get_state(), State::Message {..}) {
|
if !matches!(peer.get_state(), State::Connecting {..}) && (peer.get_state().is_timed_out() || !peer.active()) {
|
||||||
if !peer.active() {
|
|
||||||
stale_tokens.push((token.clone(), peer.get_addr()));
|
stale_tokens.push((token.clone(), peer.get_addr()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if matches!(peer.get_state(), State::Message {..}) {
|
||||||
let stream = peer.get_stream();
|
let stream = peer.get_stream();
|
||||||
registry.reregister(stream, *token, Interest::WRITABLE).unwrap();
|
registry.reregister(stream, *token, Interest::WRITABLE).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (token, addr) in &stale_tokens {
|
for (token, addr) in &stale_tokens {
|
||||||
info!("Closing stale peer from {}", addr);
|
info!("Closing stale (timed out) peer from {}", addr);
|
||||||
self.close_peer(registry, token);
|
self.close_peer(registry, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,17 @@ impl State {
|
|||||||
matches!(self, State::Idle { .. })
|
matches!(self, State::Idle { .. })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_timed_out(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
State::Error => true,
|
||||||
|
State::Banned => true,
|
||||||
|
State::Idle { from } => {
|
||||||
|
from.elapsed().as_secs() > 60
|
||||||
|
}
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_loop(&self) -> bool {
|
pub fn is_loop(&self) -> bool {
|
||||||
matches!(self, State::Loop { .. } | State::SendLoop { .. })
|
matches!(self, State::Loop { .. } | State::SendLoop { .. })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user