Comparing version 0.4.4 to 0.5.0
12
index.js
@@ -46,7 +46,5 @@ /* | ||
more details, see [arbiter function](#arbiter-function). | ||
* `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.randomBytes(20)`. If a String is provided, | ||
it will be assumed to be base64 encoded and will be converted into a | ||
Buffer. | ||
* `localNodeId`: _Buffer_ An optional Buffer representing the local node id. | ||
If not provided, a local node id will be created via | ||
`crypto.randomBytes(20)`. | ||
* `numberOfNodesPerKBucket`: _Integer_ _(Default: 20)_ The number of nodes | ||
@@ -79,4 +77,4 @@ that a k-bucket can contain before being full or split. | ||
self.localNodeId = options.localNodeId || crypto.randomBytes(20); | ||
if (!(self.localNodeId instanceof Buffer)) { | ||
self.localNodeId = new Buffer(self.localNodeId, 'base64'); | ||
if (!Buffer.isBuffer(self.localNodeId)) { | ||
throw new Error("localNodeId is not a Buffer"); | ||
} | ||
@@ -83,0 +81,0 @@ self.numberOfNodesPerKBucket = options.numberOfNodesPerKBucket || 20; |
{ | ||
"name": "k-bucket", | ||
"version": "0.4.4", | ||
"version": "0.5.0", | ||
"description": "Kademlia DHT K-bucket implementation as a binary tree", | ||
@@ -5,0 +5,0 @@ "scripts": { |
# k-bucket | ||
_Stability: 1 - [Experimental](https://github.com/tristanls/stability-index#stability-1---experimental)_ | ||
_Stability: 2 - [Unstable](https://github.com/tristanls/stability-index#stability-2---unstable)_ | ||
@@ -127,3 +127,3 @@ [![NPM version](https://badge.fury.io/js/k-bucket.png)](http://npmjs.org/package/k-bucket) | ||
* `arbiter`: _Function_ _(Default: vectorClock arbiter)_ `function (incumbent, candidate) { return contact; }` An optional `arbiter` function that givent two `contact` objects with the same `id` returns the desired object to be used for updating the k-bucket. For more details, see [arbiter function](#arbiter-function). | ||
* `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.randomBytes(20)`. If a String is provided, it will be assumed to be base64 encoded and will be converted into a Buffer. | ||
* `localNodeId`: _Buffer_ An optional Buffer representing the local node id. If not provided, a local node id will be created via `crypto.randomBytes(20)`. | ||
* `numberOfNodesPerKBucket`: _Integer_ _(Default: 20)_ The number of nodes that a k-bucket can contain before being full or split. | ||
@@ -130,0 +130,0 @@ * `numberOfNodesToPing`: _Integer_ _(Default: 3)_ The number of nodes to ping when a bucket that should not be split becomes full. KBucket will emit a `ping` event that contains `numberOfNodesToPing` nodes that have not been contacted the longest. |
"use strict"; | ||
var bufferEqual = require('buffer-equal'); | ||
var KBucket = require('../index.js'); | ||
@@ -20,12 +22,12 @@ | ||
test.ok(kBucket.localNodeId instanceof Buffer); | ||
test.equal(kBucket.localNodeId, localNodeId); | ||
test.ok(bufferEqual(kBucket.localNodeId, localNodeId)); | ||
test.done(); | ||
}; | ||
test['localNodeId is a Buffer populated from options if options.localNodeId String is provided'] = function (test) { | ||
test['throws exception if options.localNodeId is a String'] = function (test) { | ||
var localNodeId = "some identifier"; | ||
test.expect(2); | ||
var kBucket = new KBucket({localNodeId: localNodeId}); | ||
test.ok(kBucket.localNodeId instanceof Buffer); | ||
test.deepEqual(kBucket.localNodeId, new Buffer("some identifier", 'base64')); | ||
test.expect(1); | ||
test.throws(function() { | ||
new KBucket({localNodeId: "some identifier"}); | ||
}, Error); | ||
test.done(); | ||
@@ -37,4 +39,4 @@ }; | ||
var kBucket = new KBucket(); | ||
test.equal(kBucket.root, kBucket); | ||
test.strictEqual(kBucket.root, kBucket); | ||
test.done(); | ||
}; | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19
54687