Skip to content

Commit

Permalink
fix!: make circuit relay listen on addresses like other transports (#…
Browse files Browse the repository at this point in the history
…2776)

Refactors the circuit relay transport to behave like other transports

1. Specify the addresses to listen on in the `addresses.listen` config
2. Remove the `discoverRelays` option
3. Remove the transport manager listen call to just listen on configured addresses
4. Emit the `listen` event when listen addresses change like other transports

BREAKING CHANGE: The `discoverRelays` option has been removed, instead add one or more instances of `"/p2p-circuit"` to the libp2p config under the `addresses.listen` key
  • Loading branch information
achingbrain authored Oct 23, 2024
1 parent 5a25d83 commit 3244ed0
Show file tree
Hide file tree
Showing 17 changed files with 479 additions and 453 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ jobs:
strategy:
matrix:
example:
- name: js-libp2p-example-browser-pubsub
repo: https://github.com/libp2p/js-libp2p-example-browser-pubsub.git
deps:
- '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2'
- '@libp2p/dcutr@$PWD/packages/protocol-dcutr'
- '@libp2p/identify@$PWD/packages/protocol-identify'
- '@libp2p/webrtc@$PWD/packages/transport-webrtc'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
# - name: js-libp2p-example-browser-pubsub
# repo: https://github.com/libp2p/js-libp2p-example-browser-pubsub.git
# deps:
# - '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2'
# - '@libp2p/dcutr@$PWD/packages/protocol-dcutr'
# - '@libp2p/identify@$PWD/packages/protocol-identify'
# - '@libp2p/webrtc@$PWD/packages/transport-webrtc'
# - '@libp2p/websockets@$PWD/packages/transport-websockets'
# - 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-chat
repo: https://github.com/libp2p/js-libp2p-example-chat.git
deps:
- '@libp2p/mdns@$PWD/packages/peer-discovery-mdns'
- '@libp2p/tcp@$PWD/packages/transport-tcp'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-circuit-relay
repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git
deps:
- '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2'
- '@libp2p/identify@$PWD/packages/protocol-identify'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
# - name: js-libp2p-example-circuit-relay
# repo: https://github.com/libp2p/js-libp2p-example-circuit-relay.git
# deps:
# - '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2'
# - '@libp2p/identify@$PWD/packages/protocol-identify'
# - '@libp2p/websockets@$PWD/packages/transport-websockets'
# - 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-connection-encryption
repo: https://github.com/libp2p/js-libp2p-example-connection-encryption.git
deps:
Expand All @@ -62,10 +62,10 @@ jobs:
- '@libp2p/tcp@$PWD/packages/transport-tcp'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-delegated-routing
repo: https://github.com/libp2p/js-libp2p-example-delegated-routing.git
deps:
- 'libp2p@$PWD/packages/libp2p'
# - name: js-libp2p-example-delegated-routing
# repo: https://github.com/libp2p/js-libp2p-example-delegated-routing.git
# deps:
# - 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-discovery-mechanisms
repo: https://github.com/libp2p/js-libp2p-example-discovery-mechanisms.git
deps:
Expand Down Expand Up @@ -106,15 +106,15 @@ jobs:
- '@libp2p/tcp@$PWD/packages/transport-tcp'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
- name: js-libp2p-example-webrtc-private-to-private
repo: https://github.com/libp2p/js-libp2p-example-webrtc-private-to-private.git
deps:
- '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2'
- '@libp2p/identify@$PWD/packages/protocol-identify'
- '@libp2p/ping@$PWD/packages/protocol-ping'
- '@libp2p/webrtc@$PWD/packages/transport-webrtc'
- '@libp2p/websockets@$PWD/packages/transport-websockets'
- 'libp2p@$PWD/packages/libp2p'
# - name: js-libp2p-example-webrtc-private-to-private
# repo: https://github.com/libp2p/js-libp2p-example-webrtc-private-to-private.git
# deps:
# - '@libp2p/circuit-relay-v2@$PWD/packages/transport-circuit-relay-v2'
# - '@libp2p/identify@$PWD/packages/protocol-identify'
# - '@libp2p/ping@$PWD/packages/protocol-ping'
# - '@libp2p/webrtc@$PWD/packages/transport-webrtc'
# - '@libp2p/websockets@$PWD/packages/transport-websockets'
# - 'libp2p@$PWD/packages/libp2p'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
Expand Down
20 changes: 13 additions & 7 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,15 @@ import { identify } from '@libp2p/identify'


const node = await createLibp2p({
addresses: {
listen: {
// discover a relay using the routing
'/p2p-circuit'
}
},
transports: [
tcp(),
circuitRelayTransport({ // allows the current node to make and accept relayed connections
discoverRelays: 0, // how many network relays to find
reservationConcurrency: 1 // how many relays to attempt to reserve slots on at once
})
circuitRelayTransport()
],
streamMuxers: [
yamux()
Expand Down Expand Up @@ -499,11 +502,14 @@ import { noise } from '@chainsafe/libp2p-noise'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'

const node = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit'
]
},
transports: [
tcp(),
circuitRelayTransport({
discoverRelays: 1
})
circuitRelayTransport()
],
streamMuxers: [
yamux()
Expand Down
5 changes: 2 additions & 3 deletions doc/migrations/v0.42-v0.43.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ const node = await createLibp2p({
// ... other options
addresses: {
listen: {
'/p2p-circuit', // discover a public relay
'/ip4/123.123.123.123/p2p/QmRelay/p2p-circuit' // optionally configure a static relay
}
},
transports: [
circuitRelayClient({ // enable client portion of relay
discoverRelays: 1 // find this number of network relays (default: 0)
})
circuitRelayClient()
],
relay: circuitRelayServer({ // enable server portion of relay
advertise: {
Expand Down
9 changes: 4 additions & 5 deletions interop/test/fixtures/get-libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ export async function getLibp2p (): Promise<Libp2p<{ ping: PingService }>> {
}
break
case 'webrtc':
options.transports = [webRTC(),
options.transports = [
webRTC(),
webSockets({ filter: filters.all }), // ws needed to connect to relay
circuitRelayTransport({
discoverRelays: 1
}) // needed to use the relay
circuitRelayTransport()
]
options.addresses = {
listen: isDialer ? [] : ['/webrtc']
listen: isDialer ? [] : ['/p2p-circuit', '/webrtc']
}
break
case 'ws':
Expand Down
16 changes: 8 additions & 8 deletions packages/integration-tests/test/circuit-relay-discovery.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ describe('circuit-relay discovery', () => {
;[local, remote] = await Promise.all([
createLibp2p({
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0']
listen: [
'/p2p-circuit'
]
},
transports: [
tcp(),
circuitRelayTransport({
discoverRelays: 1
})
circuitRelayTransport()
],
streamMuxers: [
yamux()
Expand All @@ -117,13 +117,13 @@ describe('circuit-relay discovery', () => {
}),
createLibp2p({
addresses: {
listen: ['/ip4/127.0.0.1/tcp/0']
listen: [
'/p2p-circuit'
]
},
transports: [
tcp(),
circuitRelayTransport({
discoverRelays: 1
})
circuitRelayTransport()
],
streamMuxers: [
yamux()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ describe('circuit-relay discovery', () => {

beforeEach(async () => {
node = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit'
]
},
transports: [
webSockets({
filter: filters.all
}),
circuitRelayTransport({
discoverRelays: 1
}),
circuitRelayTransport(),
webTransport()
],
streamMuxers: [
Expand Down
Loading

0 comments on commit 3244ed0

Please sign in to comment.