+9
-1
@@ -49,3 +49,6 @@ /* | ||
| self.bucket = []; | ||
| self.localNodeId = options.localNodeId || crypto.createHash('sha1').digest(); | ||
| self.localNodeId = options.localNodeId | ||
| || crypto.createHash('sha1') | ||
| .update('' + new Date().getTime() + process.hrtime()[1]) | ||
| .digest(); | ||
| if (!(self.localNodeId instanceof Buffer)) { | ||
@@ -128,2 +131,7 @@ self.localNodeId = new Buffer(self.localNodeId, 'base64'); | ||
| // contact: Object *required* contact object | ||
| // id: Buffer *require* node id | ||
| // n: Integer *required* maximum number of closest contacts to return | ||
| // bitIndex: Integer (Default: 0) | ||
| // Return: Array of maximum of `n` closest contacts to the `contact` | ||
| KBucket.prototype.closest = function closest (contact, n, bitIndex) { | ||
@@ -130,0 +138,0 @@ var self = this; |
+24
-24
| { | ||
| "name": "k-bucket", | ||
| "version": "0.2.0", | ||
| "description": "Kademlia DHT K-bucket implementation as a binary tree", | ||
| "scripts": { | ||
| "test": "node scripts/test.js" | ||
| }, | ||
| "main": "index.js", | ||
| "dependencies": { | ||
| "buffertools": "1.1.1" | ||
| }, | ||
| "devDependencies": { | ||
| "nodeunit": "0.8.1" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git@github.com:tristanls/node-k-bucket.git" | ||
| }, | ||
| "keywords": [ | ||
| "k-bucket", | ||
| "kademlia", | ||
| "dht" | ||
| ], | ||
| "author": "Tristan Slominski <tristan.slominski@gmail.com>", | ||
| "license": "MIT" | ||
| "name": "k-bucket", | ||
| "version": "0.2.1", | ||
| "description": "Kademlia DHT K-bucket implementation as a binary tree", | ||
| "scripts": { | ||
| "test": "node scripts/test.js" | ||
| }, | ||
| "main": "index.js", | ||
| "dependencies": { | ||
| "buffertools": "1.1.1" | ||
| }, | ||
| "devDependencies": { | ||
| "nodeunit": "0.8.1" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git@github.com:tristanls/node-k-bucket.git" | ||
| }, | ||
| "keywords": [ | ||
| "k-bucket", | ||
| "kademlia", | ||
| "dht" | ||
| ], | ||
| "author": "Tristan Slominski <tristan.slominski@gmail.com>", | ||
| "license": "MIT" | ||
| } |
+53
-39
@@ -47,7 +47,15 @@ # k-bucket | ||
| **Public API** | ||
| * [KBucket.distance(firstId, secondId)](#kbucketdistancefirstid-secondid) | ||
| * [new KBucket(options)](#new-kbucketoptions) | ||
| * [kBucket.add(contact, \[bitIndex\])](#kbucketaddcontact-bitindex) | ||
| * [kBucket.closest(contact, n, \[bitIndex\])](#kbucketclosestcontact-n-bitindex) | ||
| * [kBucket.remove(contact, \[bitIndex\])](#kbucketremovecontact-bitindex) | ||
| * [Event 'ping'](#event-ping) | ||
| #### KBucket.distance(firstId, secondId) | ||
| * `firstId`: _Buffer_ | ||
| * `secondId`: _Buffer_ | ||
| * Return: _Integer_ | ||
| * `firstId`: _Buffer_ Buffer containing first id. | ||
| * `secondId`: _Buffer_ Buffer containing second id. | ||
| * Return: _Integer_ The XOR distance between `firstId` and `secondId`. | ||
@@ -59,4 +67,4 @@ Finds the XOR distance between firstId and secondId. | ||
| * `options`: | ||
| * `localNodeId`: _String (base64)_ or _Buffer_ An optional String or a Buffer representing the local node id. If not provided, a local node id will be created via `crypto.createHash('sha1').digest()`. If a String is provided, it will be assumed to be base64 encoded and will be converted into a Buffer. | ||
| * `root`: _Object_ _(reserved for internal use)_ provides a reference to the root of the tree data structure as the k-bucket splits when new contacts are added | ||
| * `localNodeId`: _String (base64)_ or _Buffer_ An optional String or a Buffer representing the local node id. If not provided, a local node id will be created via `crypto.createHash('sha1').update('' + new Date().getTime() + process.hrtime()[1]).digest()`. If a String is provided, it will be assumed to be base64 encoded and will be converted into a Buffer. | ||
| * `root`: _Object_ _**CAUTION: reserved for internal use**_ Provides a reference to the root of the tree data structure as the k-bucket splits when new contacts are added. | ||
@@ -67,7 +75,7 @@ Creates a new KBucket. | ||
| * `contact`: _Object_ | ||
| * `id`: _Buffer_ contact node id | ||
| * Any satellite data can be part of the `contact` object, only `id` is used | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ | ||
| * Return: _Object_ | ||
| * `contact`: _Object_ The contact object to add. | ||
| * `id`: _Buffer_ Contact node id. | ||
| * Any satellite data that is part of the `contact` object will not be altered, only `id` is used. | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ _**CAUTION: reserved for internal use**_ The bit index to which bit to check in the `id` Buffer. | ||
| * Return: _Object_ The k-bucket itself. | ||
@@ -78,8 +86,8 @@ Adds a `contact` to the k-bucket. | ||
| * `contact`: _Object_ | ||
| * `id`: _Buffer_ contact node id | ||
| * Any satellite data can be part of the `contact` object, only `id` is used | ||
| * `n`: _Integer_ | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ | ||
| * Return: _Array_ | ||
| * `contact`: _Object_ The contact object to find closest contacts to. | ||
| * `id`: _Buffer_ Contact node id. | ||
| * Any satellite data that is part of the `contact` object will not be altered, only `id` is used. | ||
| * `n`: _Integer_ The maximum number of closest contacts to return. | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ _**CAUTION: reserved for internal use**_ The bit index to which bit to check in the `id` Buffer. | ||
| * Return: _Array_ Maximum of `n` closest contacts to the `contact`. | ||
@@ -90,7 +98,7 @@ Get the `n` closest contacts to the provided `contact`. "Closest" here means: closest according to the XOR metric of the `contact` node id. | ||
| * `id`: _Buffer_ | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ | ||
| * Return: _Integer_ | ||
| _**CAUTION: reserved for internal use**_ | ||
| _reserved for internal use_ | ||
| * `id`: _Buffer_ Id to compare `localNodeId` with. | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ The bit index to which bit to check in the `id` Buffer. | ||
| * Return: _Integer_ -1 if `id` at `bitIndex` is 0, 1 otherwise. | ||
@@ -101,14 +109,20 @@ Determines whether the `id` at the `bitIndex` is 0 or 1. If 0, returns -1, else 1. | ||
| * `contact`: _Object_ | ||
| * Return: _Integer_ | ||
| _**CAUTION: reserved for internal use**_ | ||
| * `contact`: _Object_ The contact object. | ||
| * `id`: _Buffer_ Contact node id. | ||
| * Any satellite data that is part of the `contact` object will not be altered, only `id` is used. | ||
| * Return: _Integer_ Index of `contact` if it exists, -1 otherwise. | ||
| Returns the index of the `contact` if it exists, returns -1 otherwise. | ||
| _NOTE: `kBucket.indexOf(contact)` does not compare `contact.vectorClock`_ | ||
| #### kBucket.remove(contact, [bitIndex]) | ||
| * `contact`: _Object_ | ||
| * `id`: _Buffer_ contact node id | ||
| * `contact`: _Object_ The contact object to remove. | ||
| * `id`: _Buffer_ contact node id. | ||
| * Any satellite data can be part of the `contact` object, only `id` is used | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ | ||
| * Return: _Object_ | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ _**CAUTION: reserved for internal use**_ The bit index to which bit to check in the `id` Buffer. | ||
| * Return: _Object_ The k-bucket itself. | ||
@@ -119,9 +133,9 @@ Removes the `contact`. | ||
| * `contact`: _Object_ | ||
| * `id`: _Buffer_ contact node id | ||
| * Any satellite data can be part of the `contact` object, only `id` is used | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ | ||
| * Return: _Object_ | ||
| _**CAUTION: reserved for internal use**_ | ||
| _reserved for internal use_ | ||
| * `contact`: _Object_ The contact object to add. | ||
| * `id`: _Buffer_ Contact node id. | ||
| * Any satellite data that is part of the `contact` object will not be altered, only `id` is used. | ||
| * `bitIndex`: _Integer_ _(Default: 0)_ The bit index to which bit to check in the `id` Buffer. | ||
| * Return: _Object_ The k-bucket itself. | ||
@@ -132,8 +146,8 @@ Splits the bucket, redistributes contacts to the new buckets, and marks the bucket that was split as an inner node of the binary tree of buckets by setting `self.bucket = undefined`. Also, marks the "far away" bucket as `dontSplit`. | ||
| * `contact`: _Object_ | ||
| * `id`: _Buffer_ contact node id | ||
| * Any satellite data can be part of the `contact` object, only `id` is used | ||
| * `index`: _Integer_ | ||
| _**CAUTION: reserved for internal use**_ | ||
| _reserved for internal use_ | ||
| * `contact`: _Object_ The contact object to update. | ||
| * `id`: _Buffer_ Contact node id | ||
| * Any satellite data that is part of the `contact` object will not be altered, only `id` is used. | ||
| * `index`: _Integer_ The index in the bucket where contact exists (index has already been computed in previous calculation). | ||
@@ -144,4 +158,4 @@ Updates the `contact` and compares the vector clocks if provided. If new `contact` vector clock is deprecated, `contact` is abandoned (not added). If new `contact` vector clock is the same, `contact` is marked as moste recently contacted (by being moved to the right/end of the bucket array). If new `contact` vector clock is more recent, the old `contact` is removed and the new contact is marked as most recently contacted. | ||
| * `oldContacts`: _Array_ The array of contacts to ping | ||
| * `newContact`: _Object_ The new contact to be added if one of old contacts does not respond | ||
| * `oldContacts`: _Array_ The array of contacts to ping. | ||
| * `newContact`: _Object_ The new contact to be added if one of old contacts does not respond. | ||
@@ -148,0 +162,0 @@ Emitted every time a contact is added that would exceed the capacity of a _don't split_ k-bucket it belongs to. |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
42114
5.58%717
1.13%160
9.59%