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

Commit 06285ea

Browse files
committed
Fix light timeouts and eclipse protection.
1 parent d629b1b commit 06285ea

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

ethcore/light/src/net/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ mod packet {
114114
mod timeout {
115115
use std::time::Duration;
116116

117-
pub const HANDSHAKE: Duration = Duration::from_millis(2500);
118-
pub const ACKNOWLEDGE_UPDATE: Duration = Duration::from_millis(5000);
119-
pub const BASE: u64 = 1500; // base timeout for packet.
117+
pub const HANDSHAKE: Duration = Duration::from_millis(4_000);
118+
pub const ACKNOWLEDGE_UPDATE: Duration = Duration::from_millis(5_000);
119+
pub const BASE: u64 = 2500; // base timeout for packet.
120120

121121
// timeouts per request within packet.
122122
pub const HEADERS: u64 = 250; // per header?

util/network-devp2p/src/host.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> {
160160
}
161161

162162
fn disconnect_peer(&self, peer: PeerId) {
163+
trace!(target: "network", "Peer disconnect requested: {}", peer);
163164
self.io.message(NetworkIoMessage::Disconnect(peer))
164165
.unwrap_or_else(|e| warn!("Error sending network IO message: {:?}", e));
165166
}
@@ -687,7 +688,7 @@ impl Host {
687688
Err(e) => {
688689
let s = session.lock();
689690
trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e);
690-
if let ErrorKind::Disconnect(DisconnectReason::IncompatibleProtocol) = *e.kind() {
691+
if let ErrorKind::Disconnect(DisconnectReason::UselessPeer) = *e.kind() {
691692
if let Some(id) = s.id() {
692693
if !self.reserved_nodes.read().contains(id) {
693694
self.nodes.write().mark_as_useless(id);
@@ -720,11 +721,24 @@ impl Host {
720721
// Outgoing connections are allowed as long as their count is <= min_peers
721722
// Incoming connections are allowed to take all of the max_peers reserve, or at most half of the slots.
722723
let max_ingress = max(max_peers - min_peers, min_peers / 2);
723-
if reserved_only ||
724-
(s.info.originated && egress_count > min_peers) ||
725-
(!s.info.originated && ingress_count > max_ingress) {
726-
// only proceed if the connecting peer is reserved.
727-
if !self.reserved_nodes.read().contains(&id) {
724+
if reserved_only
725+
|| (s.info.originated && egress_count > min_peers)
726+
|| (!s.info.originated && ingress_count > max_ingress)
727+
{
728+
// We didn't start the connection, but the node is known to us
729+
// So eventually we will attempt to connect to it as well.
730+
let is_incoming_but_known = !s.info.originated && self.nodes.read().contains(&id);
731+
732+
if is_incoming_but_known {
733+
warn!(target: "network", "Allowing incoming connection from a known node.");
734+
}
735+
// only proceed if the connecting peer is reserved or is known
736+
if !is_incoming_but_known && !self.reserved_nodes.read().contains(&id) {
737+
trace!(
738+
target: "network",
739+
"Rejected {} session: TooManyPeers",
740+
if s.info.originated { "outbound" } else { "inbound" }
741+
);
728742
s.disconnect(io, DisconnectReason::TooManyPeers);
729743
kill = true;
730744
break;

0 commit comments

Comments
 (0)