Last active
September 24, 2020 17:28
-
-
Save vasco-santos/4f22275a8146dfcf34dde830cabb23ae to your computer and use it in GitHub Desktop.
libp2p discovery setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Libp2p = require('libp2p') | |
const WebSockets = require('libp2p-websockets') | |
const WebRtcStar = require('libp2p-webrtc-star') | |
const Bootstrap = require('libp2p-bootstrap') | |
const Mdns = require('libp2p-mdns') | |
// Known peers addresses | |
const bootstrapMultiaddrs = [ | |
'/dns4/ams-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd', | |
'/dns4/lon-1.bootstrap.libp2p.io/tcp/443/wss/p2p/QmSoLMeWqB7YGVLJN3pNLQpmmEk35v6wYtsMGLzSr5QBU3' | |
] | |
const node = await Libp2p.create({ | |
modules: { | |
// … other required modules | |
transport: [WebSockets, WebRtcStar], | |
peerDiscovery: [Bootstrap, Mdns] | |
}, | |
config: { | |
peerDiscovery: { | |
[Bootstrap.tag]: { | |
enabled: true, | |
list: bootstrapMultiaddrs // provide array of multiaddrs | |
} | |
} | |
}, | |
// ... | |
}) | |
await node.start() | |
node.on('peer:discovery', (peer) => {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment