Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 8545a76

Browse files
authored
fix: do not republish self key twice (#3634)
* fix: do not republish self key twice * chore: decrease brodcast initial delay * chore: decrease other test timers
1 parent 4a14d20 commit 8545a76

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

packages/ipfs-core/src/ipns/republisher.js

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ class IpnsRepublisher {
138138
const keys = await this._keychain.listKeys()
139139

140140
for (const key of keys) {
141+
if (key.name === 'self') {
142+
continue
143+
}
141144
const pem = await this._keychain.exportKey(key.name, pass)
142145
const privKey = await crypto.keys.import(pem, pass)
143146

packages/ipfs-core/test/name.spec.js

+26-6
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,44 @@ describe('name', function () {
3232

3333
it('should republish entries', async function () {
3434
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), sinon.stub(), {
35-
initialBroadcastInterval: 500,
36-
broadcastInterval: 1000
35+
initialBroadcastInterval: 200,
36+
broadcastInterval: 500
3737
})
3838
republisher._republishEntries = sinon.stub()
3939

4040
await republisher.start()
4141

4242
expect(republisher._republishEntries.calledOnce).to.equal(false)
4343

44-
// Initial republish should happen after ~500ms
45-
await delay(750)
44+
// Initial republish should happen after ~200ms
45+
await delay(300)
4646
expect(republisher._republishEntries.calledOnce).to.equal(true)
4747

48-
// Subsequent republishes should happen after ~1500ms
49-
await delay(1000)
48+
// Subsequent republishes should happen after ~700
49+
await delay(600)
5050
expect(republisher._republishEntries.calledTwice).to.equal(true)
5151
})
5252

53+
it('should not republish self key twice', async function () {
54+
const mockKeychain = {
55+
listKeys: () => Promise.resolve([{ name: 'self' }])
56+
}
57+
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), mockKeychain, {
58+
initialBroadcastInterval: 100,
59+
broadcastInterval: 1000,
60+
pass: 'pass'
61+
})
62+
republisher._republishEntry = sinon.stub()
63+
64+
await republisher.start()
65+
66+
expect(republisher._republishEntry.calledOnce).to.equal(false)
67+
68+
// Initial republish should happen after ~100ms
69+
await delay(200)
70+
expect(republisher._republishEntry.calledOnce).to.equal(true)
71+
})
72+
5373
it('should error if run republish again', async () => {
5474
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), sinon.stub(), {
5575
initialBroadcastInterval: 50,

0 commit comments

Comments
 (0)