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

Commit ce504cd

Browse files
kenshyxdaviddias
authored andcommitted
fix(bootstrap:add): prevent duplicate inserts (#893)
* fix(bootstrap:add): prevent duplicate inserts
1 parent 8166ca9 commit ce504cd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/core/components/bootstrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = function bootstrap (self) {
2727
}
2828
if (args.default) {
2929
config.Bootstrap = defaultNodes
30-
} else if (multiaddr) {
30+
} else if (multiaddr && config.Bootstrap.indexOf(multiaddr) === -1) {
3131
config.Bootstrap.push(multiaddr)
3232
}
3333
self._repo.config.set(config, (err) => {

test/http-api/over-ipfs-api/bootstrap.js

+24
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ module.exports = (ctl) => {
2828
})
2929
})
3030

31+
it('prevents duplicate inserts of bootstrap peers', () => {
32+
return ctl
33+
.bootstrap
34+
.rm(null, { all: true })
35+
.then((res) => {
36+
expect(res.Peers.length).to.equal(0)
37+
return ctl.bootstrap.add(validIp4)
38+
})
39+
.then(res => {
40+
expect(res).to.be.eql({ Peers: [validIp4] })
41+
return ctl.bootstrap.add(validIp4)
42+
})
43+
.then((res) => {
44+
expect(res).to.be.eql({ Peers: [validIp4] })
45+
return ctl.bootstrap.list()
46+
})
47+
.then((res) => {
48+
expect(res).to.exist()
49+
const insertPosition = res.Peers.indexOf(validIp4)
50+
expect(insertPosition).to.not.equal(-1)
51+
expect(res.Peers.length).to.equal(1)
52+
})
53+
})
54+
3155
it('returns a list of bootstrap peers when called with the default option', (done) => {
3256
ctl.bootstrap.add({ default: true }, (err, res) => {
3357
expect(err).to.not.exist()

0 commit comments

Comments
 (0)