From c05c1af111152be48dbf38ed5a106e41b616d1db Mon Sep 17 00:00:00 2001 From: dmitriy ryajov Date: Sat, 25 Feb 2017 23:41:14 -0800 Subject: [PATCH] feat: adding circuit addresses --- src/index.js | 18 ++++++++++++++++-- test/index.spec.js | 18 +++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 9153927..daf5f5a 100644 --- a/src/index.js +++ b/src/index.js @@ -51,9 +51,22 @@ const Reliable = or( UTP ) -const IPFS = or( +let _IPFS = or( and(Reliable, base('ipfs')), - WebRTCStar + WebRTCStar, + base('ipfs') +) + +const Circuit = or( + and(_IPFS, base('p2p-circuit'), _IPFS), + and(_IPFS, base('p2p-circuit')), + and(base('p2p-circuit'), _IPFS), + base('p2p-circuit') +) + +const IPFS = or( + and(_IPFS, Circuit), + _IPFS ) exports.DNS = DNS @@ -69,6 +82,7 @@ exports.WebSocketsSecure = WebSocketsSecure exports.WebRTCStar = WebRTCStar exports.WebRTCDirect = WebRTCDirect exports.Reliable = Reliable +exports.Circuit = Circuit exports.IPFS = IPFS /* diff --git a/test/index.spec.js b/test/index.spec.js index fecd3ed..9fa206c 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -92,12 +92,24 @@ describe('multiaddr validation', function () { '/ip6/::/ip4/0.0.0.0/udp/1234/wss' ] + const goodCircuit = [ + '/p2p-circuit', + '/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', + '/p2p-circuit/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', + '/p2p-circuit/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/p2p-circuit/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + ] + const goodIPFS = [ '/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj', '/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', - '/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4' + '/ip4/1.2.3.4/tcp/3456/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4', + '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit', + '/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4/p2p-circuit/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj' ] + goodIPFS.concat(goodCircuit) + function assertMatches (p) { const tests = Array.from(arguments).slice(1) tests.forEach(function (test) { @@ -166,6 +178,10 @@ describe('multiaddr validation', function () { assertMismatches(mafmt.WebRTCDirect, goodIP, goodUDP, badWS) }) + it('Circuit validation', function () { + assertMatches(mafmt.Circuit, goodCircuit) + }) + it('IPFS validation', function () { assertMatches(mafmt.IPFS, goodIPFS) })