public List<Node> nearestNodes(byte[] nodeIdOrInfoHash) {
        List<Node> nodes = new LinkedList<>();
        if (buckets.isEmpty()) {
            return nodes;
        }
        int bucketIndex = bucketIndex(nodeIdOrInfoHash);
        nodes.addAll(buckets.get(bucketIndex).nodes);
        int minBucketIndex = bucketIndex - 1;
        int maxBucketIndex = bucketIndex + 1;
        while ((nodes.size() < Bucket.K) && (minBucketIndex >= 0 || maxBucketIndex < buckets.size())) {
            if (minBucketIndex >= 0) {
                nodes.addAll(buckets.get(minBucketIndex).nodes);
            }
            if (maxBucketIndex < buckets.size()) {
                nodes.addAll(buckets.get(maxBucketIndex).nodes);
            }
            minBucketIndex--;
            maxBucketIndex++;
        }
        BigInteger nodeIdOrInfoHashInt = Util.nodeIdToInt(nodeIdOrInfoHash);
        nodes.sort((Node node1, Node node2) -> nodeIdOrInfoHashInt.xor(Util.nodeIdToInt(node1.id)).subtract(nodeIdOrInfoHashInt.xor(Util.nodeIdToInt(node2.id))).signum());
        return nodes.subList(0, Bucket.K > nodes.size() ? nodes.size() : Bucket.K);
    }