diff --git a/examples/auto-relay/README.md b/examples/auto-relay/README.md index 17ed5554..0f88b758 100644 --- a/examples/auto-relay/README.md +++ b/examples/auto-relay/README.md @@ -106,18 +106,15 @@ console.log(`Node started with id ${node.peerId.toB58String()}`) const conn = await node.dial(relayAddr) -// Wait for connection and relay to be bind for the example purpose -await new Promise((resolve) => { - node.peerStore.on('change:multiaddrs', ({ peerId }) => { - // Updated self multiaddrs? - if (peerId.equals(node.peerId)) { - resolve() - } - }) -}) - console.log(`Connected to the HOP relay ${conn.remotePeer.toString()}`) -console.log(`Advertising with a relay address of ${node.multiaddrs[0].toString()}/p2p/${node.peerId.toB58String()}`) + +// Wait for connection and relay to be bind for the example purpose +node.peerStore.on('change:multiaddrs', ({ peerId }) => { + // Updated self multiaddrs? + if (peerId.equals(node.peerId)) { + console.log(`Advertising with a relay address of ${node.multiaddrs[0].toString()}/p2p/${node.peerId.toB58String()}`) + } +}) ``` 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. @@ -189,4 +186,4 @@ As you can see from the output, the remote address of the established connection Before moving into production, there are a few things that you should take into account. -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. +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. \ No newline at end of file