class RlpxAgent {

  public void connect(final Stream<? extends Peer> peerStream) {
    if (!localNode.isReady()) {
      return;
    }
    final int availablePeerSlots = Math.max(0, maxConnections - getConnectionCount());
    peerStream
        .filter(peer -> !connectionsById.containsKey(peer.getId()))
        .filter(peer -> peer.getEnodeURL().isListening())
        .filter(peerPermissions::allowNewOutboundConnectionTo)
        .limit(availablePeerSlots)
        .forEach(this::connect);
  }

  private  RlpxAgent(
      final LocalNode localNode,
      final PeerConnectionEvents connectionEvents,
      final ConnectionInitializer connectionInitializer,
      final PeerRlpxPermissions peerPermissions,
      final PeerPrivileges peerPrivileges,
      final int maxConnections,
      final int maxRemotelyInitiatedConnections,
      final MetricsSystem metricsSystem);

}