synchronized Optional<DiscoveryPeer> add(final DiscoveryPeer peer)
      throws IllegalArgumentException {
    assert tailIndex >= -1 && tailIndex < bucketSize;

    // Avoid duplicating the peer if it already exists in the bucket.
    for (int i = 0; i <= tailIndex; i++) {
      if (peer.getId().equals(kBucket[i].getId())) {
        throw new IllegalArgumentException(
            String.format("Tried to add duplicate peer to k-bucket: %s", peer.getId()));
      }
    }
    if (tailIndex == bucketSize - 1) {
      return Optional.of(kBucket[tailIndex]);
    }
    arraycopy(kBucket, 0, kBucket, 1, ++tailIndex);
    kBucket[0] = peer;
    return Optional.empty();
  }
Appends the specified element to the head of the bucket array if capacity hasn't yet been
reached. Shifts the element currently at that position (if any) and any subsequent elements to
the right (adds one to their indices). If the bucket is empty, the last argument (length to
copy) will be 0. This method will not "touch" the peer, i.e. relocate it to the head.

<p>In the case that the bucket is at maximum capacity the peer at the tail of the list,
necessarily the peer that has been incomunicative for the longest time is returned as a
potential eviction candidate.

@param peer element to be appended to this list
@return an empty optional or alternatively the least recently contacted peer (tail of array)
@throws IllegalArgumentException The peer already existed in the bucket.
ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/Bucket.java