Bucket

Represents a column of the routing table holding up to K contacts

Constructor

new Bucket()

Members

Properties
NameTypeDescription
headobject

The contact at the bucket head

length

Properties
NameTypeDescription
lengthnumber

The number of contacts in the bucket

tail

Properties
NameTypeDescription
tailobject

The contact at the bucket tail

Methods

getClosestToKey(key, countopt, exclusiveopt) → {array}

Returns an array of contacts in the bucket that are closest to the given key

Parameters:
NameTypeAttributesDefaultDescription
keystring | buffer

Reference key for finding other contacts

countnumber<optional>
constants.K

Max results to return

exclusiveboolean<optional>
false

Exclude result matching the key exactly

Returns:
Type: 
array

indexOf(key) → {number}

Returns the index of the given node id

Parameters:
NameTypeDescription
keystring

Node identity key for getting index

Returns:
Type: 
number

set(nodeId, contact) → {number}

Sets the contact to the node ID in the bucket if it is not full; if the bucket already contains the contact, move it to the tail - otherwise we place it at the head

Parameters:
NameTypeDescription
nodeIdstring

The identity key for the contact

contactobject

The address information for the contact

Returns:

index

Type: 
number

Type Definitions

contact

Type:
  • array
Properties
NameTypeDescription
0string

Node identity key

1object

Contact information (varies by plugins)