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

Commit

Permalink
fix: do not republish self key twice
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Apr 27, 2021
1 parent c79d3d6 commit 26a46ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/ipfs-core/src/ipns/republisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ class IpnsRepublisher {
const keys = await this._keychain.listKeys()

for (const key of keys) {
if (key.name === 'self') {
continue
}
const pem = await this._keychain.exportKey(key.name, pass)
const privKey = await crypto.keys.import(pem, pass)

Expand Down
20 changes: 20 additions & 0 deletions packages/ipfs-core/test/name.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ describe('name', function () {
expect(republisher._republishEntries.calledTwice).to.equal(true)
})

it('should not republish self key twice', async function () {
const mockKeychain = {
listKeys: () => Promise.resolve([{ name: 'self' }])
}
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), mockKeychain, {
initialBroadcastInterval: 500,
broadcastInterval: 1000,
pass: 'pass'
})
republisher._republishEntry = sinon.stub()

await republisher.start()

expect(republisher._republishEntry.calledOnce).to.equal(false)

// Initial republish should happen after ~500ms
await delay(750)
expect(republisher._republishEntry.calledOnce).to.equal(true)
})

it('should error if run republish again', async () => {
republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), sinon.stub(), {
initialBroadcastInterval: 50,
Expand Down

0 comments on commit 26a46ec

Please sign in to comment.