From 54c25f45ad62a80280118e895c9192cf2f1490d2 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 25 Oct 2024 11:57:12 -0500 Subject: [PATCH 1/4] feat: support libp2p.direct multiaddr --- src/index.ts | 3 ++- test/index.spec.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index ca47d9f..6670b49 100644 --- a/src/index.ts +++ b/src/index.ts @@ -309,7 +309,8 @@ export const WebSockets = fmt(_WebSockets) const _WebSocketsSecure = or( and(_WEB, literal('wss'), optional(peerId())), - and(_WEB, literal('tls'), literal('ws'), optional(peerId())) + and(_WEB, literal('tls'), literal('ws'), optional(peerId())), + and(_TCP, literal('tls'), literal('sni'), string(), literal('ws'), optional(peerId())) ) /** diff --git a/test/index.spec.ts b/test/index.spec.ts index a4c5a87..fc62876 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -142,7 +142,19 @@ describe('multiaddr matcher', () => { ] const goodWSS = [ - ...exactWSS + ...exactWSS, + '/ip4/147.75.87.65/tcp/4002/tls/sni/147-75-87-65.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/ws', + '/ip4/147.75.87.65/tcp/4002/tls/sni/147-75-87-65.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT', + '/dns4/147-75-80-75.k51qzi5uqu5dho0o9zm90239gjuacg6q1s69e0l1k5ow6kna869fsyb7ukjpeg.libp2p.direct/tcp/4002/tls/ws', + '/dns4/147-75-80-75.k51qzi5uqu5dho0o9zm90239gjuacg6q1s69e0l1k5ow6kna869fsyb7ukjpeg.libp2p.direct/tcp/4002/tls/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT', + '/dns/147-75-87-65.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws', + '/dns/147-75-87-65.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT', + '/ip6/2604:1380:4601:f600::1/tcp/4002/tls/sni/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/ws', + '/ip6/2604:1380:4601:f600::1/tcp/4002/tls/sni/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT', + '/dns6/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws', + '/dns6/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT', + '/dns/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws', + '/dns/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT' ] const badWS = [ From 7e6f2dc17f15e1f520f123680720e54624f493a7 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 25 Oct 2024 10:46:09 -0700 Subject: [PATCH 2/4] chore: accept pr suggestion Co-authored-by: Alex Potsides --- src/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6670b49..21d4497 100644 --- a/src/index.ts +++ b/src/index.ts @@ -309,8 +309,7 @@ export const WebSockets = fmt(_WebSockets) const _WebSocketsSecure = or( and(_WEB, literal('wss'), optional(peerId())), - and(_WEB, literal('tls'), literal('ws'), optional(peerId())), - and(_TCP, literal('tls'), literal('sni'), string(), literal('ws'), optional(peerId())) + and(_WEB, literal('tls'), optional(literal('sni'), string()), literal('ws'), optional(peerId())) ) /** From 03f062455eaddb5a94065c7e78a59e878e9da9bb Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:10:14 -0500 Subject: [PATCH 3/4] fix: wss pr suggestion --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 21d4497..0a2a920 100644 --- a/src/index.ts +++ b/src/index.ts @@ -309,7 +309,7 @@ export const WebSockets = fmt(_WebSockets) const _WebSocketsSecure = or( and(_WEB, literal('wss'), optional(peerId())), - and(_WEB, literal('tls'), optional(literal('sni'), string()), literal('ws'), optional(peerId())) + and(_WEB, literal('tls'), optional(and(literal('sni'), string())), literal('ws'), optional(peerId())) ) /** From 622fd28e6d748a2110d615545c4e2c3eaa5b2f50 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:10:30 -0500 Subject: [PATCH 4/4] chore: move new wss matches to good exact matches --- test/index.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/index.spec.ts b/test/index.spec.ts index fc62876..475dddc 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -138,11 +138,7 @@ describe('multiaddr matcher', () => { '/dns4/ipfs.io/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', '/dns6/ipfs.io/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', '/ip4/1.2.3.4/tcp/3456/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', - '/ip6/::/tcp/3456/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79' - ] - - const goodWSS = [ - ...exactWSS, + '/ip6/::/tcp/3456/tls/ws/p2p/QmTysQQiTGMdfRsDQp516oZ9bR3FiSCDnicUnqny2q1d79', '/ip4/147.75.87.65/tcp/4002/tls/sni/147-75-87-65.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/ws', '/ip4/147.75.87.65/tcp/4002/tls/sni/147-75-87-65.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT', '/dns4/147-75-80-75.k51qzi5uqu5dho0o9zm90239gjuacg6q1s69e0l1k5ow6kna869fsyb7ukjpeg.libp2p.direct/tcp/4002/tls/ws', @@ -157,6 +153,10 @@ describe('multiaddr matcher', () => { '/dns/2604-1380-4601-f600--1.k51qzi5uqu5dhb03btheentd9nmkaygwm4q3tfrm596s5thf1u87bc7gq0m2ia.libp2p.direct/tcp/4002/tls/ws/p2p/12D3KooWDpp7U7W9Q8feMZPPEpPP5FKXTUakLgnVLbavfjb9mzrT' ] + const goodWSS = [ + ...exactWSS + ] + const badWS = [ '/ip4/0.0.0.0/tcp/12345/udp/2222/ws', '/ip6/::/ip4/0.0.0.0/udp/1234/ws',