feat: adding circuit addresses

This commit is contained in:
dmitriy ryajov 2017-02-25 23:41:14 -08:00
parent 43b401646f
commit c05c1af111
2 changed files with 33 additions and 3 deletions

View File

@ -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
/*

View File

@ -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)
})