Export MultiAddress pattern procedures.

This commit is contained in:
cheatfate 2020-02-12 12:04:12 +02:00
parent 540e79a430
commit 5b6f4bf5fa
No known key found for this signature in database
GPG Key ID: 46ADD633A7201F95
1 changed files with 28 additions and 28 deletions

View File

@ -234,17 +234,17 @@ proc dnsVB(vb: var VBuffer): bool =
if s.find('/') == -1: if s.find('/') == -1:
result = true result = true
proc pEq(codec: string): MaPattern = proc mapEq*(codec: string): MaPattern =
## ``Equal`` operator for pattern ## ``Equal`` operator for pattern
result.operator = Eq result.operator = Eq
result.value = multiCodec(codec) result.value = multiCodec(codec)
proc pOr(args: varargs[MaPattern]): MaPattern = proc mapOr*(args: varargs[MaPattern]): MaPattern =
## ``Or`` operator for pattern ## ``Or`` operator for pattern
result.operator = Or result.operator = Or
result.args = @args result.args = @args
proc pAnd(args: varargs[MaPattern]): MaPattern = proc mapAnd*(args: varargs[MaPattern]): MaPattern =
## ``And`` operator for pattern ## ``And`` operator for pattern
result.operator = And result.operator = And
result.args = @args result.args = @args
@ -379,39 +379,39 @@ const
) )
] ]
DNS4* = pEq("dns4") DNS4* = mapEq("dns4")
DNS6* = pEq("dns6") DNS6* = mapEq("dns6")
IP4* = pEq("ip4") IP4* = mapEq("ip4")
IP6* = pEq("ip6") IP6* = mapEq("ip6")
DNS* = pOr(pEq("dnsaddr"), DNS4, DNS6) DNS* = mapOr(mapEq("dnsaddr"), DNS4, DNS6)
IP* = pOr(IP4, IP6) IP* = mapOr(IP4, IP6)
TCP* = pOr(pAnd(DNS, pEq("tcp")), pAnd(IP, pEq("tcp"))) TCP* = mapOr(mapAnd(DNS, mapEq("tcp")), mapAnd(IP, mapEq("tcp")))
UDP* = pOr(pAnd(DNS, pEq("udp")), pAnd(IP, pEq("udp"))) UDP* = mapOr(mapAnd(DNS, mapEq("udp")), mapAnd(IP, mapEq("udp")))
UTP* = pAnd(UDP, pEq("utp")) UTP* = mapAnd(UDP, mapEq("utp"))
QUIC* = pAnd(UDP, pEq("quic")) QUIC* = mapAnd(UDP, mapEq("quic"))
UNIX* = pEq("unix") UNIX* = mapEq("unix")
Unreliable* = pOr(UDP) Unreliable* = mapOr(UDP)
Reliable* = pOr(TCP, UTP, QUIC) Reliable* = mapOr(TCP, UTP, QUIC)
IPFS* = pAnd(Reliable, pEq("p2p")) IPFS* = mapAnd(Reliable, mapEq("p2p"))
HTTP* = pOr( HTTP* = mapOr(
pAnd(TCP, pEq("http")), mapAnd(TCP, mapEq("http")),
pAnd(IP, pEq("http")), mapAnd(IP, mapEq("http")),
pAnd(DNS, pEq("http")) mapAnd(DNS, mapEq("http"))
) )
HTTPS* = pOr( HTTPS* = mapOr(
pAnd(TCP, pEq("https")), mapAnd(TCP, mapEq("https")),
pAnd(IP, pEq("https")), mapAnd(IP, mapEq("https")),
pAnd(DNS, pEq("https")) mapAnd(DNS, mapEq("https"))
) )
WebRTCDirect* = pOr( WebRTCDirect* = mapOr(
pAnd(HTTP, pEq("p2p-webrtc-direct")), mapAnd(HTTP, mapEq("p2p-webrtc-direct")),
pAnd(HTTPS, pEq("p2p-webrtc-direct")) mapAnd(HTTPS, mapEq("p2p-webrtc-direct"))
) )
proc initMultiAddressCodeTable(): Table[MultiCodec, proc initMultiAddressCodeTable(): Table[MultiCodec,