@@ -160,6 +160,7 @@ impl<'s> NetworkContextTrait for NetworkContext<'s> {
160
160
}
161
161
162
162
fn disconnect_peer ( & self , peer : PeerId ) {
163
+ trace ! ( target: "network" , "Peer disconnect requested: {}" , peer) ;
163
164
self . io . message ( NetworkIoMessage :: Disconnect ( peer) )
164
165
. unwrap_or_else ( |e| warn ! ( "Error sending network IO message: {:?}" , e) ) ;
165
166
}
@@ -687,7 +688,7 @@ impl Host {
687
688
Err ( e) => {
688
689
let s = session. lock ( ) ;
689
690
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 ( ) {
691
692
if let Some ( id) = s. id ( ) {
692
693
if !self . reserved_nodes . read ( ) . contains ( id) {
693
694
self . nodes . write ( ) . mark_as_useless ( id) ;
@@ -720,11 +721,24 @@ impl Host {
720
721
// Outgoing connections are allowed as long as their count is <= min_peers
721
722
// Incoming connections are allowed to take all of the max_peers reserve, or at most half of the slots.
722
723
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
+ ) ;
728
742
s. disconnect ( io, DisconnectReason :: TooManyPeers ) ;
729
743
kill = true ;
730
744
break ;
0 commit comments