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

Commit bc76ddf

Browse files
committed
fix: do not republish self key twice
1 parent 63b11e5 commit bc76ddf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
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

+20
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ describe('name', function () {
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: 500,
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 ~500ms
69+
await delay(750)
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)