You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
libp2p is a modular networking stack. It's designed to be able to suit a variety of project needs. The configuration of libp2p is a key part of its structure. It enables you to bring exactly what you need, and only what you need. This document is a guide on how to configure libp2p for your particular project. Check out the [Configuration examples](#configuration-examples) section if you're just looking to leverage an existing configuration.
19
20
20
-
`js-libp2p` acts as the composer for this modular p2p networking stack using libp2p compatible modules as its building blocks.
21
21
Regardless of how you configure libp2p, the top level [API](./API.md) will always remain the same. **Note**: if some modules are not configured, like Content Routing, using those methods will throw errors.
22
22
23
23
## Modules
24
24
25
-
For getting an instance of `js-libp2p` compliant with all types of networking requirements, it is possible to specify the following building blocks:
25
+
`js-libp2p` acts as the composer for this modular p2p networking stack using libp2p compatible modules as its subsystems. For getting an instance of `js-libp2p` compliant with all types of networking requirements, it is possible to specify the following subsystems:
26
26
27
27
- Transports
28
28
- Multiplexers
@@ -33,11 +33,11 @@ For getting an instance of `js-libp2p` compliant with all types of networking re
33
33
- DHT implementation
34
34
- Pubsub router
35
35
36
-
The libp2p ecosystem contains at least one module for each of these building blocks. This way, the user should install and import the modules that are relevant for their requirements. Moreover, thanks to the existing interfaces it is easy to create a libp2p compatible module and use it.
36
+
The libp2p ecosystem contains at least one module for each of these subsystems. This way, the user should install and import the modules that are relevant for their requirements. Moreover, thanks to the existing interfaces it is easy to create a libp2p compatible module and use it.
37
37
38
38
After selecting the modules to use, it is also possible to configure each one according to your needs.
39
39
40
-
Bear in mind that only a **transport** is required, being all the other building blocks optional.
40
+
Bear in mind that only a **transport** is required, being all the other subsystems optional.
41
41
42
42
### Transport
43
43
@@ -62,7 +62,7 @@ If you want to know more about libp2p transports, you should read the following
62
62
63
63
> Libp2p peers will need to communicate with each other through several protocols during their life. Stream multiplexing allows multiple independent logical streams to share a common underlying transport medium, instead of creating a new connection with the same peer per needed protocol.
@@ -110,7 +110,7 @@ If you want to know more about libp2p peer discovery, you should read the follow
110
110
111
111
> Content routing provides a way to find where content lives in the network. It works in two steps: 1) Peers provide (announce) to the network that they are holders of specific content and 2) Peers issue queries to find where that content lives. A Content Routing mechanism could be as complex as a DHT or as simple as a registry somewhere in the network.
@@ -125,7 +125,7 @@ If you want to know more about libp2p content routing, you should read the follo
125
125
126
126
> Peer Routing offers a way to find other peers in the network by issuing queries using a Peer Routing algorithm, which may be iterative or recursive. If the algorithm is unable to find the target peer, it will return the peers that are "closest" to the target peer, using a distance metric defined by the algorithm.
@@ -142,7 +142,7 @@ If you want to know more about libp2p peer routing, you should read the followin
142
142
143
143
The DHT implementation currently available is [libp2p/js-libp2p-kad-dht](https://github.com/libp2p/js-libp2p-kad-dht). This implementation is largely based on the Kademlia whitepaper, augmented with notions from S/Kademlia, Coral and mainlineDHT.
144
144
145
-
If this DHT implementation does not fulfill your needs, we recommend that you create a **Peer Routing**or **Content Routing** module, according to your needs. The reason behind this recommendation is that we aim to move the DHT implementation to the Peer Routing and Content Routing modules.
145
+
If this DHT implementation does not fulfill your needs and you want to create or use your own implementation, please get in touch with us through a github issue. We plan to work on improving the ability to bring your own DHT in a future release.
146
146
147
147
If you want to know more about libp2p DHT, you should read the following content:
148
148
@@ -153,7 +153,7 @@ If you want to know more about libp2p DHT, you should read the following content
153
153
154
154
> Publish/Subscribe is a system where peers congregate around topics they are interested in. Peers interested in a topic are said to be subscribed to that topic and should receive the data published on it from other peers.
Moreover, the majority of the modules can be customized via option parameters. This way, it is also possible to provide this options through a config object. This config object should have the property name of each building block to configure, the same way as the modules specification.
185
+
Moreover, the majority of the modules can be customized via option parameters. This way, it is also possible to provide this options through a `config` object. This config object should have the property name of each building block to configure, the same way as the modules specification.
186
186
187
-
**Example:**
187
+
Besides the `modules` and `config`, libp2p allows other internal options and configurations:
188
+
-`datastore`: an instance of [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore/) modules.
189
+
- This is used in modules such as the DHT. If it is not provided, `js-libp2p` will use an in memory datastore.
190
+
-`peerInfo`: a previously created instance of [libp2p/js-peer-info](https://github.com/libp2p/js-peer-info).
191
+
- This is particularly useful if you want to reuse the same `peer-id`, as well as for modules like `libp2p-delegated-content-routing`, which need a `peer-id` in their instantiation.
autoDial:true, // Auto connect to discovered peers (limited by ConnectionManager minPeers)
236
-
mdns: { // mdns options
237
-
interval:1000, // ms
249
+
// The `tag` property will be searched when creating the instance of your Peer Discovery service.
250
+
// The associated object, will be passed to the service when it is instantiated.
251
+
[MulticastDNS.tag]: {
252
+
interval:1000,
238
253
enabled:true
239
254
}
240
255
// .. other discovery module options.
241
-
},
242
-
// relay: { // Circuit Relay options (this config is part of libp2p core configurations)
243
-
// enabled: true,
244
-
// hop: {
245
-
// enabled: false,
246
-
// active: false
247
-
// }
248
-
// },
249
-
dht: {
256
+
}
257
+
}
258
+
})
259
+
```
260
+
261
+
**3) Customizing Pubsub**
262
+
263
+
```js
264
+
constLibp2p=require('libp2p')
265
+
constTCP=require('libp2p-tcp')
266
+
constMPLEX=require('libp2p-mplex')
267
+
constSECIO=require('libp2p-secio')
268
+
constGossipSub=require('libp2p-gossipsub')
269
+
270
+
constnode=awaitLibp2p.create({
271
+
modules: {
272
+
transport: [TCP],
273
+
streamMuxer: [MPLEX],
274
+
connEncryption: [SECIO],
275
+
pubsub: GossipSub
276
+
},
277
+
config: {
278
+
pubsub: { // The pubsub options (and defaults) can be found in the pubsub router documentation
279
+
enabled:true,
280
+
emitSelf:true, // whether the node should emit to self on publish
281
+
signMessages:true, // if messages should be signed
282
+
strictSigning:true// if message signing should be required
283
+
}
284
+
}
285
+
})
286
+
```
287
+
288
+
**4) Customizing DHT**
289
+
290
+
```js
291
+
constLibp2p=require('libp2p')
292
+
constTCP=require('libp2p-tcp')
293
+
constMPLEX=require('libp2p-mplex')
294
+
constSECIO=require('libp2p-secio')
295
+
constDHT=require('libp2p-kad-dht')
296
+
297
+
constnode=awaitLibp2p.create({
298
+
modules: {
299
+
transport: [TCP],
300
+
streamMuxer: [MPLEX],
301
+
connEncryption: [SECIO],
302
+
dht:DHT
303
+
},
304
+
config: {
305
+
dht: { // The DHT options (and defaults) can be found in its documentation
250
306
kBucketSize:20,
251
307
enabled:true,
252
308
randomWalk: {
253
309
enabled:true, // Allows to disable discovery (enabled by default)
254
310
interval:300e3,
255
311
timeout:10e3
256
312
}
257
-
},
258
-
pubsub: {
259
-
enabled:true,
260
-
emitSelf:true, // whether the node should emit to self on publish, in the event of the topic being subscribed
261
-
signMessages:true, // if messages should be signed
262
-
strictSigning:true// if message signing should be required
263
313
}
264
314
}
265
315
})
266
316
```
267
317
268
-
Besides the `modules` and `config`, libp2p allows other internal options and configurations:
318
+
**5) Setup with Content and Peer Routing**
269
319
270
-
-`datastore`: an instance of [ipfs/interface-datastore](https://github.com/ipfs/interface-datastore/) modules.
271
-
- This is used in modules such as the DHT. If it is not provided, `js-libp2p` will use an in memory datastore.
272
-
-`peerInfo`: a previously created instance of [libp2p/js-peer-info](https://github.com/libp2p/js-peer-info).
273
-
- This is particularly useful if you want to reuse the same `peer-id`, as well as for modules like `libp2p-delegated-content-routing`, which need a `peer-id` in their instantiation.
0 commit comments