1
0
mirror of https://github.com/fluencelabs/js-libp2p synced 2025-04-03 08:11:04 +00:00
Vasco Santos c038550fad
fix: throw if no conn encryption module provided ()
* fix: throw if no conn encryption module provided

* chore: address review

* chore: apply suggestions from code review

Co-authored-by: Jacob Heun <jacobheun@gmail.com>

Co-authored-by: Jacob Heun <jacobheun@gmail.com>
2020-06-11 12:49:32 +02:00

49 lines
1.0 KiB
JavaScript

/* eslint-disable no-console */
'use strict'
const Libp2p = require('../../')
const TCP = require('libp2p-tcp')
const Mplex = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const { NOISE } = require('libp2p-noise')
const MulticastDNS = require('libp2p-mdns')
const createNode = async () => {
const node = await Libp2p.create({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0']
},
modules: {
transport: [TCP],
streamMuxer: [Mplex],
connEncryption: [NOISE, SECIO],
peerDiscovery: [MulticastDNS]
},
config: {
peerDiscovery: {
[MulticastDNS.tag]: {
interval: 20e3,
enabled: true
}
}
}
})
return node
}
;(async () => {
const [node1, node2] = await Promise.all([
createNode(),
createNode()
])
node1.on('peer:discovery', (peerId) => console.log('Discovered:', peerId.toB58String()))
node2.on('peer:discovery', (peerId) => console.log('Discovered:', peerId.toB58String()))
await Promise.all([
node1.start(),
node2.start()
])
})();