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

Commit

Permalink
fix(core/bootstrap): promisfy API and validate mulliaddr param
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Feb 15, 2018
1 parent 42545dc commit 08b3e16
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 6 deletions.
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)
}
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})
})
})
}
})
}
}
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

0 comments on commit 08b3e16

Please sign in to comment.