diff --git a/packages/ipfs-core/src/ipns/republisher.js b/packages/ipfs-core/src/ipns/republisher.js index e419ab8884..93ca682dac 100644 --- a/packages/ipfs-core/src/ipns/republisher.js +++ b/packages/ipfs-core/src/ipns/republisher.js @@ -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) diff --git a/packages/ipfs-core/test/name.spec.js b/packages/ipfs-core/test/name.spec.js index b972915225..5612f9ec51 100644 --- a/packages/ipfs-core/test/name.spec.js +++ b/packages/ipfs-core/test/name.spec.js @@ -32,8 +32,8 @@ describe('name', function () { it('should republish entries', async function () { republisher = new IpnsRepublisher(sinon.stub(), sinon.stub(), sinon.stub(), sinon.stub(), { - initialBroadcastInterval: 500, - broadcastInterval: 1000 + initialBroadcastInterval: 200, + broadcastInterval: 500 }) republisher._republishEntries = sinon.stub() @@ -41,15 +41,35 @@ describe('name', function () { expect(republisher._republishEntries.calledOnce).to.equal(false) - // Initial republish should happen after ~500ms - await delay(750) + // Initial republish should happen after ~200ms + await delay(300) expect(republisher._republishEntries.calledOnce).to.equal(true) - // Subsequent republishes should happen after ~1500ms - await delay(1000) + // Subsequent republishes should happen after ~700 + await delay(600) 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: 100, + broadcastInterval: 1000, + pass: 'pass' + }) + republisher._republishEntry = sinon.stub() + + await republisher.start() + + expect(republisher._republishEntry.calledOnce).to.equal(false) + + // Initial republish should happen after ~100ms + await delay(200) + 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,