Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: record outdated local correction (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Nov 5, 2018
1 parent 9ca5826 commit d1869ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
34 changes: 34 additions & 0 deletions test/kad-dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d1869ed

Please sign in to comment.