From b48838583e69f6b1e39691e7a0c9097a26c8df2a Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Mon, 31 Jul 2017 10:45:18 -0700 Subject: [PATCH 1/4] feat: add TCP and WS filtering with /ipfs fragment --- src/index.js | 28 ++++++++++++++++++++++++++ test/index.spec.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/src/index.js b/src/index.js index 7062fc1..5840a09 100644 --- a/src/index.js +++ b/src/index.js @@ -18,21 +18,45 @@ const TCP = and(IP, base('tcp')) const UDP = and(IP, base('udp')) const UTP = and(UDP, base('utp')) +const TCP_IPFS = or( + and(TCP, base('ipfs')), + TCP +) + const DNS = or( and(_DNS, base('tcp')), _DNS ) +const DNS_IPFS = or( + and(DNS, base('ipfs')), + DNS +) + const WebSockets = or( and(TCP, base('ws')), and(DNS, base('ws')) ) +const WebSocketsIPFS = or( + and(WebSockets, base('ipfs')), + and(TCP_IPFS, base('ws')), + and(DNS_IPFS, base('ws')), + WebSockets +) + const WebSocketsSecure = or( and(TCP, base('wss')), and(DNS, base('wss')) ) +const WebSocketsSecureIPFS = or( + and(WebSocketsSecure, base('ipfs')), + and(TCP_IPFS, base('wss')), + and(DNS_IPFS, base('wss')), + WebSocketsSecure +) + const HTTP = or( and(TCP, base('http')), and(DNS), @@ -93,15 +117,19 @@ const IPFS = or( ) exports.DNS = DNS +exports.DNS_IPFS = DNS_IPFS exports.DNS4 = DNS4 exports.DNS6 = DNS6 exports.IP = IP exports.TCP = TCP +exports.TCP_IPFS = TCP_IPFS exports.UDP = UDP exports.UTP = UTP exports.HTTP = HTTP exports.WebSockets = WebSockets +exports.WebSocketsIPFS = WebSocketsIPFS exports.WebSocketsSecure = WebSocketsSecure +exports.WebSocketsSecureIPFS = WebSocketsSecureIPFS exports.WebSocketsStar = WebSocketsStar exports.WebRTCStar = WebRTCStar exports.WebRTCDirect = WebRTCDirect diff --git a/test/index.spec.js b/test/index.spec.js index a52d9df..fd2e838 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -20,6 +20,20 @@ describe('multiaddr validation', function () { '/ip4/127.0.0.1' ] + const goodDnsIPFS = [ + '/dns/ipfs.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns4/ipfs.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns4/libp2p.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns6/protocol.ai/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns4/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns6/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + + const badDnsIPFS = [ + '/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + const goodIP = [ '/ip4/0.0.0.0', '/ip6/fc00::' @@ -40,6 +54,11 @@ describe('multiaddr validation', function () { '/ip6/fc00::/udp/5523/tcp/9543' ] + const goodTcpIPFS = [ + '/ip4/0.0.7.6/tcp/1234/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/tcp/0/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + const goodUDP = [ '/ip4/0.0.7.6/udp/1234', '/ip6/::/udp/0' @@ -72,6 +91,18 @@ describe('multiaddr validation', function () { '/ip6/::/tcp/0/wss' ] + const goodWsIPFS = [ + '/dns/ipfs.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/tcp/0/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + + const goodWssIPFS = [ + '/dns/ipfs.io/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip4/1.2.3.4/tcp/3456/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/tcp/0/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + const goodWebRTCStar = [ '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/dns/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', @@ -151,6 +182,11 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.DNS, badDNS, badIP, goodTCP) }) + it('DNS IPFS validation', function () { + assertMatches(mafmt.DNS_IPFS, goodDnsIPFS) + assertMismatches(mafmt.DNS_IPFS, badDnsIPFS, badDNS, badIP, goodTCP) + }) + it('IP validation', function () { assertMatches(mafmt.IP, goodIP) assertMismatches(mafmt.IP, badIP, goodTCP) @@ -161,6 +197,10 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.TCP, badTCP, goodIP) }) + it('TCP IPFS validation', function () { + assertMatches(mafmt.TCP_IPFS, goodTcpIPFS) + }) + it('UDP validation', function () { assertMatches(mafmt.UDP, goodUDP) assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP) @@ -186,6 +226,16 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.WebSocketsSecure, goodIP, badWSS, goodUDP, badWS) }) + it('WebSockets IPFS validation', function () { + assertMatches(mafmt.WebSocketsIPFS, goodWsIPFS) + assertMismatches(mafmt.WebSocketsIPFS, goodIP, goodUDP, badWS) + }) + + it('WebSocketsSecure IPFS validation', function () { + assertMatches(mafmt.WebSocketsSecureIPFS, goodWssIPFS) + assertMismatches(mafmt.WebSocketsIPFS, goodIP, goodUDP, badWSS) + }) + it('WebSocketsStar validation', function () { assertMatches(mafmt.WebSocketsStar, goodWebSocketsStar) assertMismatches(mafmt.WebSocketsStar, goodIP, goodUDP, badWS) From 0508384bd1580a7f14b05598e529baa9f559dbf6 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 29 Aug 2017 12:32:01 -0600 Subject: [PATCH 2/4] Revert "feat: add TCP and WS filtering with /ipfs fragment" This reverts commit 1af9badd7431800e5eb5d2326ddf255851a90cfa. --- src/index.js | 27 ------------------------- test/index.spec.js | 50 ---------------------------------------------- 2 files changed, 77 deletions(-) diff --git a/src/index.js b/src/index.js index 5840a09..784c693 100644 --- a/src/index.js +++ b/src/index.js @@ -18,45 +18,21 @@ const TCP = and(IP, base('tcp')) const UDP = and(IP, base('udp')) const UTP = and(UDP, base('utp')) -const TCP_IPFS = or( - and(TCP, base('ipfs')), - TCP -) - const DNS = or( and(_DNS, base('tcp')), _DNS ) -const DNS_IPFS = or( - and(DNS, base('ipfs')), - DNS -) - const WebSockets = or( and(TCP, base('ws')), and(DNS, base('ws')) ) -const WebSocketsIPFS = or( - and(WebSockets, base('ipfs')), - and(TCP_IPFS, base('ws')), - and(DNS_IPFS, base('ws')), - WebSockets -) - const WebSocketsSecure = or( and(TCP, base('wss')), and(DNS, base('wss')) ) -const WebSocketsSecureIPFS = or( - and(WebSocketsSecure, base('ipfs')), - and(TCP_IPFS, base('wss')), - and(DNS_IPFS, base('wss')), - WebSocketsSecure -) - const HTTP = or( and(TCP, base('http')), and(DNS), @@ -117,17 +93,14 @@ const IPFS = or( ) exports.DNS = DNS -exports.DNS_IPFS = DNS_IPFS exports.DNS4 = DNS4 exports.DNS6 = DNS6 exports.IP = IP exports.TCP = TCP -exports.TCP_IPFS = TCP_IPFS exports.UDP = UDP exports.UTP = UTP exports.HTTP = HTTP exports.WebSockets = WebSockets -exports.WebSocketsIPFS = WebSocketsIPFS exports.WebSocketsSecure = WebSocketsSecure exports.WebSocketsSecureIPFS = WebSocketsSecureIPFS exports.WebSocketsStar = WebSocketsStar diff --git a/test/index.spec.js b/test/index.spec.js index fd2e838..a52d9df 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -20,20 +20,6 @@ describe('multiaddr validation', function () { '/ip4/127.0.0.1' ] - const goodDnsIPFS = [ - '/dns/ipfs.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/dns4/ipfs.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/dns4/libp2p.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/dns6/protocol.ai/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/dns4/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/dns6/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/dns/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' - ] - - const badDnsIPFS = [ - '/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' - ] - const goodIP = [ '/ip4/0.0.0.0', '/ip6/fc00::' @@ -54,11 +40,6 @@ describe('multiaddr validation', function () { '/ip6/fc00::/udp/5523/tcp/9543' ] - const goodTcpIPFS = [ - '/ip4/0.0.7.6/tcp/1234/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/ip6/::/tcp/0/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' - ] - const goodUDP = [ '/ip4/0.0.7.6/udp/1234', '/ip6/::/udp/0' @@ -91,18 +72,6 @@ describe('multiaddr validation', function () { '/ip6/::/tcp/0/wss' ] - const goodWsIPFS = [ - '/dns/ipfs.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/ip6/::/tcp/0/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' - ] - - const goodWssIPFS = [ - '/dns/ipfs.io/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/ip4/1.2.3.4/tcp/3456/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/ip6/::/tcp/0/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' - ] - const goodWebRTCStar = [ '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/dns/ipfs.io/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', @@ -182,11 +151,6 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.DNS, badDNS, badIP, goodTCP) }) - it('DNS IPFS validation', function () { - assertMatches(mafmt.DNS_IPFS, goodDnsIPFS) - assertMismatches(mafmt.DNS_IPFS, badDnsIPFS, badDNS, badIP, goodTCP) - }) - it('IP validation', function () { assertMatches(mafmt.IP, goodIP) assertMismatches(mafmt.IP, badIP, goodTCP) @@ -197,10 +161,6 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.TCP, badTCP, goodIP) }) - it('TCP IPFS validation', function () { - assertMatches(mafmt.TCP_IPFS, goodTcpIPFS) - }) - it('UDP validation', function () { assertMatches(mafmt.UDP, goodUDP) assertMismatches(mafmt.UDP, badUDP, goodIP, goodTCP, goodUTP) @@ -226,16 +186,6 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.WebSocketsSecure, goodIP, badWSS, goodUDP, badWS) }) - it('WebSockets IPFS validation', function () { - assertMatches(mafmt.WebSocketsIPFS, goodWsIPFS) - assertMismatches(mafmt.WebSocketsIPFS, goodIP, goodUDP, badWS) - }) - - it('WebSocketsSecure IPFS validation', function () { - assertMatches(mafmt.WebSocketsSecureIPFS, goodWssIPFS) - assertMismatches(mafmt.WebSocketsIPFS, goodIP, goodUDP, badWSS) - }) - it('WebSocketsStar validation', function () { assertMatches(mafmt.WebSocketsStar, goodWebSocketsStar) assertMismatches(mafmt.WebSocketsStar, goodIP, goodUDP, badWS) From b1e01b97ce89a3007ca2478d6be8dde1383c3271 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Tue, 29 Aug 2017 16:35:46 -0600 Subject: [PATCH 3/4] feat: allow /ipfs to come as part of multiaddrs --- src/index.js | 52 +++++++++++++++++++++++++++++++++----------- test/index.spec.js | 54 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 22 deletions(-) diff --git a/src/index.js b/src/index.js index 784c693..c7af5e5 100644 --- a/src/index.js +++ b/src/index.js @@ -14,25 +14,55 @@ const _DNS = or( ) const IP = or(base('ip4'), base('ip6')) -const TCP = and(IP, base('tcp')) -const UDP = and(IP, base('udp')) -const UTP = and(UDP, base('utp')) -const DNS = or( +const _UDP = and(IP, base('udp')) +const UDP = or( + and(_UDP, base('ipfs')), + _UDP +) + +const _UTP = and(UDP, base('utp')) +const UTP = or( + and(_UTP, base('ipfs')), + _UTP +) + +const _TCP = and(IP, base('tcp')) +const TCP = or( + and(_TCP, base('ipfs')), + _TCP +) + +const __DNS = or( and(_DNS, base('tcp')), _DNS ) -const WebSockets = or( +const DNS = or( + and(__DNS, base('ipfs')), + __DNS +) + +const _WebSockets = or( and(TCP, base('ws')), and(DNS, base('ws')) ) -const WebSocketsSecure = or( +const WebSockets = or( + and(_WebSockets, base('ipfs')), + _WebSockets +) + +const _WebSocketsSecure = or( and(TCP, base('wss')), and(DNS, base('wss')) ) +const WebSocketsSecure = or( + and(_WebSocketsSecure, base('ipfs')), + _WebSocketsSecure +) + const HTTP = or( and(TCP, base('http')), and(DNS), @@ -40,8 +70,8 @@ const HTTP = or( ) const WebRTCStar = or( - and(WebSockets, base('p2p-webrtc-star'), base('ipfs')), - and(WebSocketsSecure, base('p2p-webrtc-star'), base('ipfs')) + and(_WebSockets, base('p2p-webrtc-star'), base('ipfs')), + and(_WebSocketsSecure, base('p2p-webrtc-star'), base('ipfs')) ) const WebSocketsStar = or( @@ -63,8 +93,7 @@ const Reliable = or( ) let _IPFS = or( - and(Reliable, base('ipfs')), - WebRTCStar, + Reliable, base('ipfs') ) @@ -72,8 +101,6 @@ const _Circuit = or( and(_IPFS, base('p2p-circuit'), _IPFS), and(_IPFS, base('p2p-circuit')), and(base('p2p-circuit'), _IPFS), - and(Reliable, base('p2p-circuit')), - and(base('p2p-circuit'), Reliable), base('p2p-circuit') ) @@ -102,7 +129,6 @@ exports.UTP = UTP exports.HTTP = HTTP exports.WebSockets = WebSockets exports.WebSocketsSecure = WebSocketsSecure -exports.WebSocketsSecureIPFS = WebSocketsSecureIPFS exports.WebSocketsStar = WebSocketsStar exports.WebRTCStar = WebRTCStar exports.WebRTCDirect = WebRTCDirect diff --git a/test/index.spec.js b/test/index.spec.js index a52d9df..ff7d3d8 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -20,6 +20,20 @@ describe('multiaddr validation', function () { '/ip4/127.0.0.1' ] + const goodDnsIPFS = [ + '/dns/ipfs.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns4/ipfs.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns4/libp2p.io/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns6/protocol.ai/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns4/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns6/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/dns/protocol.ai/tcp/80/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + + const badDnsIPFS = [ + '/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + const goodIP = [ '/ip4/0.0.0.0', '/ip6/fc00::' @@ -32,7 +46,9 @@ describe('multiaddr validation', function () { const goodTCP = [ '/ip4/0.0.7.6/tcp/1234', - '/ip6/::/tcp/0' + '/ip6/::/tcp/0', + '/ip4/0.0.7.6/tcp/1234/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/tcp/0/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' ] const badTCP = [ @@ -42,7 +58,9 @@ describe('multiaddr validation', function () { const goodUDP = [ '/ip4/0.0.7.6/udp/1234', - '/ip6/::/udp/0' + '/ip6/::/udp/0', + '/ip4/0.0.7.6/udp/1234/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/udp/0/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' ] const badUDP = [ @@ -52,7 +70,9 @@ describe('multiaddr validation', function () { const goodUTP = [ '/ip4/1.2.3.4/udp/3456/utp', - '/ip6/::/udp/0/utp' + '/ip6/::/udp/0/utp', + '/ip4/1.2.3.4/udp/3456/utp/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/udp/0/utp/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' ] const badUTP = [ @@ -63,13 +83,19 @@ describe('multiaddr validation', function () { const goodWS = [ '/dns/ipfs.io/ws', '/ip4/1.2.3.4/tcp/3456/ws', - '/ip6/::/tcp/0/ws' + '/ip6/::/tcp/0/ws', + '/dns/ipfs.io/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/tcp/0/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' ] const goodWSS = [ '/dns/ipfs.io/wss', '/ip4/1.2.3.4/tcp/3456/wss', - '/ip6/::/tcp/0/wss' + '/ip6/::/tcp/0/wss', + '/dns/ipfs.io/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip4/1.2.3.4/tcp/3456/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip6/::/tcp/0/wss/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' ] const goodWebRTCStar = [ @@ -104,7 +130,9 @@ describe('multiaddr validation', function () { '/p2p-circuit', '/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', '/p2p-circuit/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', - '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + // TODO: figure out how to make circuit addrs and /p2p-webrtc-star work together + // since they don't add to tuples when used together + // '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/p2p-circuit/ip4/127.0.0.1/tcp/4002/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA', '/p2p-circuit/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA', @@ -121,12 +149,15 @@ describe('multiaddr validation', function () { ] const goodIPFS = [ + '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', - '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + // TODO: figure out how to make circuit addrs and /p2p-webrtc-star work together + // since they don't add to tuples when used together + // '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit', '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj' - ].concat(goodCircuit) + ] function assertMatches (p) { const tests = Array.from(arguments).slice(1) @@ -151,6 +182,11 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.DNS, badDNS, badIP, goodTCP) }) + it('DNS IPFS validation', function () { + assertMatches(mafmt.DNS, goodDnsIPFS) + assertMismatches(mafmt.DNS, badDnsIPFS, badDNS, badIP, goodTCP) + }) + it('IP validation', function () { assertMatches(mafmt.IP, goodIP) assertMismatches(mafmt.IP, badIP, goodTCP) @@ -207,6 +243,6 @@ describe('multiaddr validation', function () { }) it('IPFS validation', function () { - assertMatches(mafmt.IPFS, goodIPFS) + assertMatches(mafmt.IPFS, goodIPFS, goodCircuit) }) }) From 78bbd07684b02acb995113e7073d4c8f459abeb7 Mon Sep 17 00:00:00 2001 From: Dmitriy Ryajov Date: Sun, 3 Sep 2017 18:46:30 -0600 Subject: [PATCH 4/4] wip --- test/index.spec.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/test/index.spec.js b/test/index.spec.js index ff7d3d8..c9e7c38 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -130,9 +130,7 @@ describe('multiaddr validation', function () { '/p2p-circuit', '/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', '/p2p-circuit/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', - // TODO: figure out how to make circuit addrs and /p2p-webrtc-star work together - // since they don't add to tuples when used together - // '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/p2p-circuit/ip4/127.0.0.1/tcp/4002/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA', '/p2p-circuit/ipfs/QmddWMcQX6orJGHpETYMyPgXrCXCtYANMFVDCvhKoDwLqA', @@ -151,9 +149,7 @@ describe('multiaddr validation', function () { const goodIPFS = [ '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', - // TODO: figure out how to make circuit addrs and /p2p-webrtc-star work together - // since they don't add to tuples when used together - // '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ip4/1.2.3.4/tcp/3456/ws/p2p-webrtc-star/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit', '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj'