mirror of
https://github.com/fluencelabs/js-mafmt
synced 2025-06-06 14:51:26 +00:00
feat: adding circuit addresses
This commit is contained in:
parent
43b401646f
commit
c05c1af111
18
src/index.js
18
src/index.js
@ -51,9 +51,22 @@ const Reliable = or(
|
|||||||
UTP
|
UTP
|
||||||
)
|
)
|
||||||
|
|
||||||
const IPFS = or(
|
let _IPFS = or(
|
||||||
and(Reliable, base('ipfs')),
|
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
|
exports.DNS = DNS
|
||||||
@ -69,6 +82,7 @@ exports.WebSocketsSecure = WebSocketsSecure
|
|||||||
exports.WebRTCStar = WebRTCStar
|
exports.WebRTCStar = WebRTCStar
|
||||||
exports.WebRTCDirect = WebRTCDirect
|
exports.WebRTCDirect = WebRTCDirect
|
||||||
exports.Reliable = Reliable
|
exports.Reliable = Reliable
|
||||||
|
exports.Circuit = Circuit
|
||||||
exports.IPFS = IPFS
|
exports.IPFS = IPFS
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -92,12 +92,24 @@ describe('multiaddr validation', function () {
|
|||||||
'/ip6/::/ip4/0.0.0.0/udp/1234/wss'
|
'/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 = [
|
const goodIPFS = [
|
||||||
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
'/ip4/127.0.0.1/tcp/20008/ws/ipfs/QmUjNmr8TgJCn1Ao7DvMy4cjoZU15b9bwSCBLE3vwXiwgj',
|
||||||
'/libp2p-webrtc-star/ip4/1.2.3.4/tcp/3456/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSoooo4',
|
'/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) {
|
function assertMatches (p) {
|
||||||
const tests = Array.from(arguments).slice(1)
|
const tests = Array.from(arguments).slice(1)
|
||||||
tests.forEach(function (test) {
|
tests.forEach(function (test) {
|
||||||
@ -166,6 +178,10 @@ describe('multiaddr validation', function () {
|
|||||||
assertMismatches(mafmt.WebRTCDirect, goodIP, goodUDP, badWS)
|
assertMismatches(mafmt.WebRTCDirect, goodIP, goodUDP, badWS)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Circuit validation', function () {
|
||||||
|
assertMatches(mafmt.Circuit, goodCircuit)
|
||||||
|
})
|
||||||
|
|
||||||
it('IPFS validation', function () {
|
it('IPFS validation', function () {
|
||||||
assertMatches(mafmt.IPFS, goodIPFS)
|
assertMatches(mafmt.IPFS, goodIPFS)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user