diff --git a/src/private.js b/src/private.js index 39ad0bed..da93ad47 100644 --- a/src/private.js +++ b/src/private.js @@ -299,7 +299,7 @@ module.exports = (dht) => ({ } // send correction - dht._putValueToPeer(v.from, key, fixupRec, (err) => { + dht._putValueToPeer(key, fixupRec, v.from, (err) => { if (err) { dht._log.error('Failed error correcting entry', err) } diff --git a/test/kad-dht.spec.js b/test/kad-dht.spec.js index 3455c199..76e7b261 100644 --- a/test/kad-dht.spec.js +++ b/test/kad-dht.spec.js @@ -222,6 +222,40 @@ describe('KadDHT', () => { }) }) + 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) { this.timeout(20 * 1000)