Skip to content

Commit 4ea2f4e

Browse files
authored
fix: make webrtc-direct certhashes optional and require udp (#30)
Browsers cannot make TCP connections so they must be UDP as per the spec. Also certhashes must be optional to allow listening on webrtc-direct addresses.
1 parent 8a72835 commit 4ea2f4e

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,6 @@ export const IP = fmt(_IP)
420420
const _TCP = and(_IP_OR_DOMAIN, literal('tcp'), number())
421421
const _UDP = and(_IP_OR_DOMAIN, literal('udp'), number())
422422

423-
const TCP_OR_UDP = or(_TCP, _UDP)
424-
425423
/**
426424
* Matches TCP addresses.
427425
*
@@ -528,7 +526,7 @@ const _WebSocketsSecure = or(
528526
*/
529527
export const WebSocketsSecure = fmt(_WebSocketsSecure)
530528

531-
const _WebRTCDirect = and(TCP_OR_UDP, literal('webrtc-direct'), certhash(), optional(certhash()), optional(peerId()))
529+
const _WebRTCDirect = and(_UDP, literal('webrtc-direct'), optional(certhash()), optional(certhash()), optional(peerId()))
532530

533531
/**
534532
* Matches WebRTC-direct addresses.

test/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,17 @@ describe('multiaddr matcher', () => {
196196
]
197197

198198
const goodWebRTCDirect = [
199-
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw',
200-
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
201-
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
199+
'/ip4/0.0.0.0/udp/4004/webrtc-direct',
202200
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw',
203201
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
204202
'/ip4/0.0.0.0/udp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
205203
]
206204

207205
const badWebRTCDirect = [
208-
'/ip4/0.0.0.0/udp/4004/webrtc-direct',
209-
'/ip4/0.0.0.0/tcp/4004/webrtc-direct'
206+
'/ip4/0.0.0.0/tcp/4004/webrtc-direct',
207+
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw',
208+
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
209+
'/ip4/0.0.0.0/tcp/4004/webrtc-direct/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
210210
]
211211

212212
const goodWebRTC = [

0 commit comments

Comments
 (0)