libp2p-kad-dht
Advanced tools
Comparing version 0.10.6 to 0.11.0
@@ -0,1 +1,16 @@ | ||
<a name="0.11.0"></a> | ||
# [0.11.0](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.10.6...v0.11.0) (2018-11-09) | ||
### Bug Fixes | ||
* record outdated local correction ([#49](https://github.com/libp2p/js-libp2p-kad-dht/issues/49)) ([d1869ed](https://github.com/libp2p/js-libp2p-kad-dht/commit/d1869ed)) | ||
### Features | ||
* select first record when no selector function ([#51](https://github.com/libp2p/js-libp2p-kad-dht/issues/51)) ([683a903](https://github.com/libp2p/js-libp2p-kad-dht/commit/683a903)) | ||
<a name="0.10.6"></a> | ||
@@ -2,0 +17,0 @@ ## [0.10.6](https://github.com/libp2p/js-libp2p-kad-dht/compare/v0.10.5...v0.10.6) (2018-10-25) |
{ | ||
"name": "libp2p-kad-dht", | ||
"version": "0.10.6", | ||
"version": "0.11.0", | ||
"description": "JavaScript implementation of the Kad-DHT for libp2p", | ||
@@ -49,3 +49,3 @@ "leadMaintainer": "Vasco Santos <vasco.santos@moxy.studio>", | ||
"libp2p-crypto": "~0.13.0", | ||
"libp2p-record": "~0.6.0", | ||
"libp2p-record": "~0.6.1", | ||
"multihashes": "~0.4.14", | ||
@@ -52,0 +52,0 @@ "multihashing-async": "~0.5.1", |
@@ -274,3 +274,13 @@ 'use strict' | ||
const recs = vals.map((v) => v.val) | ||
const i = libp2pRecord.selection.bestRecord(dht.selectors, key, recs) | ||
let i = 0 | ||
try { | ||
i = libp2pRecord.selection.bestRecord(dht.selectors, key, recs) | ||
} catch (err) { | ||
// Assume the first record if no selector available | ||
if (err.code !== 'ERR_NO_SELECTOR_FUNCTION_FOR_RECORD_KEY') { | ||
return cb(err) | ||
} | ||
} | ||
const best = recs[i] | ||
@@ -303,3 +313,3 @@ dht._log('GetValue %b %s', key, best) | ||
// send correction | ||
dht._putValueToPeer(v.from, key, fixupRec, (err) => { | ||
dht._putValueToPeer(key, fixupRec, v.from, (err) => { | ||
if (err) { | ||
@@ -306,0 +316,0 @@ dht._log.error('Failed error correcting entry', err) |
@@ -225,2 +225,81 @@ /* eslint-env mocha */ | ||
it('put - get using key with no prefix (no selector available)', function (done) { | ||
this.timeout(10 * 1000) | ||
const tdht = new TestDHT() | ||
tdht.spawn(2, (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('hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('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) { | ||
this.timeout(10 * 1000) | ||
const tdht = new TestDHT() | ||
tdht.spawn(2, (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('/v2/hello'), Buffer.from('world'), cb), | ||
(cb) => dhtB.get(Buffer.from('/v2/hello'), { maxTimeout: 1000 }, cb) | ||
], (err) => { | ||
expect(err).to.exist() | ||
expect(err.code).to.eql('ERR_UNRECOGNIZED_KEY_PREFIX') | ||
tdht.teardown(done) | ||
}) | ||
}) | ||
}) | ||
it('put - get with update', function (done) { | ||
this.timeout(20 * 1000) | ||
const tdht = new TestDHT() | ||
tdht.spawn(2, (err, dhts) => { | ||
expect(err).to.not.exist() | ||
const dhtA = dhts[0] | ||
const dhtB = dhts[1] | ||
const dhtASpy = sinon.spy(dhtA, '_putValueToPeer') | ||
series([ | ||
(cb) => dhtA.put(Buffer.from('/v/hello'), Buffer.from('worldA'), cb), | ||
(cb) => dhtB.put(Buffer.from('/v/hello'), Buffer.from('worldB'), cb), | ||
(cb) => connect(dhtA, dhtB, cb) | ||
], (err) => { | ||
expect(err).to.not.exist() | ||
series([ | ||
(cb) => dhtA.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb), | ||
(cb) => dhtB.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb) | ||
], (err, results) => { | ||
expect(err).to.not.exist() | ||
results.forEach((res) => { | ||
expect(res).to.eql(Buffer.from('worldA')) // first is selected | ||
}) | ||
expect(dhtASpy.callCount).to.eql(1) | ||
expect(dhtASpy.getCall(0).args[2].isEqual(dhtB.peerInfo.id)).to.eql(true) // inform B | ||
tdht.teardown(done) | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('provides', function (done) { | ||
@@ -227,0 +306,0 @@ this.timeout(20 * 1000) |
@@ -59,2 +59,4 @@ 'use strict' | ||
dht.validators.v2 = dht.validators.v // added to simulate just validators available | ||
dht.selectors.v = (k, records) => 0 | ||
@@ -61,0 +63,0 @@ |
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
154582
4865
Updatedlibp2p-record@~0.6.1