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: (BREAKING CHANGE) new libp2p configuration (#1401)
BREAKING CHANGE: libp2p configuration has changed
* old: `libp2p.modules.discovery`
* new: `libp2p.modules.peerDiscovery`
License: MIT
Signed-off-by: David Dias <[email protected]>
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+13-7
Original file line number
Diff line number
Diff line change
@@ -224,22 +224,28 @@ Creates and returns an instance of an IPFS node. Use the `options` argument to s
224
224
225
225
-`pass` (string):A passphrase to encrypt/decrypt your keys.
226
226
227
+
-`relay` (object): Configure circuit relay (see the [circuit relay tutorial](https://github.com/ipfs/js-ipfs/tree/master/examples/circuit-relaying) to learn more).
228
+
-`enabled` (boolean): Enable circuit relay dialer and listener. (Default:`false`)
229
+
-`hop` (object)
230
+
-`enabled` (boolean): Make this node a relay (other nodes can connect *through* it). (Default:`false`)
231
+
-`active` (boolean): Make this an *active* relay node. Active relay nodes will attempt to dial a destination peer even if that peer is not yet connected to the relay. (Default:`false`)
232
+
227
233
-`EXPERIMENTAL` (object): Enable and configure experimental features.
-`sharding` (boolean): Enable directory sharding. Directories that have many child objects will be represented by multiple DAG nodes instead of just one. It can improve lookup performance when a directory has several thousand files or more. (Default:`false`)
230
236
-`dht` (boolean): Enable KadDHT. **This is currently not interopable with`go-ipfs`.**
231
-
-`relay` (object): Configure circuit relay (see the [circuit relay tutorial](https://github.com/ipfs/js-ipfs/tree/master/examples/circuit-relaying) to learn more).
232
-
-`enabled` (boolean): Enable circuit relay dialer and listener. (Default:`false`)
233
-
-`hop` (object)
234
-
-`enabled` (boolean): Make this node a relay (other nodes can connect *through* it). (Default:`false`)
235
-
-`active` (boolean): Make this an *active* relay node. Active relay nodes will attempt to dial a destination peer even if that peer is not yet connected to the relay. (Default:`false`)
236
237
237
238
-`config` (object) Modify the default IPFS node config. Find the Node.js defaults at [`src/core/runtime/config-nodejs.js`](https://github.com/ipfs/js-ipfs/tree/master/src/core/runtime/config-nodejs.js) and the browser defaults at [`src/core/runtime/config-browser.js`](https://github.com/ipfs/js-ipfs/tree/master/src/core/runtime/config-browser.js). This object will be *merged* with the default config; it will not replace it.
238
239
239
240
-`libp2p` (object) add custom modules to the libp2p stack of your node
240
241
-`modules` (object):
241
-
-`transport` (Array<[libp2p.Transport](https://github.com/libp2p/interface-transport)>): An array of additional Libp2p transport instances to use. See [libp2p/interface-transport](https://github.com/libp2p/interface-transport) for details.
242
-
-`discovery` (Array<[libp2p.PeerDiscovery](https://github.com/libp2p/interface-peer-discovery)>): An array of additional Libp2p peer discovery instances to use. See [libp2p/peer-discovery](https://github.com/libp2p/interface-peer-discovery) for details.
242
+
-`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.
243
+
-`peerDiscovery` (Array<[libp2p.PeerDiscovery](https://github.com/libp2p/interface-peer-discovery)>): An array of Libp2p peer discovery classes/instances to use _instead_ of the defaults. See [libp2p/peer-discovery](https://github.com/libp2p/interface-peer-discovery) for details. If passing a class, configuration can be passed using the config section below under the key corresponding to you module's unique `tag` (a static property on the class)
244
+
-`config` (object):
245
+
-`peerDiscovery` (object):
246
+
-`[PeerDiscovery.tag]` (object): configuration for a peer discovery module
247
+
-`enabled` (boolean): whether thismodule is enabled or disabled
248
+
-`[custom config]` (any): other keys are specific to the module
Copy file name to clipboardExpand all lines: examples/circuit-relaying/README.md
+17-23
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ Here is a simple diagram depicting how a typical circuit-relay connection might
22
22
+---------------------+
23
23
```
24
24
25
-
`Node A` tries to connect to `Node B` but, UH-OH! There is a firewall in between that's preventing it from happening. If both `Node A` and `Node B` know about a relay, they can use it to establish the connection.
25
+
`Node A` tries to connect to `Node B` but, UH-OH! There is a firewall in between that's preventing it from happening. If both `Node A` and `Node B` know about a relay, they can use it to establish the connection.
26
26
27
27
This is what it looks like, in simplified steps:
28
28
@@ -60,7 +60,7 @@ There are a couple of caveats and features to be aware of:
60
60
61
61
#### A word on circuit relay addresses
62
62
63
-
A circuit relay address is a [multiaddress](https://multiformats.io/multiaddr/) that describes how to either connect to a peer over a relay (or relays), or allow a peer to announce it is reachable over a particular relay or any relay it is already connected to.
63
+
A circuit relay address is a [multiaddress](https://multiformats.io/multiaddr/) that describes how to either connect to a peer over a relay (or relays), or allow a peer to announce it is reachable over a particular relay or any relay it is already connected to.
64
64
65
65
Circuit relay addresses are very flexible and can describe many different aspects of how to esablish the relayed connection. In its simplest form, it looks something like this:
66
66
@@ -78,8 +78,8 @@ We can take it a step further and encode the same information for the destinatio
If a node is configured with this address, it will use the specified host (`/ip4/127.0.0.1/tcp/65000/ipfs/QmRelay`) as a relay and it will be reachable over this relay.
82
-
- There could multiple addresses of this sort specified in the config, in which case the node will be reachable over all of them.
81
+
If a node is configured with this address, it will use the specified host (`/ip4/127.0.0.1/tcp/65000/ipfs/QmRelay`) as a relay and it will be reachable over this relay.
82
+
- There could multiple addresses of this sort specified in the config, in which case the node will be reachable over all of them.
83
83
- This is useful if, for example, the node is behind a firewall but wants to be reachable from the outside over a specific relay.
84
84
85
85
Other use-cases are also supported by this scheme, e.g. we can have multiple hops (circuit-relay nodes) encoded in the address, something planed for future releases.
@@ -153,7 +153,7 @@ In order to enable the relay functionality in `go-ipfs` we need to edit it's con
153
153
}
154
154
```
155
155
156
-
The two options we're looking for are `DisableRelay` and `EnableRelayHop`. We want the former (`DisableRelay`) set to `false` and the latter (`EnableRelayHop`) to `true`, just like in the example above. That should set our go node as a relay.
156
+
The two options we're looking for are `DisableRelay` and `EnableRelayHop`. We want the former (`DisableRelay`) set to `false` and the latter (`EnableRelayHop`) to `true`, just like in the example above. That should set our go node as a relay.
157
157
158
158
We also need to make sure our go node can be dialed from the browser. For that, we need to enable a transport that both the browser and the go node can communicate over. We will use the web sockets transport, although there are others that can be used, such as `webrtc-star` and `websocket-star`. To enable the transport and set the interface and port we need to edit the `~/.ipfs/config` one more time. Let's find the `Swarm` array and add our desired address there. I picked `/ip4/0.0.0.0/tcp/4004/ws` because it is a port I know is not being used by anything on my machine, but we can also use port `0` so that the OS chooses a random available port for us — either one should work.
159
159
@@ -173,15 +173,11 @@ We need to go through similar steps to enable circuit relay in `jsipfs`. However
173
173
174
174
Just as we did with `go-ipfs`, go ahead and edit `js-ipfs` config file located under `~/.jsipfs/config`. Let's add the following config:
175
175
176
-
(Note that the "EXPERIMENTAL" section might be missing from the config file. In that case, just go ahead and add it)
177
-
178
176
```js
179
-
"EXPERIMENTAL": {
180
-
"relay": {
181
-
"enabled":true,
182
-
"hop": {
183
-
"enabled":true
184
-
}
177
+
"relay": {
178
+
"enabled":true,
179
+
"hop": {
180
+
"enabled":true
185
181
}
186
182
}
187
183
```
@@ -247,7 +243,7 @@ Gateway (readonly) is listening on: /ip4/127.0.0.1/tcp/9090
247
243
Daemon is ready
248
244
```
249
245
250
-
Look out for an address similar to `/ip4/127.0.0.1/tcp/4003/ws/ipfs/Qm...`. Note it down somewhere, and let's move on to the next step.
246
+
Look out for an address similar to `/ip4/127.0.0.1/tcp/4003/ws/ipfs/Qm...`. Note it down somewhere, and let's move on to the next step.
251
247
252
248
### 2. Configure and run the bundled example
253
249
@@ -270,7 +266,7 @@ The bundled example is a simple chat app that uses another cool ipfs feature - [
270
266
271
267
### 3. Connect the two browser nodes to the circuit relay
272
268
273
-
In order for our browser nodes to be able to messages each other, we need to get them connected. But to do that, we need to use a relay - browser nodes can't be connected directly because of lack of socket support.
269
+
In order for our browser nodes to be able to messages each other, we need to get them connected. But to do that, we need to use a relay - browser nodes can't be connected directly because of lack of socket support.
274
270
275
271
Remember the caveat above `Currently a Relay will only work if it already has a connection to the STOP node`? This means that we need to connect our browser nodes to the relay node first.
276
272
@@ -304,21 +300,19 @@ Thats it!
304
300
305
301
### So what just happened?
306
302
307
-
Good question!
303
+
Good question!
308
304
309
305
- We used [js-ipfs](htpps://github.com/ipfs/js-ipfs) running in the browser with circuit relay enabled:
0 commit comments