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

Commit

Permalink
feat: Bootstrap API compliance (#1218)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider authored and daviddias committed Feb 15, 2018
1 parent 48881a3 commit 9a445d1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"form-data": "^2.3.2",
"go-ipfs-dep": "^0.4.13",
"hat": "0.0.3",
"interface-ipfs-core": "~0.50.1",
"interface-ipfs-core": "~0.51.0",
"ipfsd-ctl": "~0.28.0",
"left-pad": "^1.2.0",
"lodash": "^4.17.5",
Expand Down
28 changes: 22 additions & 6 deletions src/core/components/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
'use strict'

const defaultNodes = require('../runtime/config-nodejs.json').Bootstrap
const MultiAddr = require('multiaddr')
const promisify = require('promisify-es6')

module.exports = function bootstrap (self) {
return {
list: (callback) => {
list: promisify((callback) => {
self._repo.config.get((err, config) => {
if (err) {
return callback(err)
}
callback(null, {Peers: config.Bootstrap})
})
},
add: (multiaddr, args, callback) => {
}),
add: promisify((multiaddr, args, callback) => {
if (typeof args === 'function') {
callback = args
args = {default: false}
}
try {
if (multiaddr)
new MultiAddr(multiaddr)
}

This comment has been minimized.

Copy link
@daviddias

daviddias Feb 17, 2018

Member

Somehow this escaped the linting checks

catch (err) {
return setImmediate(() => callback(err))
}
self._repo.config.get((err, config) => {
if (err) {
return callback(err)
Expand All @@ -36,12 +45,19 @@ module.exports = function bootstrap (self) {
})
})
})
},
rm: (multiaddr, args, callback) => {
}),
rm: promisify((multiaddr, args, callback) => {
if (typeof args === 'function') {
callback = args
args = {all: false}
}
try {
if (multiaddr)
new MultiAddr(multiaddr)
}
catch (err) {
return setImmediate(() => callback(err))
}
self._repo.config.get((err, config) => {
if (err) {
return callback(err)
Expand All @@ -65,6 +81,6 @@ module.exports = function bootstrap (self) {
callback(null, {Peers: res})
})
})
}
})
}
}
10 changes: 5 additions & 5 deletions test/core/bootstrap.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('bootstrap', () => {
'/ip6/2604:a880:1:20::1d9:6001/tcp/4001/ipfs/QmSoLju6m7xTh3DuokvT3886QRYqxAzb1kShaanJgW36yx',
'/dns4/wss0.bootstrap.libp2p.io/tcp/443/wss/ipfs/QmZMxNdpMkewiVZLMRxaNxUeZpDUb34pWjZ1kZvsd16Zic',
'/dns4/wss1.bootstrap.libp2p.io/tcp/443/wss/ipfs/Qmbut9Ywz9YEDrz8ySBSgWyJk41Uvm2QJPhwDJzJyGFsD6',
'/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'
'/ip4/111.111.111.111/tcp/1001/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb'
]

it('get bootstrap list', (done) => {
Expand All @@ -93,9 +93,9 @@ describe('bootstrap', () => {
})

it('add a peer to the bootstrap list', (done) => {
node.bootstrap.add('/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT', (err, res) => {
node.bootstrap.add('/ip4/111.111.111.111/tcp/1001/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb', (err, res) => {
expect(err).to.not.exist()
expect(res).to.be.eql({ Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'] })
expect(res).to.be.eql({ Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb'] })
node.bootstrap.list((err, list) => {
expect(err).to.not.exist()
expect(list.Peers).to.deep.equal(updatedList)
Expand All @@ -105,9 +105,9 @@ describe('bootstrap', () => {
})

it('remove a peer from the bootstrap list', (done) => {
node.bootstrap.rm('/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT', (err, res) => {
node.bootstrap.rm('/ip4/111.111.111.111/tcp/1001/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb', (err, res) => {
expect(err).to.not.exist()
expect(res).to.be.eql({ Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLUVIT'] })
expect(res).to.be.eql({ Peers: ['/ip4/111.111.111.111/tcp/1001/ipfs/QmXFX2P5ammdmXQgfqGkfswtEVFsZUJ5KeHRXQYCTdiTAb'] })
node.bootstrap.list((err, list) => {
expect(err).to.not.exist()
expect(list.Peers).to.deep.equal(defaultList)
Expand Down
33 changes: 33 additions & 0 deletions test/core/interface/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* eslint-env mocha */
'use strict'

const test = require('interface-ipfs-core')
const parallel = require('async/parallel')

const IPFS = require('../../../src')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ type: 'proc', exec: IPFS })

const nodes = []
const common = {
setup: function (callback) {
callback(null, {
spawnNode: (cb) => {
df.spawn((err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, _ipfsd.api)
})
}
})
},
teardown: function (callback) {
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
}
}

test.bootstrap(common)
1 change: 1 addition & 0 deletions test/core/interface/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const isNode = require('detect-node')

describe('interface-ipfs-core tests', () => {
require('./block')
require('./bootstrap')
require('./config')
require('./files')
require('./generic')
Expand Down
31 changes: 31 additions & 0 deletions test/http-api/interface/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-env mocha */
'use strict'

const test = require('interface-ipfs-core')
const parallel = require('async/parallel')

const DaemonFactory = require('ipfsd-ctl')
const df = DaemonFactory.create({ exec: 'src/cli/bin.js' })

const nodes = []
const common = {
setup: function (callback) {
callback(null, {
spawnNode: (cb) => {
df.spawn((err, _ipfsd) => {
if (err) {
return cb(err)
}

nodes.push(_ipfsd)
cb(null, _ipfsd.api)
})
}
})
},
teardown: function (callback) {
parallel(nodes.map((node) => (cb) => node.stop(cb)), callback)
}
}

test.bootstrap(common)

0 comments on commit 9a445d1

Please sign in to comment.