Buckets are used to store a finite amount of contact informations about other nodes. Multiple buckets are used in the router to speed up the lookup process.
- constructor
- getters
- methods
Creates a new Bucket instance.
const plexus = require("plexus");
// Bucket creation
const bucket = new plexus.Bucket();
Returns the amount of known contacts.
// Get the number of contacts
const size = bucket.size;
Returns the list of known contacts.
// Get the list of contacts
const contacts = bucket.get_contacts();
index
: Integer The index of the contact to look for.
Returns the contact stored at the specified index.
// Get the contact at the head of the bucket
const head = bucket.get_contact(0);
contact
: Contact The contact of which to get the index.
Gets the index of a contact.
const contact = new plexus.Contact({host: "127.0.0.1", port: 8080});
// Get the first contact
const index = bucket.get_index(contact);
contact
: Contact The contact to add to the bucket.
Adds a contact to the bucket.
const contact = new plexus.Contact({host: "127.0.0.1", port: 8080});
bucket.add_contact(contact);
contact
: Contact The contact to remove from the bucket.
Removes a contact from the bucket.
const contact = new plexus.Contact({host: "127.0.0.1", port: 8080});
bucket.remove_contact(contact);
contact
: Contact The contact to look for.
Checks if the contact is stored in the bucket.
const contact = new plexus.Contact({host: "127.0.0.1", port: 8080});
const exists = bucket.has_contact(contact);