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

fix: do not republish self key twice #3634

Merged
merged 3 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 26 additions & 6 deletions packages/ipfs-core/test/name.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,44 @@ 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()

await republisher.start()

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need stopping?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is stopped in the afterEach (line 29), like remaining tests


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,
Expand Down