diff --git a/src/core/components/bootstrap.js b/src/core/components/bootstrap.js index af2bd95818..21c4615132 100644 --- a/src/core/components/bootstrap.js +++ b/src/core/components/bootstrap.js @@ -27,7 +27,7 @@ module.exports = function bootstrap (self) { } if (args.default) { config.Bootstrap = defaultNodes - } else if (multiaddr) { + } else if (multiaddr && config.Bootstrap.indexOf(multiaddr) === -1) { config.Bootstrap.push(multiaddr) } self._repo.config.set(config, (err) => { diff --git a/src/core/components/stop.js b/src/core/components/stop.js index d5fb672c84..865c6f2943 100644 --- a/src/core/components/stop.js +++ b/src/core/components/stop.js @@ -1,7 +1,6 @@ 'use strict' const series = require('async/series') -const setImmediate = require('async/setImmediate') module.exports = (self) => { return (callback) => { diff --git a/test/http-api/over-ipfs-api/bootstrap.js b/test/http-api/over-ipfs-api/bootstrap.js index 1e31b40412..ebde07318e 100644 --- a/test/http-api/over-ipfs-api/bootstrap.js +++ b/test/http-api/over-ipfs-api/bootstrap.js @@ -28,6 +28,30 @@ module.exports = (ctl) => { }) }) + it('prevents duplicate inserts of bootstrap peers', () => { + return ctl + .bootstrap + .rm(null, { all: true }) + .then((res) => { + expect(res.Peers.length).to.equal(0) + return ctl.bootstrap.add(validIp4) + }) + .then(res => { + expect(res).to.be.eql({ Peers: [validIp4] }) + return ctl.bootstrap.add(validIp4) + }) + .then((res) => { + expect(res).to.be.eql({ Peers: [validIp4] }) + return ctl.bootstrap.list() + }) + .then((res) => { + expect(res).to.exist() + const insertPosition = res.Peers.indexOf(validIp4) + expect(insertPosition).to.not.equal(-1) + expect(res.Peers.length).to.equal(1) + }) + }) + it('returns a list of bootstrap peers when called with the default option', (done) => { ctl.bootstrap.add({ default: true }, (err, res) => { expect(err).to.not.exist()