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
{{ message }}
This repository was archived by the owner on Feb 12, 2024. It is now read-only.
feat: add libp2p factory config option with example (#1470)
Resolves#1463 and libp2p/js-libp2p#222
This adds the ability to pass a libp2p generator function to the ipfs configuration. This makes it easier for users to add custom modules to libp2p that require some startup time properties, like peerInfo (libp2p/js-libp2p#222).
I have also included an example of how to do this. I think this makes complex libp2p configuration much cleaner and easier to do.
Tests have been added for the old configuration options and the new generator option. I isolated them to avoid spinning up a full ipfs node.
Copy file name to clipboardExpand all lines: README.md
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -320,8 +320,11 @@ Modify the default IPFS node config. This object will be *merged* with the defau
320
320
| Type | Default |
321
321
|------|---------|
322
322
| object |[`libp2p-nodejs.js`](https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/libp2p-nodejs.js) in Node.js, [`libp2p-browser.js`](https://github.com/ipfs/js-ipfs/blob/master/src/core/runtime/libp2p-browser.js) in browsers |
323
+
| function |[`libp2p bundle`](examples/custom-libp2p)|
323
324
324
-
Add custom modules to the libp2p stack of your node.
325
+
The libp2p option allows you to build your libp2p node by configuration, or via a bundle function. If you are looking to just modify the below options, using the object format is the quickest way to get the default features of libp2p. If you need to create a more customized libp2p node, such as with custom transports or peer/content routers that need some of the ipfs data on startup, a custom bundle is a great way to achieve this.
326
+
327
+
You can see the bundle in action in the [custom libp2p example](examples/custom-libp2p).
325
328
326
329
-`modules` (object):
327
330
-`transport` (Array<[libp2p.Transport](https://github.com/libp2p/interface-transport)>): An array of Libp2p transport classes/instances to use _instead_ of the defaults. See [libp2p/interface-transport](https://github.com/libp2p/interface-transport) for details.
This example shows you how to make full use of the ipfs configuration to create a libp2p bundle function. As IPFS applications become more complex, their needs for a custom libp2p bundle also grow. Instead of fighting with configuration options, you can use your own libp2p bundle function to get exactly what you need.
4
+
5
+
## Run this example
6
+
7
+
Running this example should result in metrics being logged out to the console every few seconds.
8
+
9
+
```
10
+
> npm install
11
+
> npm start
12
+
```
13
+
14
+
## Play with the configuration!
15
+
16
+
With the metrics for peers and bandwidth stats being logged out, try playing around with the nodes configuration to see what kind of metrics you can get. How many peers are you getting? What does your bandwidth look like?
17
+
18
+
This is also a good opportunity to explore the various stats that ipfs offers! Not seeing a statistic you think would be useful? We'd love to have you [contribute](https://github.com/ipfs/js-ipfs/blob/master/CONTRIBUTING.md)!
0 commit comments