diff --git a/src/index.ts b/src/index.ts index 7b27ef5..64a541e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -248,8 +248,8 @@ export const TCP = fmt(and(_TCP, optional(peerId()))) */ export const UDP = fmt(_UDP) -const _QUIC = and(_UDP, literal('quic')) -const _QUICV1 = and(_UDP, literal('quic-v1')) +const _QUIC = and(_UDP, literal('quic'), optional(peerId())) +const _QUICV1 = and(_UDP, literal('quic-v1'), optional(peerId())) const QUIC_V0_OR_V1 = or(_QUIC, _QUICV1) diff --git a/test/index.spec.ts b/test/index.spec.ts index 0b7ca70..36db956 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -85,7 +85,9 @@ describe('multiaddr matcher', () => { const exactQUIC = [ '/ip4/1.2.3.4/udp/1234/quic', - '/ip6/::/udp/1234/quic' + '/ip4/1.2.3.4/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', + '/ip6/::/udp/1234/quic', + '/ip6/::/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' ] const goodQUIC = [ @@ -100,6 +102,30 @@ describe('multiaddr matcher', () => { '/quic' ] + const exactQUICv1 = [ + '/ip4/1.2.3.4/udp/1234/quic-v1', + '/ip4/1.2.3.4/udp/1234/quic-v1/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', + '/ip6/::/udp/1234/quic-v1', + '/ip6/::/udp/1234/quic-v1/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' + ] + + const goodQUICv1 = [ + ...exactQUICv1, + '/ip4/1.2.3.4/udp/1234/quic-v1/webtransport/certhash/uEiAeP0OEmBbGVTH5Bhnm3WopwRNSQ0et46xNkn2dIagnGw', + '/dns/google.com/udp/1234/quic-v1/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' + ] + + const badQUICv1 = [ + '/ip4/0.0.0.0/tcp/12345/quic-v1', + '/ip6/1.2.3.4/ip4/0.0.0.0/udp/1234/quic-v1', + '/quic-v1', + '/quic', + '/ip4/1.2.3.4/udp/1234/quic', + '/ip4/1.2.3.4/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64', + '/ip6/::/udp/1234/quic', + '/ip6/::/udp/1234/quic/p2p/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64' + ] + const exactWS = [ '/dnsaddr/ipfs.io/ws', '/dns4/ipfs.io/ws', @@ -382,6 +408,12 @@ describe('multiaddr matcher', () => { assertMismatches(mafmt.QUIC, badQUIC) }) + it('QUICv1 addresses', () => { + assertMatches(mafmt.QUICV1, goodQUICv1) + assertExactMatches(mafmt.QUICV1, exactQUICv1) + assertMismatches(mafmt.QUICV1, badQUICv1) + }) + it('WebSockets addresses', () => { assertMatches(mafmt.WebSockets, goodWS) assertExactMatches(mafmt.WebSockets, exactWS)