2018-10-19 17:37:34 +02:00
|
|
|
/* eslint-disable no-console */
|
2017-07-06 14:26:20 +01:00
|
|
|
'use strict'
|
|
|
|
|
2020-01-07 14:56:05 +01:00
|
|
|
const Libp2p = require('../..')
|
2017-07-06 14:26:20 +01:00
|
|
|
const TCP = require('libp2p-tcp')
|
2020-01-07 14:56:05 +01:00
|
|
|
const SECIO = require('libp2p-secio')
|
2017-07-06 14:26:20 +01:00
|
|
|
const PeerInfo = require('peer-info')
|
|
|
|
|
2020-01-07 14:56:05 +01:00
|
|
|
const createNode = async (peerInfo) => {
|
|
|
|
// To signall the addresses we want to be available, we use
|
|
|
|
// the multiaddr format, a self describable address
|
|
|
|
peerInfo.multiaddrs.add('/ip4/0.0.0.0/tcp/0')
|
|
|
|
|
|
|
|
const node = await Libp2p.create({
|
|
|
|
peerInfo,
|
|
|
|
modules: {
|
|
|
|
transport: [TCP],
|
|
|
|
connEncryption: [SECIO]
|
2017-07-06 14:26:20 +01:00
|
|
|
}
|
2020-01-07 14:56:05 +01:00
|
|
|
})
|
2018-06-28 10:06:25 +02:00
|
|
|
|
2020-01-07 14:56:05 +01:00
|
|
|
await node.start()
|
|
|
|
return node
|
2017-07-06 14:26:20 +01:00
|
|
|
}
|
|
|
|
|
2020-01-07 14:56:05 +01:00
|
|
|
;(async () => {
|
|
|
|
const peerInfo = await PeerInfo.create()
|
|
|
|
const node = await createNode(peerInfo)
|
2017-07-06 14:26:20 +01:00
|
|
|
|
2017-07-31 17:35:08 +08:00
|
|
|
console.log('node has started (true/false):', node.isStarted())
|
2017-07-06 14:26:20 +01:00
|
|
|
console.log('listening on:')
|
|
|
|
node.peerInfo.multiaddrs.forEach((ma) => console.log(ma.toString()))
|
2020-01-07 14:56:05 +01:00
|
|
|
})();
|