libp2p-kad-dht
Advanced tools
Comparing version 0.12.0 to 0.12.1
@@ -0,1 +1,11 @@ | ||
<a name="0.12.1"></a> | ||
## [0.12.1](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.12.0...v0.12.1) (2018-11-30) | ||
### Features | ||
* allow configurable validators and selectors ([#57](https://github.com/libp2p/js-libp2p-kad-dht/issues/57)) ([b731a1d](https://github.com/libp2p/js-libp2p-kad-dht/commit/b731a1d)) | ||
<a name="0.12.0"></a> | ||
@@ -2,0 +12,0 @@ # [0.12.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.11.1...v0.12.0) (2018-11-22) |
{ | ||
"name": "libp2p-kad-dht", | ||
"version": "0.12.0", | ||
"version": "0.12.1", | ||
"description": "JavaScript implementation of the Kad-DHT for libp2p", | ||
@@ -5,0 +5,0 @@ "leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>", |
@@ -39,2 +39,4 @@ 'use strict' | ||
* @param {boolean} options.enabledDiscovery enable dht discovery (default true) | ||
* @param {object} options.validators validators object with namespace as keys and function(key, record, callback) | ||
* @param {object} options.selectors selectors object with namespace as keys and function(key, records) | ||
*/ | ||
@@ -44,2 +46,4 @@ constructor (sw, options) { | ||
options = options || {} | ||
options.validators = options.validators | ||
options.selectors = options.selectors | ||
@@ -88,5 +92,12 @@ /** | ||
this.validators = { pk: libp2pRecord.validator.validators.pk } | ||
this.selectors = { pk: libp2pRecord.selection.selectors.pk } | ||
this.validators = { | ||
pk: libp2pRecord.validator.validators.pk, | ||
...options.validators | ||
} | ||
this.selectors = { | ||
pk: libp2pRecord.selection.selectors.pk, | ||
...options.selectors | ||
} | ||
this.network = new Network(this) | ||
@@ -93,0 +104,0 @@ |
@@ -142,2 +142,25 @@ /* eslint-env mocha */ | ||
it('create with validators and selectors', () => { | ||
const sw = new Switch(peerInfos[0], new PeerBook()) | ||
sw.transport.add('tcp', new TCP()) | ||
sw.connection.addStreamMuxer(Mplex) | ||
sw.connection.reuse() | ||
const dht = new KadDHT(sw, { | ||
validators: { | ||
ipns: { | ||
func: (key, record, cb) => cb() | ||
} | ||
}, | ||
selectors: { | ||
ipns: (key, records) => 0 | ||
} | ||
}) | ||
expect(dht).to.have.property('peerInfo').eql(peerInfos[0]) | ||
expect(dht).to.have.property('switch').eql(sw) | ||
expect(dht).to.have.property('routingTable') | ||
expect(dht.validators).to.have.property('ipns') | ||
expect(dht.selectors).to.have.property('ipns') | ||
}) | ||
it('should be able to start and stop', function (done) { | ||
@@ -284,2 +307,35 @@ const sw = new Switch(peerInfos[0], new PeerBook()) | ||
it('put - get using key from provided validator and selector', function (done) { | ||
this.timeout(10 * 1000) | ||
const tdht = new TestDHT() | ||
tdht.spawn(2, { | ||
validators: { | ||
ipns: { | ||
func: (key, record, cb) => cb() | ||
} | ||
}, | ||
selectors: { | ||
ipns: (key, records) => 0 | ||
} | ||
}, (err, dhts) => { | ||
expect(err).to.not.exist() | ||
const dhtA = dhts[0] | ||
const dhtB = dhts[1] | ||
waterfall([ | ||
(cb) => connect(dhtA, dhtB, cb), | ||
(cb) => dhtA.put(Buffer.from('/ipns/hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('/ipns/hello'), { maxTimeout: 1000 }, cb), | ||
(res, cb) => { | ||
expect(res).to.eql(Buffer.from('world')) | ||
cb() | ||
} | ||
], (err) => { | ||
expect(err).to.not.exist() | ||
tdht.teardown(done) | ||
}) | ||
}) | ||
}) | ||
it('put - get should fail if unrecognized key prefix in get', function (done) { | ||
@@ -286,0 +342,0 @@ this.timeout(10 * 1000) |
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
162764
5058