forked from libp2p/js-libp2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.js
36 lines (31 loc) · 974 Bytes
/
1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* eslint-disable no-console */
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { bootstrap } from '@libp2p/bootstrap'
import { mplex } from '@libp2p/mplex'
import { tcp } from '@libp2p/tcp'
import { createLibp2p } from 'libp2p'
import bootstrappers from './bootstrappers.js'
(async () => {
const node = await createLibp2p({
addresses: {
listen: ['/ip4/0.0.0.0/tcp/0']
},
transports: [tcp()],
streamMuxers: [yamux(), mplex()],
connectionEncryption: [noise()],
peerDiscovery: [
bootstrap({
list: bootstrappers
})
]
})
node.addEventListener('peer:connect', (evt) => {
const peerId = evt.detail
console.log('Connection established to:', peerId.toString()) // Emitted when a peer has been found
})
node.addEventListener('peer:discovery', (evt) => {
const peerInfo = evt.detail
console.log('Discovered:', peerInfo.id.toString())
})
})()