mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-22 02:20:50 +00:00
* docs: update chat example and add info to its readme * docs: update echo example * docs: update libp2p in browser example * docs: update pubsub example * docs: update peer and content routing examples * docs: update discovery mechanisms example * docs: update encrypted comms example * docs: update protocol and stream muxing example * feat: add config validation * test: update CI configs, use only node 8
39 lines
839 B
JavaScript
39 lines
839 B
JavaScript
'use strict'
|
|
|
|
const libp2p = require('../../')
|
|
const TCP = require('libp2p-tcp')
|
|
const PeerInfo = require('peer-info')
|
|
const waterfall = require('async/waterfall')
|
|
const defaultsDeep = require('@nodeutils/defaults-deep')
|
|
|
|
class MyBundle extends libp2p {
|
|
constructor (_options) {
|
|
const defaults = {
|
|
modules: {
|
|
transport: [
|
|
TCP
|
|
]
|
|
}
|
|
}
|
|
|
|
super(defaultsDeep(_options, defaults))
|
|
}
|
|
}
|
|
|
|
let node
|
|
|
|
waterfall([
|
|
(cb) => PeerInfo.create(cb),
|
|
(peerInfo, cb) => {
|
|
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0')
|
|
node = new MyBundle({ peerInfo: peerInfo })
|
|
node.start(cb)
|
|
}
|
|
], (err) => {
|
|
if (err) { throw err }
|
|
|
|
console.log('node has started (true/false):', node.isStarted())
|
|
console.log('listening on:')
|
|
node.peerInfo.multiaddrs.forEach((ma) => console.log(ma.toString()))
|
|
})
|