diff --git a/ethcore/light/src/net/mod.rs b/ethcore/light/src/net/mod.rs index ba6444184b4..4230d6559d0 100644 --- a/ethcore/light/src/net/mod.rs +++ b/ethcore/light/src/net/mod.rs @@ -114,9 +114,9 @@ mod packet { mod timeout { use std::time::Duration; - pub const HANDSHAKE: Duration = Duration::from_millis(2500); - pub const ACKNOWLEDGE_UPDATE: Duration = Duration::from_millis(5000); - pub const BASE: u64 = 1500; // base timeout for packet. + pub const HANDSHAKE: Duration = Duration::from_millis(4_000); + pub const ACKNOWLEDGE_UPDATE: Duration = Duration::from_millis(5_000); + pub const BASE: u64 = 2500; // base timeout for packet. // timeouts per request within packet. pub const HEADERS: u64 = 250; // per header? diff --git a/util/network-devp2p/src/host.rs b/util/network-devp2p/src/host.rs index 0a3668971df..2df8fdcbf39 100644 --- a/util/network-devp2p/src/host.rs +++ b/util/network-devp2p/src/host.rs @@ -160,6 +160,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> { } fn disconnect_peer(&self, peer: PeerId) { + trace!(target: "network", "Peer disconnect requested: {}", peer); self.io.message(NetworkIoMessage::Disconnect(peer)) .unwrap_or_else(|e| warn!("Error sending network IO message: {:?}", e)); } @@ -687,7 +688,7 @@ 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); @@ -720,11 +721,24 @@ impl Host { // Outgoing connections are allowed as long as their count is <= min_peers // Incoming connections are allowed to take all of the max_peers reserve, or at most half of the slots. let max_ingress = max(max_peers - min_peers, min_peers / 2); - if reserved_only || - (s.info.originated && egress_count > min_peers) || - (!s.info.originated && ingress_count > max_ingress) { - // only proceed if the connecting peer is reserved. - if !self.reserved_nodes.read().contains(&id) { + if reserved_only + || (s.info.originated && egress_count > min_peers) + || (!s.info.originated && ingress_count > max_ingress) + { + // We didn't start the connection, but the node is known to us + // So eventually we will attempt to connect to it as well. + let is_incoming_but_known = !s.info.originated && self.nodes.read().contains(&id); + + if is_incoming_but_known { + warn!(target: "network", "Allowing incoming connection from a known node."); + } + // only proceed if the connecting peer is reserved or is known + if !is_incoming_but_known && !self.reserved_nodes.read().contains(&id) { + trace!( + target: "network", + "Rejected {} session: TooManyPeers", + if s.info.originated { "outbound" } else { "inbound" } + ); s.disconnect(io, DisconnectReason::TooManyPeers); kill = true; break;