js-libp2p/test/utils/create-node.js
Jacob Heun a95389a28e
feat: add delegated peer and content routing support (#242)
* feat: allow for configuring content and peer routing

* feat: support multiple peer and content routing modules

* docs: add delegated routing example
2018-10-19 16:28:28 +02:00

42 lines
950 B
JavaScript

/* 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')
const Node = require('./bundle-nodejs')
function createNode (multiaddrs, options, callback) {
if (typeof options === 'function') {
callback = options
options = {}
}
options = options || {}
if (!Array.isArray(multiaddrs)) {
multiaddrs = [multiaddrs]
}
waterfall([
(cb) => createPeerInfo(cb),
(peerInfo, cb) => {
multiaddrs.map((ma) => peerInfo.multiaddrs.add(ma))
options.peerInfo = peerInfo
cb(null, new Node(options))
}
], callback)
}
function createPeerInfo (callback) {
waterfall([
(cb) => PeerId.create({ bits: 512 }, cb),
(peerId, cb) => PeerInfo.create(peerId, cb)
], callback)
}
module.exports = createNode
module.exports.createPeerInfo = createPeerInfo