From f3d0430529d54f661668827ce9cda82e9bf72546 Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Wed, 23 Oct 2024 16:53:09 +0100 Subject: [PATCH] deps: update to latest circuit relay transport (#183) Updates examples to use the latest version --- examples/js-libp2p-example-browser-pubsub/index.js | 9 ++++----- .../js-libp2p-example-browser-pubsub/package.json | 2 +- examples/js-libp2p-example-circuit-relay/README.md | 13 ++++++++----- .../js-libp2p-example-circuit-relay/listener.js | 9 ++++++--- .../js-libp2p-example-circuit-relay/package.json | 2 +- .../src/index.html | 4 ++-- .../test/index.spec.js | 11 +++++++---- .../package.json | 2 +- .../index.js | 5 ++--- .../package.json | 2 +- 10 files changed, 33 insertions(+), 26 deletions(-) diff --git a/examples/js-libp2p-example-browser-pubsub/index.js b/examples/js-libp2p-example-browser-pubsub/index.js index d458897..a62499f 100644 --- a/examples/js-libp2p-example-browser-pubsub/index.js +++ b/examples/js-libp2p-example-browser-pubsub/index.js @@ -38,6 +38,9 @@ const clean = (line) => line.replaceAll('\n', '') const libp2p = await createLibp2p({ addresses: { listen: [ + // make a reservation on any discovered relays - this will let other + // peers use the relay to contact us + '/p2p-circuit', // create listeners for incoming WebRTC connection attempts on on all // available Circuit Relay connections '/webrtc' @@ -52,11 +55,7 @@ const libp2p = await createLibp2p({ // support dialing/listening on WebRTC addresses webRTC(), // support dialing/listening on Circuit Relay addresses - circuitRelayTransport({ - // make a reservation on any discovered relays - this will let other - // peers use the relay to contact us - discoverRelays: 1 - }) + circuitRelayTransport() ], // a connection encrypter is necessary to dial the relay connectionEncrypters: [noise()], diff --git a/examples/js-libp2p-example-browser-pubsub/package.json b/examples/js-libp2p-example-browser-pubsub/package.json index 20199a0..da9eda2 100644 --- a/examples/js-libp2p-example-browser-pubsub/package.json +++ b/examples/js-libp2p-example-browser-pubsub/package.json @@ -24,7 +24,7 @@ "@chainsafe/libp2p-gossipsub": "^14.0.0", "@chainsafe/libp2p-noise": "^16.0.0", "@chainsafe/libp2p-yamux": "^7.0.0", - "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/circuit-relay-v2": "^3.0.0", "@libp2p/dcutr": "^2.0.0", "@libp2p/identify": "^3.0.0", "@libp2p/webrtc": "^5.0.0", diff --git a/examples/js-libp2p-example-circuit-relay/README.md b/examples/js-libp2p-example-circuit-relay/README.md index ef99f93..2407362 100644 --- a/examples/js-libp2p-example-circuit-relay/README.md +++ b/examples/js-libp2p-example-circuit-relay/README.md @@ -11,7 +11,7 @@ - [0. Setup the example](#0-setup-the-example) - [1. Set up a relay node](#1-set-up-a-relay-node) -- [2. Set up a listener node with `discoverRelays` Enabled](#2-set-up-a-listener-node-with-discoverrelays-enabled) +- [2. Set up a listener node with a circuit relay address](#2-set-up-a-listener-node-with-a-circuit-relay-address) - [3. Set up a dialer node for testing connectivity](#3-set-up-a-dialer-node-for-testing-connectivity) - [4. What is next?](#4-what-is-next) - [Need help?](#need-help) @@ -88,7 +88,7 @@ Listening on: /ip4/192.168.1.120/tcp/61592/ws/p2p/QmWDn2LY8nannvSWJzruUYoLZ4vV83vfCBwd8DipvdgQc3 ``` -## 2. Set up a listener node with `discoverRelays` Enabled +## 2. Set up a listener node with a circuit relay address 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. @@ -111,11 +111,14 @@ if (!relayAddr) { } const node = await createLibp2p({ + addresses: { + listen: [ + '/p2p-circuit' + ] + }, transports: [ webSockets(), - circuitRelayTransport({ - discoverRelays: 2 - }) + circuitRelayTransport() ], connectionEncrypters: [ noise() diff --git a/examples/js-libp2p-example-circuit-relay/listener.js b/examples/js-libp2p-example-circuit-relay/listener.js index ad9fd4d..6ebe161 100644 --- a/examples/js-libp2p-example-circuit-relay/listener.js +++ b/examples/js-libp2p-example-circuit-relay/listener.js @@ -15,11 +15,14 @@ async function main () { } const node = await createLibp2p({ + addresses: { + listen: [ + '/p2p-circuit' + ] + }, transports: [ webSockets(), - circuitRelayTransport({ - discoverRelays: 2 - }) + circuitRelayTransport() ], connectionEncrypters: [ noise() diff --git a/examples/js-libp2p-example-circuit-relay/package.json b/examples/js-libp2p-example-circuit-relay/package.json index c688827..6e04cac 100644 --- a/examples/js-libp2p-example-circuit-relay/package.json +++ b/examples/js-libp2p-example-circuit-relay/package.json @@ -18,7 +18,7 @@ "dependencies": { "@chainsafe/libp2p-noise": "^16.0.0", "@chainsafe/libp2p-yamux": "^7.0.0", - "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/circuit-relay-v2": "^3.0.0", "@libp2p/identify": "^3.0.0", "@libp2p/websockets": "^9.0.0", "@multiformats/multiaddr": "^12.3.1", diff --git a/examples/js-libp2p-example-delegated-routing/src/index.html b/examples/js-libp2p-example-delegated-routing/src/index.html index 28f2011..0d4e9b1 100644 --- a/examples/js-libp2p-example-delegated-routing/src/index.html +++ b/examples/js-libp2p-example-delegated-routing/src/index.html @@ -16,14 +16,14 @@

Delegated Routing

diff --git a/examples/js-libp2p-example-delegated-routing/test/index.spec.js b/examples/js-libp2p-example-delegated-routing/test/index.spec.js index e6e70da..bb643bb 100644 --- a/examples/js-libp2p-example-delegated-routing/test/index.spec.js +++ b/examples/js-libp2p-example-delegated-routing/test/index.spec.js @@ -27,6 +27,12 @@ async function spawnServer () { multiaddrs: [], protocols: [] } + }, + findPeer: async function () { + return { + id: peerIdFromString('QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN'), + multiaddrs: [] + } } }] }) @@ -69,10 +75,7 @@ test.describe('delegated routing example:', () => { await page.click(findProvidersBtn) const outputLocator = page.locator(output) - await expect(outputLocator).toContainText('[', { - // we depend on an external service and it can take a long time to respond - timeout: 5 * 60_000 - }) + await expect(outputLocator).toContainText('[') }) test('should find peer using the delegate', async ({ page, context }) => { diff --git a/examples/js-libp2p-example-discovery-mechanisms/package.json b/examples/js-libp2p-example-discovery-mechanisms/package.json index 9ffc231..3df3220 100644 --- a/examples/js-libp2p-example-discovery-mechanisms/package.json +++ b/examples/js-libp2p-example-discovery-mechanisms/package.json @@ -20,7 +20,7 @@ "@chainsafe/libp2p-noise": "^16.0.0", "@chainsafe/libp2p-yamux": "^7.0.0", "@libp2p/bootstrap": "^11.0.0", - "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/circuit-relay-v2": "^3.0.0", "@libp2p/identify": "^3.0.0", "@libp2p/kad-dht": "^14.0.0", "@libp2p/mdns": "^11.0.0", diff --git a/examples/js-libp2p-example-webrtc-private-to-private/index.js b/examples/js-libp2p-example-webrtc-private-to-private/index.js index 102f813..1eb1952 100644 --- a/examples/js-libp2p-example-webrtc-private-to-private/index.js +++ b/examples/js-libp2p-example-webrtc-private-to-private/index.js @@ -27,6 +27,7 @@ let chatStream const node = await createLibp2p({ addresses: { listen: [ + '/p2p-circuit', '/webrtc' ] }, @@ -35,9 +36,7 @@ const node = await createLibp2p({ filter: filters.all }), webRTC(), - circuitRelayTransport({ - discoverRelays: 1 - }) + circuitRelayTransport() ], connectionEncrypters: [noise()], streamMuxers: [yamux()], diff --git a/examples/js-libp2p-example-webrtc-private-to-private/package.json b/examples/js-libp2p-example-webrtc-private-to-private/package.json index 0bc385f..c212175 100644 --- a/examples/js-libp2p-example-webrtc-private-to-private/package.json +++ b/examples/js-libp2p-example-webrtc-private-to-private/package.json @@ -14,7 +14,7 @@ "dependencies": { "@chainsafe/libp2p-noise": "^16.0.0", "@chainsafe/libp2p-yamux": "^7.0.0", - "@libp2p/circuit-relay-v2": "^2.0.0", + "@libp2p/circuit-relay-v2": "^3.0.0", "@libp2p/identify": "^3.0.1", "@libp2p/ping": "^2.0.1", "@libp2p/webrtc": "^5.0.0",