private int compareDuplicateConnections(final PeerConnection a, final PeerConnection b) {

    if (a.isDisconnected() != b.isDisconnected()) {
      // One connection has failed - prioritize the one that hasn't failed
      return a.isDisconnected() ? 1 : -1;
    }

    final Bytes peerId = a.getPeer().getId();
    // peerId is the id of the other node
    if (a.inboundInitiated() != b.inboundInitiated()) {
      // If we have connections initiated in different directions, keep the connection initiated
      // by the node with the lower id
      if (localNodeId.compareTo(peerId) < 0) {
        return a.inboundInitiated() ? 1 : -1;
      } else {
        return a.inboundInitiated() ? -1 : 1;
      }
    }
    // Otherwise, keep older connection
    LOG.atTrace()
        .setMessage("comparing timestamps {} with {}")
        .addArgument(a.getInitiatedAt())
        .addArgument(b.getInitiatedAt())
        .log();
    return a.getInitiatedAt() < b.getInitiatedAt() ? -1 : 1;
  }
Compares two connections to the same peer to determine which connection should be kept

@param a The first connection
@param b The second connection
@return A negative value if {@code a} should be kept, a positive value is {@code b} should be
    kept
ethereum/eth/src/main/java/org/hyperledger/besu/ethereum/eth/manager/EthPeer.java