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
Before moving into the examples, you should run `npm install` and `npm run build` on the top level `js-libp2p` folder, in order to install all the dependencies needed for this example. Once the install finishes, you should move into the example folder with `cd examples/auto-relay`.
22
+
First of all run `npm install` in the example folder. This will install all
23
+
required dependencies and you'll be ready to go.
23
24
24
-
This example comes with 3 main files. A `relay.js` file to be used in the first step, a `listener.js` file to be used in the second step and a `dialer.js` file to be used on the third step. All of these scripts will run their own libp2p node, which will interact with the previous ones. All nodes must be running in order for you to proceed.
25
+
This example comes with 3 main files. A `relay.js` file to be used in the first
26
+
step, a `listener.js` file to be used in the second step and a `dialer.js` file
27
+
to be used on the third step. All of these scripts will run their own libp2p
28
+
node, which will interact with the previous ones. All nodes must be running in
29
+
order for you to proceed.
25
30
26
31
## 1. Set up a relay node
27
32
28
-
In the first step of this example, we need to configure and run a relay node in order for our target node to bind to for accepting inbound connections.
33
+
In the first step of this example, we need to configure and run a relay node in
34
+
order for our target node to bind to for accepting inbound connections.
29
35
30
-
The relay node will need to have its relay subsystem enabled, as well as its HOP capability. It can be configured as follows:
36
+
The relay node will need to have a relay service added which will allow a
37
+
limited number of remote peers to make relay reservations with it.
38
+
39
+
It can be configured as follows:
31
40
32
41
```js
33
42
import { noise } from'@chainsafe/libp2p-noise'
@@ -80,9 +89,11 @@ Listening on:
80
89
81
90
## 2. Set up a listener node with `discoverRelays` Enabled
82
91
83
-
One of the typical use cases for Circuit Relay is nodes behind a NAT or browser nodes due to their inability to expose a public address.
92
+
One of the typical use cases for Circuit Relay is nodes behind a NAT or browser
93
+
nodes due to their inability to expose a public address.
84
94
85
-
For running a libp2p node that automatically discovers available relays, you can see the following:
95
+
For running a libp2p node that automatically discovers available relays, you can
As you can see in the code, we need to provide the relay address, `relayAddr`, as a process argument. This node will dial the provided relay address and automatically bind to it.
143
+
As you can see in the code, we need to provide the relay address, `relayAddr`,
144
+
as a process argument. This node will dial the provided relay address and
145
+
automatically bind to it.
133
146
134
147
You should now run the following to start the node running Auto Relay:
135
148
@@ -145,13 +158,19 @@ Connected to the HOP relay QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3
145
158
Advertising with a relay address of /ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit/p2p/QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
146
159
```
147
160
148
-
Per the address, it is possible to verify that the auto relay node is listening on the circuit relay node address.
161
+
Per the address, it is possible to verify that the auto relay node is listening
162
+
on the circuit relay node address.
149
163
150
-
Instead of dialing this relay manually, you could set up this node with the Bootstrap module and provide it in the bootstrap list. Moreover, you can use other `peer-discovery` modules to discover peers in the network and the node will automatically bind to the relays that support HOP until reaching the maximum number of listeners.
164
+
Instead of dialing this relay manually, you could set up this node with the
165
+
Bootstrap module and provide it in the bootstrap list. Moreover, you can use
166
+
other `peer-discovery` modules to discover peers in the network and the node
167
+
will automatically bind to the relays that support HOP until reaching the
168
+
maximum number of listeners.
151
169
152
170
## 3. Set up a dialer node for testing connectivity
153
171
154
-
Now that you have a relay node and a node bound to that relay, you can test connecting to the auto relay node via the relay.
172
+
Now that you have a relay node and a node bound to that relay, you can test
Connected to the auto relay node via /ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3/p2p-circuit/p2p/QmerrWofKF358JE6gv3z74cEAyL7z1KqhuUoVfGEynqjRm
191
212
```
192
213
193
-
As you can see from the output, the remote address of the established connection uses the relayed connection.
214
+
As you can see from the output, the remote address of the established connection
215
+
uses the relayed connection.
194
216
195
217
## 4. What is next?
196
218
197
-
Before moving into production, there are a few things that you should take into account.
219
+
Before moving into production, there are a few things that you should take into
220
+
account.
198
221
199
-
A relay node should not advertise its private address in a real world scenario, as the node would not be reachable by others. You should provide an array of public addresses in the libp2p `addresses.announce` option. If you are using websockets, bear in mind that due to browser’s security policies you cannot establish unencrypted connection from secure context. The simplest solution is to setup SSL with nginx and proxy to the node and setup a domain name for the certificate.
222
+
A relay node should not advertise its private address in a real world scenario,
223
+
as the node would not be reachable by others. You should provide an array of
224
+
public addresses in the libp2p `addresses.announce` option. If you are using
225
+
websockets, bear in mind that due to browser’s security policies you cannot
226
+
establish unencrypted connection from secure context. The simplest solution is
227
+
to setup SSL with nginx and proxy to the node and setup a domain name for the
228
+
certificate.
200
229
201
230
## License
202
231
@@ -207,4 +236,6 @@ Licensed under either of
207
236
208
237
## Contribution
209
238
210
-
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
239
+
Unless you explicitly state otherwise, any contribution intentionally submitted
240
+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
241
+
be dual licensed as above, without any additional terms or conditions.
0 commit comments