Skip to content

Latest commit

 

History

History
108 lines (81 loc) · 2.42 KB

bucket.md

File metadata and controls

108 lines (81 loc) · 2.42 KB

Bucket

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.

Contents

Constructor

new Bucket()


Creates a new Bucket instance.

const plexus = require("plexus");

//  Bucket creation
const bucket = new plexus.Bucket();

Getters

bucket.size


Returns the amount of known contacts.

//  Get the number of contacts
const size = bucket.size;

Methods

bucket.get_contacts()


Returns the list of known contacts.

//  Get the list of contacts
const contacts = bucket.get_contacts();

bucket.get_contact(index)

  • 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);

bucket.get_index(contact)

  • 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);

bucket.add_contact(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);

bucket.remove_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);

bucket.has_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);