Function bucketIndex

  • Calculate the bucket index that the target node should be located in A node's k-buckets are organised such that for the ith k-bucket where 0 <= i < nodeIdBits, the contacts in this ith bucket are known to adhere to the following inequality: 2^i <= distance (from current node) < 2^(i+1) This means lower buckets will have less nodes then the upper buckets. The highest bucket will contain half of all possible nodes. The lowest bucket will only contain 1 node.

    NOTE: because XOR is a commutative operation (i.e. a XOR b = b XOR a), the order of the passed parameters is actually irrelevant. These variables are purely named for communicating function purpose.

    NOTE: Kademlia literature generally talks about buckets with 1-based indexing and that the buckets are ordered from largest to smallest. This means the first 1th-bucket is far & large bucket, and the last 255th-bucket is the close bucket. This is reversed in our NodeBucketIndex encoding. This is so that lexicographic sort orders our buckets from closest bucket to farthest bucket.

    To convert from NodeBucketIndex to nth-bucket in Kademlia literature:

    NodeBucketIndex Nth-Bucket
    255 1
    254 2
    ... ...
    1 254
    0 256

    Parameters

    Returns NodeBucketIndex

Generated using TypeDoc