Class: RoutingTable

RoutingTable

Represents a kademlia routing table

new RoutingTable(identity)

Constructs a routing table
Parameters:
Name Type Description
identity buffer Reference point for calculating distances
Source:

Members


length

Returns the total buckets in the routing table
Properties:
Name Type Description
length number
Source:

size

Returns the total contacts in the routing table
Properties:
Name Type Description
size number
Source:

Methods


addContactByNodeId(nodeId, contact)

Adds the contact to the routing table in the proper bucket position, returning the [bucketIndex, bucket, contactIndex, contact]; if the returned contactIndex is -1, it indicates the bucket is full and the contact was not added; kademlia implementations should PING the contact at bucket.head to determine if it should be dropped before calling this method again
Parameters:
Name Type Description
nodeId string | buffer Node identity to add
contact object contact information for peer
Source:
Returns:
Type
array

getClosestBucket()

Returns the [index, bucket] of the occupied bucket with the lowest index
Source:
Returns:
Type
Bucket

getClosestContactsToKey(key [, n] [, exclusive])

Returns a array of N contacts closest to the supplied key
Parameters:
Name Type Argument Default Description
key string | buffer Key to get buckets for
n number <optional>
20 Number of results to return
exclusive boolean <optional>
false Exclude exact matches
Source:
Returns:
Type
map

getContactByNodeId(nodeId)

Returns the contact object associated with the given node id
Parameters:
Name Type Description
nodeId string | buffer Node identity of the contact
Source:
Returns:
Type
Bucket~contact

indexOf(nodeId)

Returns the bucket index of the given node id
Parameters:
Name Type Description
nodeId string | buffer Node identity to get index for
Source:
Returns:
Type
number

removeContactByNodeId(nodeId)

Removes the contact from the routing table given a node id
Parameters:
Name Type Description
nodeId string | buffer Node identity to remove
Source:
Returns:
Type
boolean