Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 60fe851

Browse files
authored
docs: custom-libp2p example print peer id in swarm addresses on startup (#2775)
Since libp2p/js-libp2p#558 js-libp2p now requires peer ids to be part of dialled multiaddrs. Previously a user was able to copy/paste swarm addresses printed as part of the daemon starting up but now they can't because the peer id is not included in the console output. This PR prints the node's peer id as part of the swarm address to let people continue doing this and fixes the custom-libp2p example.
1 parent ffb1ebe commit 60fe851

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

examples/custom-libp2p/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const libp2pBundle = (opts) => {
3232
const bootstrapList = opts.config.Bootstrap
3333

3434
// Build and return our libp2p node
35+
// n.b. for full configuration options, see https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md
3536
return new Libp2p({
3637
peerInfo,
3738
peerBook,
@@ -91,6 +92,17 @@ const libp2pBundle = (opts) => {
9192
pubsub: {
9293
enabled: true
9394
}
95+
},
96+
metrics: {
97+
enabled: true,
98+
computeThrottleMaxQueueSize: 1000, // How many messages a stat will queue before processing
99+
computeThrottleTimeout: 2000, // Time in milliseconds a stat will wait, after the last item was added, before processing
100+
movingAverageIntervals: [ // The moving averages that will be computed
101+
60 * 1000, // 1 minute
102+
5 * 60 * 1000, // 5 minutes
103+
15 * 60 * 1000 // 15 minutes
104+
],
105+
maxOldPeersRetention: 50 // How many disconnected peers we will retain stats for
94106
}
95107
})
96108
}

src/core/components/start.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = ({
5757

5858
await libp2p.start()
5959

60-
peerInfo.multiaddrs.forEach(ma => print('Swarm listening on', ma.toString()))
60+
peerInfo.multiaddrs.forEach(ma => print(`Swarm listening on ${ma}/p2p/${peerInfo.id.toB58String()}`))
6161

6262
const ipnsRouting = routingConfig({ libp2p, repo, peerInfo, options: constructorOptions })
6363
const ipns = new IPNS(ipnsRouting, repo.datastore, peerInfo, keychain, { pass: initOptions.pass })

0 commit comments

Comments
 (0)