mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-03 08:11:04 +00:00
53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
/* eslint-disable no-console */
|
|
'use strict'
|
|
|
|
const Libp2p = require('../../')
|
|
const TCP = require('libp2p-tcp')
|
|
const Mplex = require('libp2p-mplex')
|
|
const { NOISE } = require('libp2p-noise')
|
|
const Bootstrap = require('libp2p-bootstrap')
|
|
|
|
// Find this list at: https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/config-nodejs.json
|
|
const bootstrapers = [
|
|
'/ip4/104.131.131.82/tcp/4001/p2p/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ',
|
|
'/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN',
|
|
'/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb',
|
|
'/dnsaddr/bootstrap.libp2p.io/p2p/QmZa1sAxajnQjVM8WjWXoMbmPd7NsWhfKsPkErzpm9wGkp',
|
|
'/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa',
|
|
'/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt'
|
|
]
|
|
|
|
;(async () => {
|
|
const node = await Libp2p.create({
|
|
addresses: {
|
|
listen: ['/ip4/0.0.0.0/tcp/0']
|
|
},
|
|
modules: {
|
|
transport: [TCP],
|
|
streamMuxer: [Mplex],
|
|
connEncryption: [NOISE],
|
|
peerDiscovery: [Bootstrap]
|
|
},
|
|
config: {
|
|
peerDiscovery: {
|
|
bootstrap: {
|
|
interval: 60e3,
|
|
enabled: true,
|
|
list: bootstrapers
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
node.connectionManager.on('peer:connect', (connection) => {
|
|
console.log('Connection established to:', connection.remotePeer.toB58String()) // Emitted when a peer has been found
|
|
})
|
|
|
|
node.on('peer:discovery', (peerId) => {
|
|
// No need to dial, autoDial is on
|
|
console.log('Discovered:', peerId.toB58String())
|
|
})
|
|
|
|
await node.start()
|
|
})();
|