Skip to content

Commit

Permalink
deps: update to latest circuit relay transport (#183)
Browse files Browse the repository at this point in the history
Updates examples to use the latest version
  • Loading branch information
achingbrain authored Oct 23, 2024
1 parent 80bdaa7 commit f3d0430
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 26 deletions.
9 changes: 4 additions & 5 deletions examples/js-libp2p-example-browser-pubsub/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()],
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-browser-pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions examples/js-libp2p-example-circuit-relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -111,11 +111,14 @@ if (!relayAddr) {
}

const node = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit'
]
},
transports: [
webSockets(),
circuitRelayTransport({
discoverRelays: 2
})
circuitRelayTransport()
],
connectionEncrypters: [
noise()
Expand Down
9 changes: 6 additions & 3 deletions examples/js-libp2p-example-circuit-relay/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ async function main () {
}

const node = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit'
]
},
transports: [
webSockets(),
circuitRelayTransport({
discoverRelays: 2
})
circuitRelayTransport()
],
connectionEncrypters: [
noise()
Expand Down
2 changes: 1 addition & 1 deletion examples/js-libp2p-example-circuit-relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/js-libp2p-example-delegated-routing/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ <h1>Delegated Routing</h1>
<form id="findProvidersForm">
<label>
Find providers of CID:
<input type="text" value="" id="find-providers-input" />
<input type="text" value="bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354" id="find-providers-input" />
<input type="submit" value="Find Providers" id="find-providers-button" />
</label>
</form>
<form id="findPeerForm">
<label>
Find peer:
<input type="text" value="" id="find-peer-input" />
<input type="text" value="QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN" id="find-peer-input" />
<input type="submit" value="Find PeerInfo" id="find-peer-button" />
</label>
</form>
Expand Down
11 changes: 7 additions & 4 deletions examples/js-libp2p-example-delegated-routing/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ async function spawnServer () {
multiaddrs: [],
protocols: []
}
},
findPeer: async function () {
return {
id: peerIdFromString('QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN'),
multiaddrs: []
}
}
}]
})
Expand Down Expand Up @@ -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 }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions examples/js-libp2p-example-webrtc-private-to-private/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let chatStream
const node = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit',
'/webrtc'
]
},
Expand All @@ -35,9 +36,7 @@ const node = await createLibp2p({
filter: filters.all
}),
webRTC(),
circuitRelayTransport({
discoverRelays: 1
})
circuitRelayTransport()
],
connectionEncrypters: [noise()],
streamMuxers: [yamux()],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f3d0430

Please sign in to comment.