Skip to content

Commit eb7adcf

Browse files
vasco-santosjacobheun
authored andcommittedMay 28, 2020
docs: libp2p components options specified
1 parent 0be74e6 commit eb7adcf

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed
 

‎doc/API.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ Creates an instance of Libp2p.
8080
| Name | Type | Description |
8181
|------|------|-------------|
8282
| options | `object` | libp2p options |
83-
| options.modules | `Array<object>` | libp2p modules to use |
83+
| options.modules | [`Array<object>`](./CONFIGURATION.md#modules) | libp2p modules to use |
8484
| [options.addresses] | `{ listen: Array<string>, announce: Array<string>, noAnnounce: Array<string> }` | Addresses for transport listening and to advertise to the network |
8585
| [options.config] | `object` | libp2p modules configuration and core configuration |
86-
| [options.connectionManager] | `object` | libp2p Connection Manager configuration |
86+
| [options.connectionManager] | [`object`](./CONFIGURATION.md#configuring-connection-manager) | libp2p Connection Manager configuration |
8787
| [options.datastore] | `object` | must implement [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore) (in memory datastore will be used if not provided) |
88-
| [options.dialer] | `object` | libp2p Dialer configuration
88+
| [options.dialer] | [`object`](./CONFIGURATION.md#configuring-dialing) | libp2p Dialer configuration
8989
| [options.keychain] | [`object`](./CONFIGURATION.md#setup-with-keychain) | keychain configuration |
90-
| [options.metrics] | `object` | libp2p Metrics configuration
90+
| [options.metrics] | [`object`](./CONFIGURATION.md#configuring-metrics) | libp2p Metrics configuration
9191
| [options.peerId] | [`PeerId`][peer-id] | peerId instance (it will be created if not provided) |
92-
| [options.peerStore] | `object` | libp2p PeerStore configuration |
92+
| [options.peerStore] | [`object`](./CONFIGURATION.md#configuring-peerstore) | libp2p PeerStore configuration |
9393

9494
For Libp2p configurations and modules details read the [Configuration Document](./CONFIGURATION.md).
9595

‎doc/CONFIGURATION.md

+42-16
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- [Configuring Dialing](#configuring-dialing)
2525
- [Configuring Connection Manager](#configuring-connection-manager)
2626
- [Configuring Metrics](#configuring-metrics)
27+
- [Configuring PeerStore](#configuring-peerstore)
2728
- [Customizing Transports](#customizing-transports)
2829
- [Configuration examples](#configuration-examples)
2930

@@ -376,24 +377,24 @@ const MPLEX = require('libp2p-mplex')
376377
const SECIO = require('libp2p-secio')
377378
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
378379
const DelegatedContentRouter = require('libp2p-delegated-content-routing')
379-
const PeerInfo = require('peer-info')
380+
const PeerId = require('peer-id')
380381

381-
// create a peerInfo
382-
const peerInfo = await PeerInfo.create()
382+
// create a peerId
383+
const peerId = await PeerId.create()
383384

384385
const node = await Libp2p.create({
385386
modules: {
386387
transport: [TCP],
387388
streamMuxer: [MPLEX],
388389
connEncryption: [SECIO],
389390
contentRouting: [
390-
new DelegatedContentRouter(peerInfo.id)
391+
new DelegatedContentRouter(peerId)
391392
],
392393
peerRouting: [
393394
new DelegatedPeerRouter()
394395
],
395396
},
396-
peerInfo
397+
peerId
397398
})
398399
```
399400

@@ -456,7 +457,15 @@ await libp2p.loadKeychain()
456457

457458
#### Configuring Dialing
458459

459-
Dialing in libp2p can be configured to limit the rate of dialing, and how long dials are allowed to take. The below configuration example shows the default values for the dialer.
460+
Dialing in libp2p can be configured to limit the rate of dialing, and how long dials are allowed to take. The dialer configuration object should have the following properties:
461+
462+
| Name | Type | Description |
463+
|------|------|-------------|
464+
| maxParallelDials | `number` | How many multiaddrs we can dial in parallel. |
465+
| maxDialsPerPeer | `number` | How many multiaddrs we can dial per peer, in parallel. |
466+
| dialTimeout | `number` | Second dial timeout per peer in ms. |
467+
468+
The below configuration example shows how the dialer should be configured, with the current defaults:
460469

461470
```js
462471
const Libp2p = require('libp2p')
@@ -471,9 +480,9 @@ const node = await Libp2p.create({
471480
connEncryption: [SECIO]
472481
},
473482
dialer: {
474-
maxParallelDials: 100, // How many multiaddrs we can dial in parallel
475-
maxDialsPerPeer: 4, // How many multiaddrs we can dial per peer, in parallel
476-
dialTimeout: 30e3 // 30 second dial timeout per peer
483+
maxParallelDials: 100,
484+
maxDialsPerPeer: 4,
485+
dialTimeout: 30e3
477486
}
478487
```
479488
@@ -510,7 +519,17 @@ const node = await Libp2p.create({
510519
511520
#### Configuring Metrics
512521
513-
Metrics are disabled in libp2p by default. You can enable and configure them as follows. Aside from enabled being `false` by default, the configuration options listed here are the current defaults.
522+
Metrics are disabled in libp2p by default. You can enable and configure them as follows:
523+
524+
| Name | Type | Description |
525+
|------|------|-------------|
526+
| enabled | `boolean` | Enabled metrics collection. |
527+
| computeThrottleMaxQueueSize | `number` | How many messages a stat will queue before processing. |
528+
| computeThrottleTimeout | `number` | Time in milliseconds a stat will wait, after the last item was added, before processing. |
529+
| movingAverageIntervals | `Array<number>` | The moving averages that will be computed. |
530+
| maxOldPeersRetention | `number` | How many disconnected peers we will retain stats for. |
531+
532+
The below configuration example shows how the metrics should be configured. Aside from enabled being `false` by default, the following default configuration options are listed below:
514533
515534
```js
516535
const Libp2p = require('libp2p')
@@ -526,14 +545,14 @@ const node = await Libp2p.create({
526545
},
527546
metrics: {
528547
enabled: true,
529-
computeThrottleMaxQueueSize: 1000, // How many messages a stat will queue before processing
530-
computeThrottleTimeout: 2000, // Time in milliseconds a stat will wait, after the last item was added, before processing
531-
movingAverageIntervals: [ // The moving averages that will be computed
548+
computeThrottleMaxQueueSize: 1000,
549+
computeThrottleTimeout: 2000,
550+
movingAverageIntervals: [
532551
60 * 1000, // 1 minute
533552
5 * 60 * 1000, // 5 minutes
534553
15 * 60 * 1000 // 15 minutes
535554
],
536-
maxOldPeersRetention: 50 // How many disconnected peers we will retain stats for
555+
maxOldPeersRetention: 50
537556
}
538557
})
539558
```
@@ -544,6 +563,13 @@ PeerStore persistence is disabled in libp2p by default. You can enable and confi
544563
545564
The threshold number represents the maximum number of "dirty peers" allowed in the PeerStore, i.e. peers that are not updated in the datastore. In this context, browser nodes should use a threshold of 1, since they might not "stop" properly in several scenarios and the PeerStore might end up with unflushed records when the window is closed.
546565
566+
| Name | Type | Description |
567+
|------|------|-------------|
568+
| persistence | `boolean` | Is persistence enabled. |
569+
| threshold | `number` | Number of dirty peers allowed. |
570+
571+
The below configuration example shows how the PeerStore should be configured. Aside from persistence being `false` by default, the following default configuration options are listed below:
572+
547573
```js
548574
const Libp2p = require('libp2p')
549575
const TCP = require('libp2p-tcp')
@@ -560,8 +586,8 @@ const node = await Libp2p.create({
560586
},
561587
datastore: new LevelStore('path/to/store'),
562588
peerStore: {
563-
persistence: true, // Is persistence enabled (default: false)
564-
threshold: 5 // Number of dirty peers allowed (default: 5)
589+
persistence: true,
590+
threshold: 5
565591
}
566592
})
567593
```

0 commit comments

Comments
 (0)
Please sign in to comment.