feat: add support for recursive addresses

This commit is contained in:
dmitriy ryajov 2017-03-26 19:40:06 -07:00
parent c0d2d051b9
commit 2e28d27740

View File

@ -62,15 +62,24 @@ let _IPFS = or(
base('ipfs') base('ipfs')
) )
const Circuit = or( const _Circuit = or(
and(_IPFS, base('p2p-circuit'), _IPFS), and(_IPFS, base('p2p-circuit'), _IPFS),
and(_IPFS, base('p2p-circuit')), and(_IPFS, base('p2p-circuit')),
and(base('p2p-circuit'), _IPFS), and(base('p2p-circuit'), _IPFS),
and(Reliable, base('p2p-circuit')), and(Reliable, base('p2p-circuit')),
and(base('p2p-circuit'), Reliable),
base('p2p-circuit') base('p2p-circuit')
) )
const CircuitRecursive = () => or(
and(_Circuit, CircuitRecursive),
_Circuit
)
const Circuit = CircuitRecursive()
const IPFS = or( const IPFS = or(
and(Circuit, _IPFS, Circuit),
and(_IPFS, Circuit), and(_IPFS, Circuit),
and(Circuit, _IPFS), and(Circuit, _IPFS),
Circuit, Circuit,
@ -116,7 +125,7 @@ function and () {
return null return null
} }
args.some(function (arg) { args.some(function (arg) {
a = arg.partialMatch(a) a = typeof arg === 'function' ? arg().partialMatch(a) : arg.partialMatch(a)
if (a === null) { if (a === null) {
return true return true
} }
@ -149,7 +158,7 @@ function or () {
function partialMatch (a) { function partialMatch (a) {
let out = null let out = null
args.some(function (arg) { args.some(function (arg) {
const res = arg.partialMatch(a) const res = typeof arg === 'function' ? arg().partialMatch(a) : arg.partialMatch(a)
if (res) { if (res) {
out = res out = res
return true return true
@ -171,6 +180,7 @@ function or () {
function base (n) { function base (n) {
const name = n const name = n
function matches (a) { function matches (a) {
if (typeof a === 'string') { if (typeof a === 'string') {
a = multiaddr(a) a = multiaddr(a)