public AddResult tryAdd(final DiscoveryPeer peer) {
    if (isIpAddressInvalid(peer.getEndpoint())) {
      return AddResult.invalid();
    }
    final Bytes id = peer.getId();
    final int distance = distanceFrom(peer);

    // Safeguard against adding ourselves to the peer table.
    if (distance == 0) {
      return AddResult.self();
    }

    final Bucket bucket = table[distance];
    // We add the peer, and two things can happen: (1) either we get an empty optional (peer was
    // added successfully,
    // or it was already there), or (2) we get a filled optional, in which case the bucket is full
    // and an eviction
    // candidate is proposed. The Bucket#add method will raise an exception if the peer already
    // existed.
    final Optional<DiscoveryPeer> res;
    try {
      res = bucket.add(peer);
    } catch (final IllegalArgumentException ex) {
      return AddResult.existed();
    }

    if (!res.isPresent()) {
      idBloom.put(id);
      distanceCache.put(id, distance);
      return AddResult.added();
    }

    return res.map(AddResult::bucketFull).get();
  }
Attempts to add the provided peer to the peer table, and returns an {@link AddResult}
signalling one of three outcomes.

<h3>Possible outcomes:</h3>

<ul>
  <li>the operation succeeded and the peer was added to the corresponding k-bucket.
  <li>the operation failed because the k-bucket was full, in which case a candidate is proposed
      for eviction.
  <li>the operation failed because the peer already existed.
  <li>the operation failed because the IP address is invalid.
</ul>

@param peer The peer to add.
@return An object indicating the outcome of the operation.
@see AddOutcome
ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/discovery/internal/PeerTable.java