|
|
@ -305,6 +305,9 @@ public class RlpxAgent { |
|
|
|
connection -> { |
|
|
|
connection -> { |
|
|
|
if (!peerPermissions.allowOngoingConnection( |
|
|
|
if (!peerPermissions.allowOngoingConnection( |
|
|
|
connection.getPeer(), connection.initiatedRemotely())) { |
|
|
|
connection.getPeer(), connection.initiatedRemotely())) { |
|
|
|
|
|
|
|
LOG.debug( |
|
|
|
|
|
|
|
"Disconnecting from peer that is not permitted to maintain ongoing connection: {}", |
|
|
|
|
|
|
|
connection); |
|
|
|
connection.disconnect(DisconnectReason.REQUESTED); |
|
|
|
connection.disconnect(DisconnectReason.REQUESTED); |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
@ -332,21 +335,28 @@ public class RlpxAgent { |
|
|
|
final Peer peer = peerConnection.getPeer(); |
|
|
|
final Peer peer = peerConnection.getPeer(); |
|
|
|
// Deny connection if our local node isn't ready
|
|
|
|
// Deny connection if our local node isn't ready
|
|
|
|
if (!localNode.isReady()) { |
|
|
|
if (!localNode.isReady()) { |
|
|
|
|
|
|
|
LOG.debug("Node is not ready. Disconnect incoming connection: {}", peerConnection); |
|
|
|
peerConnection.disconnect(DisconnectReason.UNKNOWN); |
|
|
|
peerConnection.disconnect(DisconnectReason.UNKNOWN); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Disconnect if too many peers
|
|
|
|
// Disconnect if too many peers
|
|
|
|
if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= maxConnections) { |
|
|
|
if (!peerPrivileges.canExceedConnectionLimits(peer) && getConnectionCount() >= maxConnections) { |
|
|
|
|
|
|
|
LOG.debug("Too many peers. Disconnect incoming connection: {}", peerConnection); |
|
|
|
peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); |
|
|
|
peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Disconnect if too many remotely-initiated connections
|
|
|
|
// Disconnect if too many remotely-initiated connections
|
|
|
|
if (!peerPrivileges.canExceedConnectionLimits(peer) && remoteConnectionLimitReached()) { |
|
|
|
if (!peerPrivileges.canExceedConnectionLimits(peer) && remoteConnectionLimitReached()) { |
|
|
|
|
|
|
|
LOG.debug( |
|
|
|
|
|
|
|
"Too many remotely-initiated connections. Disconnect incoming connection: {}", |
|
|
|
|
|
|
|
peerConnection); |
|
|
|
peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); |
|
|
|
peerConnection.disconnect(DisconnectReason.TOO_MANY_PEERS); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Disconnect if not permitted
|
|
|
|
// Disconnect if not permitted
|
|
|
|
if (!peerPermissions.allowNewInboundConnectionFrom(peer)) { |
|
|
|
if (!peerPermissions.allowNewInboundConnectionFrom(peer)) { |
|
|
|
|
|
|
|
LOG.debug( |
|
|
|
|
|
|
|
"Node is not permitted to connect. Disconnect incoming connection: {}", peerConnection); |
|
|
|
peerConnection.disconnect(DisconnectReason.UNKNOWN); |
|
|
|
peerConnection.disconnect(DisconnectReason.UNKNOWN); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
@ -426,7 +436,13 @@ public class RlpxAgent { |
|
|
|
.filter(RlpxConnection::initiatedRemotely) |
|
|
|
.filter(RlpxConnection::initiatedRemotely) |
|
|
|
.filter(conn -> !peerPrivileges.canExceedConnectionLimits(conn.getPeer())) |
|
|
|
.filter(conn -> !peerPrivileges.canExceedConnectionLimits(conn.getPeer())) |
|
|
|
.skip(maxRemotelyInitiatedConnections) |
|
|
|
.skip(maxRemotelyInitiatedConnections) |
|
|
|
.forEach(c -> c.disconnect(DisconnectReason.TOO_MANY_PEERS)); |
|
|
|
.forEach( |
|
|
|
|
|
|
|
conn -> { |
|
|
|
|
|
|
|
LOG.debug( |
|
|
|
|
|
|
|
"Too many remotely initiated connections. Disconnect low-priority connection: {}", |
|
|
|
|
|
|
|
conn); |
|
|
|
|
|
|
|
conn.disconnect(DisconnectReason.TOO_MANY_PEERS); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void enforceConnectionLimits() { |
|
|
|
private void enforceConnectionLimits() { |
|
|
@ -438,7 +454,11 @@ public class RlpxAgent { |
|
|
|
getActivePrioritizedConnections() |
|
|
|
getActivePrioritizedConnections() |
|
|
|
.skip(maxConnections) |
|
|
|
.skip(maxConnections) |
|
|
|
.filter(c -> !peerPrivileges.canExceedConnectionLimits(c.getPeer())) |
|
|
|
.filter(c -> !peerPrivileges.canExceedConnectionLimits(c.getPeer())) |
|
|
|
.forEach(c -> c.disconnect(DisconnectReason.TOO_MANY_PEERS)); |
|
|
|
.forEach( |
|
|
|
|
|
|
|
conn -> { |
|
|
|
|
|
|
|
LOG.debug("Too many connections. Disconnect low-priority connection: {}", conn); |
|
|
|
|
|
|
|
conn.disconnect(DisconnectReason.TOO_MANY_PEERS); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Stream<RlpxConnection> getActivePrioritizedConnections() { |
|
|
|
private Stream<RlpxConnection> getActivePrioritizedConnections() { |
|
|
|