Skip to content

Commit

Permalink
fix: maximum call stack size with duplicate webrtc addresses (#2980)
Browse files Browse the repository at this point in the history
Ignore other instances of WebRTCPeerListener when getting listen addresses.

Fixes #2539

---------

Co-authored-by: achingbrain <[email protected]>
  • Loading branch information
dozyio and achingbrain authored Feb 21, 2025
1 parent 7718d02 commit d98cc46
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions packages/integration-tests/test/webrtc-private-to-private.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-env mocha */
/* eslint max-nested-callbacks: ['error', 6] */

import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import { plaintext } from '@libp2p/plaintext'
import { webRTC } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import { WebRTC } from '@multiformats/multiaddr-matcher'
import { expect } from 'aegir/chai'
import { createLibp2p } from 'libp2p'
import type { Libp2p } from '@libp2p/interface'

describe('webrtc private-to-private', () => {
let local: Libp2p

afterEach(async () => {
await local?.stop()
})

it('should listen on two webrtc addresses', async () => {
local = await createLibp2p({
addresses: {
listen: [
`${process.env.RELAY_MULTIADDR}/p2p-circuit`,
// this is a misconfiguration, it's only necessary to specify this
// once as the WebRTC transport is really just a protocol handler so
// in effect it will always bind to all addresses
'/webrtc',
'/webrtc'
]
},
transports: [
circuitRelayTransport(),
webSockets(),
webRTC()
],
streamMuxers: [
yamux()
],
connectionEncrypters: [
plaintext()
],
connectionGater: {
denyDialMultiaddr: () => false
},
services: {
identify: identify()
}
})

// two because the relay listens on two TCP addresses so it binds to both
expect(local.getMultiaddrs().filter(WebRTC.exactMatch)).to.have.lengthOf(2)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class WebRTCPeerListener extends TypedEventEmitter<ListenerEvents> implem
getAddrs (): Multiaddr[] {
return this.transportManager
.getListeners()
.filter(l => l !== this)
.filter(l => !(l instanceof WebRTCPeerListener))
.map(l => l.getAddrs()
.filter(ma => Circuit.exactMatch(ma))
.map(ma => {
Expand Down

0 comments on commit d98cc46

Please sign in to comment.