-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example in readme #236
Comments
I do see an example: import { Discv5Discovery, ENR } from "@chainsafe/discv5";
import Libp2p from "libp2p";
import PeerId from "peer-id";
const myPeerId: PeerId = ...;
const bootstrapEnrs: ENR[] = [...];
const libp2p = new Libp2p({
peerId: myPeerId,
modules: {
peerDiscovery: [Discv5Discovery],
},
config: {
discv5: {
enr: ENR.createFromPeerId(myPeerInfo.id),
bindAddr: "/ip4/0.0.0.0/udp/9000",
bootstrapEnrs: bootstrapEnrs,
searchInterval: 30000, // wait 30s between searches
},
},
}); However, if we compare with an example from the Bootstrap discovery mechanism from the libp2p website itself import { createLibp2p } from 'libp2p'
import { bootstrap } from '@libp2p/bootstrap'
import { tcp } from 'libp2p/tcp'
import { noise } from '@libp2p/noise'
import { mplex } from '@libp2p/mplex'
let options = {
transports: [
tcp()
],
streamMuxers: [
mplex()
],
connectionEncryption: [
noise()
],
peerDiscovery: [
bootstrap({
list: [ // a list of bootstrap peer multiaddrs to connect to on node startup
"/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
"/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa"
],
timeout: 1000, // in ms,
tagName: 'bootstrap',
tagValue: 50,
tagTTL: 120000 // in ms
})
]
}
const libp2p = await createLibp2p(options)
libp2p.on('peer:discovery', function (peerId) {
console.log('found peer: ', peerId.toB58String())
}) These examples seem radically different. The libp2p example uses Could it be that the current example is for an older version of libp2p? Nowadays I tend to make tests in my project containing the example code that I use in the docs, so that when something changes the test breaks and I get a reminder that de example code in the docs needs to be updated. |
Yeah, thats what happened
Good idea, we have a much better example that's an e2e test, better to use that |
Related #8 |
we should have better usage docs for this library
cc @holgerd77
The text was updated successfully, but these errors were encountered: