Skip to content

Commit b7dbfa0

Browse files
authored
feat: match peer ids in quic addresses (#44)
Also test quic-v1 addresses
1 parent 229b12d commit b7dbfa0

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ export const TCP = fmt(and(_TCP, optional(peerId())))
248248
*/
249249
export const UDP = fmt(_UDP)
250250

251-
const _QUIC = and(_UDP, literal('quic'))
252-
const _QUICV1 = and(_UDP, literal('quic-v1'))
251+
const _QUIC = and(_UDP, literal('quic'), optional(peerId()))
252+
const _QUICV1 = and(_UDP, literal('quic-v1'), optional(peerId()))
253253

254254
const QUIC_V0_OR_V1 = or(_QUIC, _QUICV1)
255255

test/index.spec.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ describe('multiaddr matcher', () => {
8585

8686
const exactQUIC = [
8787
'/ip4/1.2.3.4/udp/1234/quic',
88-
'/ip6/::/udp/1234/quic'
88+
'/ip4/1.2.3.4/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
89+
'/ip6/::/udp/1234/quic',
90+
'/ip6/::/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
8991
]
9092

9193
const goodQUIC = [
@@ -100,6 +102,30 @@ describe('multiaddr matcher', () => {
100102
'/quic'
101103
]
102104

105+
const exactQUICv1 = [
106+
'/ip4/1.2.3.4/udp/1234/quic-v1',
107+
'/ip4/1.2.3.4/udp/1234/quic-v1/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
108+
'/ip6/::/udp/1234/quic-v1',
109+
'/ip6/::/udp/1234/quic-v1/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
110+
]
111+
112+
const goodQUICv1 = [
113+
...exactQUICv1,
114+
'/ip4/1.2.3.4/udp/1234/quic-v1/webtransport/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw',
115+
'/dns/google.com/udp/1234/quic-v1/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
116+
]
117+
118+
const badQUICv1 = [
119+
'/ip4/0.0.0.0/tcp/12345/quic-v1',
120+
'/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic-v1',
121+
'/quic-v1',
122+
'/quic',
123+
'/ip4/1.2.3.4/udp/1234/quic',
124+
'/ip4/1.2.3.4/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64',
125+
'/ip6/::/udp/1234/quic',
126+
'/ip6/::/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64'
127+
]
128+
103129
const exactWS = [
104130
'/dnsaddr/ipfs.io/ws',
105131
'/dns4/ipfs.io/ws',
@@ -382,6 +408,12 @@ describe('multiaddr matcher', () => {
382408
assertMismatches(mafmt.QUIC, badQUIC)
383409
})
384410

411+
it('QUICv1 addresses', () => {
412+
assertMatches(mafmt.QUICV1, goodQUICv1)
413+
assertExactMatches(mafmt.QUICV1, exactQUICv1)
414+
assertMismatches(mafmt.QUICV1, badQUICv1)
415+
})
416+
385417
it('WebSockets addresses', () => {
386418
assertMatches(mafmt.WebSockets, goodWS)
387419
assertExactMatches(mafmt.WebSockets, exactWS)

0 commit comments

Comments
 (0)