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

Commit d1869ed

Browse files
authored
fix: record outdated local correction (#49)
1 parent 9ca5826 commit d1869ed

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/private.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ module.exports = (dht) => ({
299299
}
300300

301301
// send correction
302-
dht._putValueToPeer(v.from, key, fixupRec, (err) => {
302+
dht._putValueToPeer(key, fixupRec, v.from, (err) => {
303303
if (err) {
304304
dht._log.error('Failed error correcting entry', err)
305305
}

test/kad-dht.spec.js

+34
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,40 @@ describe('KadDHT', () => {
222222
})
223223
})
224224

225+
it('put - get with update', function (done) {
226+
this.timeout(20 * 1000)
227+
const tdht = new TestDHT()
228+
229+
tdht.spawn(2, (err, dhts) => {
230+
expect(err).to.not.exist()
231+
const dhtA = dhts[0]
232+
const dhtB = dhts[1]
233+
234+
const dhtASpy = sinon.spy(dhtA, '_putValueToPeer')
235+
236+
series([
237+
(cb) => dhtA.put(Buffer.from('/v/hello'), Buffer.from('worldA'), cb),
238+
(cb) => dhtB.put(Buffer.from('/v/hello'), Buffer.from('worldB'), cb),
239+
(cb) => connect(dhtA, dhtB, cb)
240+
], (err) => {
241+
expect(err).to.not.exist()
242+
243+
series([
244+
(cb) => dhtA.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb),
245+
(cb) => dhtB.get(Buffer.from('/v/hello'), { maxTimeout: 1000 }, cb)
246+
], (err, results) => {
247+
expect(err).to.not.exist()
248+
results.forEach((res) => {
249+
expect(res).to.eql(Buffer.from('worldA')) // first is selected
250+
})
251+
expect(dhtASpy.callCount).to.eql(1)
252+
expect(dhtASpy.getCall(0).args[2].isEqual(dhtB.peerInfo.id)).to.eql(true) // inform B
253+
tdht.teardown(done)
254+
})
255+
})
256+
})
257+
})
258+
225259
it('provides', function (done) {
226260
this.timeout(20 * 1000)
227261

0 commit comments

Comments
 (0)