2017-07-04 11:43:45 +01:00
|
|
|
/* eslint-env mocha */
|
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const chai = require('chai')
|
|
|
|
chai.use(require('dirty-chai'))
|
|
|
|
const PeerInfo = require('peer-info')
|
|
|
|
const PeerId = require('peer-id')
|
|
|
|
const waterfall = require('async/waterfall')
|
2018-06-28 10:06:25 +02:00
|
|
|
const Node = require('./bundle-nodejs')
|
2017-07-04 11:43:45 +01:00
|
|
|
|
|
|
|
function createNode (multiaddrs, options, callback) {
|
|
|
|
if (typeof options === 'function') {
|
|
|
|
callback = options
|
|
|
|
options = {}
|
|
|
|
}
|
|
|
|
|
2017-10-26 04:51:36 -07:00
|
|
|
options = options || {}
|
|
|
|
|
2017-07-04 11:43:45 +01:00
|
|
|
if (!Array.isArray(multiaddrs)) {
|
|
|
|
multiaddrs = [multiaddrs]
|
|
|
|
}
|
|
|
|
|
|
|
|
waterfall([
|
2018-10-19 16:28:28 +02:00
|
|
|
(cb) => createPeerInfo(cb),
|
2017-07-04 11:43:45 +01:00
|
|
|
(peerInfo, cb) => {
|
|
|
|
multiaddrs.map((ma) => peerInfo.multiaddrs.add(ma))
|
2018-06-28 10:06:25 +02:00
|
|
|
options.peerInfo = peerInfo
|
|
|
|
cb(null, new Node(options))
|
2017-07-04 11:43:45 +01:00
|
|
|
}
|
|
|
|
], callback)
|
|
|
|
}
|
|
|
|
|
2018-10-19 16:28:28 +02:00
|
|
|
function createPeerInfo (callback) {
|
|
|
|
waterfall([
|
|
|
|
(cb) => PeerId.create({ bits: 512 }, cb),
|
|
|
|
(peerId, cb) => PeerInfo.create(peerId, cb)
|
|
|
|
], callback)
|
|
|
|
}
|
|
|
|
|
2018-06-28 10:06:25 +02:00
|
|
|
module.exports = createNode
|
2018-10-19 16:28:28 +02:00
|
|
|
module.exports.createPeerInfo = createPeerInfo
|