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')
|
2021-08-19 13:18:50 +02:00
|
|
|
const { NOISE } = require('@chainsafe/libp2p-noise')
|
2020-01-07 14:56:05 +01:00
|
|
|
|
2020-05-15 15:37:47 +02:00
|
|
|
const createNode = async () => {
|
2020-01-07 14:56:05 +01:00
|
|
|
const node = await Libp2p.create({
|
2020-05-15 15:37:47 +02:00
|
|
|
addresses: {
|
2020-10-15 10:28:01 -05:00
|
|
|
// To signal the addresses we want to be available, we use
|
2020-05-15 15:37:47 +02:00
|
|
|
// the multiaddr format, a self describable address
|
|
|
|
listen: ['/ip4/0.0.0.0/tcp/0']
|
|
|
|
},
|
2020-01-07 14:56:05 +01:00
|
|
|
modules: {
|
|
|
|
transport: [TCP],
|
2020-10-07 16:16:36 +02:00
|
|
|
connEncryption: [NOISE]
|
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 () => {
|
2020-05-15 15:37:47 +02:00
|
|
|
const node = await createNode()
|
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:')
|
2020-05-15 15:37:47 +02:00
|
|
|
node.multiaddrs.forEach((ma) => console.log(`${ma.toString()}/p2p/${node.peerId.toB58String()}`))
|
2020-01-07 14:56:05 +01:00
|
|
|
})();
|