MultiAddress support
This commit is contained in:
parent
75871817ee
commit
6ab779d30a
|
@ -297,6 +297,33 @@ proc dnsVB(vb: var VBuffer): bool =
|
||||||
if s.find('/') == -1:
|
if s.find('/') == -1:
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
|
proc certHashStB(s: string, vb: var VBuffer): bool =
|
||||||
|
## CertHash address stringToBuffer() implementation.
|
||||||
|
var data = MultiBase.decode(s).valueOr:
|
||||||
|
return false
|
||||||
|
var mh: MultiHash
|
||||||
|
if MultiHash.decode(data, mh).isOk:
|
||||||
|
vb.writeSeq(data)
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc certHashBtS(vb: var VBuffer, s: var string): bool =
|
||||||
|
## CertHash address bufferToString() implementation.
|
||||||
|
var address = newSeq[byte]()
|
||||||
|
if vb.readSeq(address) > 0:
|
||||||
|
var mh: MultiHash
|
||||||
|
if MultiHash.decode(address, mh).isOk:
|
||||||
|
s = MultiBase.encode("base64", address).valueOr:
|
||||||
|
return false
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc certHashVB(vb: var VBuffer): bool =
|
||||||
|
## CertHash address validateBuffer() implementation.
|
||||||
|
var address = newSeq[byte]()
|
||||||
|
if vb.readSeq(address) > 0:
|
||||||
|
var mh: MultiHash
|
||||||
|
if MultiHash.decode(address, mh).isOk:
|
||||||
|
result = true
|
||||||
|
|
||||||
proc mapEq*(codec: string): MaPattern =
|
proc mapEq*(codec: string): MaPattern =
|
||||||
## ``Equal`` operator for pattern
|
## ``Equal`` operator for pattern
|
||||||
result.operator = Eq
|
result.operator = Eq
|
||||||
|
@ -358,6 +385,11 @@ const
|
||||||
bufferToString: dnsBtS,
|
bufferToString: dnsBtS,
|
||||||
validateBuffer: dnsVB
|
validateBuffer: dnsVB
|
||||||
)
|
)
|
||||||
|
TranscoderCertHash* = Transcoder(
|
||||||
|
stringToBuffer: certHashStB,
|
||||||
|
bufferToString: certHashBtS,
|
||||||
|
validateBuffer: certHashVB
|
||||||
|
)
|
||||||
ProtocolsList = [
|
ProtocolsList = [
|
||||||
MAProtocol(
|
MAProtocol(
|
||||||
mcodec: multiCodec("ip4"), kind: Fixed, size: 4,
|
mcodec: multiCodec("ip4"), kind: Fixed, size: 4,
|
||||||
|
@ -458,7 +490,17 @@ const
|
||||||
),
|
),
|
||||||
MAProtocol(
|
MAProtocol(
|
||||||
mcodec: multiCodec("p2p-webrtc-direct"), kind: Marker, size: 0
|
mcodec: multiCodec("p2p-webrtc-direct"), kind: Marker, size: 0
|
||||||
)
|
),
|
||||||
|
MAProtocol(
|
||||||
|
mcodec: multiCodec("webrtc"), kind: Marker, size: 0
|
||||||
|
),
|
||||||
|
MAProtocol(
|
||||||
|
mcodec: multiCodec("webrtc-direct"), kind: Marker, size: 0
|
||||||
|
),
|
||||||
|
MAProtocol(
|
||||||
|
mcodec: multiCodec("certhash"), kind: Length, size: 0,
|
||||||
|
coder: TranscoderCertHash
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
DNSANY* = mapEq("dns")
|
DNSANY* = mapEq("dns")
|
||||||
|
@ -489,6 +531,7 @@ const
|
||||||
WebSockets_DNS* = mapOr(WS_DNS, WSS_DNS)
|
WebSockets_DNS* = mapOr(WS_DNS, WSS_DNS)
|
||||||
WebSockets_IP* = mapOr(WS_IP, WSS_IP)
|
WebSockets_IP* = mapOr(WS_IP, WSS_IP)
|
||||||
WebSockets* = mapOr(WS, WSS)
|
WebSockets* = mapOr(WS, WSS)
|
||||||
|
WebRtcDirect2* = mapAnd(UDP, mapEq("webrtc-direct"), mapEq("certhash"))
|
||||||
Onion3* = mapEq("onion3")
|
Onion3* = mapEq("onion3")
|
||||||
TcpOnion3* = mapAnd(TCP, Onion3)
|
TcpOnion3* = mapAnd(TCP, Onion3)
|
||||||
|
|
||||||
|
@ -512,7 +555,7 @@ const
|
||||||
mapAnd(DNS, mapEq("https"))
|
mapAnd(DNS, mapEq("https"))
|
||||||
)
|
)
|
||||||
|
|
||||||
WebRTCDirect* = mapOr(
|
WebRTCDirect* {.deprecated.} = mapOr(
|
||||||
mapAnd(HTTP, mapEq("p2p-webrtc-direct")),
|
mapAnd(HTTP, mapEq("p2p-webrtc-direct")),
|
||||||
mapAnd(HTTPS, mapEq("p2p-webrtc-direct"))
|
mapAnd(HTTPS, mapEq("p2p-webrtc-direct"))
|
||||||
)
|
)
|
||||||
|
|
|
@ -193,11 +193,14 @@ const MultiCodecList = [
|
||||||
("https", 0x01BB),
|
("https", 0x01BB),
|
||||||
("tls", 0x01C0),
|
("tls", 0x01C0),
|
||||||
("quic", 0x01CC),
|
("quic", 0x01CC),
|
||||||
|
("certhash", 0x01D2),
|
||||||
("ws", 0x01DD),
|
("ws", 0x01DD),
|
||||||
("wss", 0x01DE),
|
("wss", 0x01DE),
|
||||||
("p2p-websocket-star", 0x01DF), # not in multicodec list
|
("p2p-websocket-star", 0x01DF), # not in multicodec list
|
||||||
("p2p-webrtc-star", 0x0113), # not in multicodec list
|
("p2p-webrtc-star", 0x0113), # not in multicodec list
|
||||||
("p2p-webrtc-direct", 0x0114), # not in multicodec list
|
("p2p-webrtc-direct", 0x0114), # not in multicodec list
|
||||||
|
("webrtc-direct", 0x0118),
|
||||||
|
("webrtc", 0x0119),
|
||||||
("onion", 0x01BC),
|
("onion", 0x01BC),
|
||||||
("onion3", 0x01BD),
|
("onion3", 0x01BD),
|
||||||
("p2p-circuit", 0x0122),
|
("p2p-circuit", 0x0122),
|
||||||
|
|
|
@ -147,7 +147,9 @@ const
|
||||||
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
|
"/ip4/127.0.0.1/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC/tcp/1234",
|
||||||
"/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
|
"/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
|
||||||
"/p2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
|
"/p2p-webrtc-star/ip4/127.0.0.1/tcp/9090/ws/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
|
||||||
"/ip4/127.0.0.1/tcp/9090/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"
|
"/ip4/127.0.0.1/tcp/9090/p2p-circuit/ipfs/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
|
||||||
|
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
|
||||||
|
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
|
||||||
]
|
]
|
||||||
|
|
||||||
RustSuccessExpects = [
|
RustSuccessExpects = [
|
||||||
|
@ -177,7 +179,9 @@ const
|
||||||
"047F000001A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B0604D2",
|
"047F000001A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B0604D2",
|
||||||
"29200108A07AC542013AC986FFFE317095061F40DD03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
|
"29200108A07AC542013AC986FFFE317095061F40DD03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
|
||||||
"9302047F000001062382DD03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
|
"9302047F000001062382DD03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
|
||||||
"047F000001062382A202A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B"
|
"047F000001062382A202A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
|
||||||
|
"047F000001910204D29802",
|
||||||
|
"047F000001910204D29802D203221220C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2"
|
||||||
]
|
]
|
||||||
|
|
||||||
RustFailureVectors = [
|
RustFailureVectors = [
|
||||||
|
@ -211,7 +215,9 @@ const
|
||||||
"/ip4/127.0.0.1/tcp",
|
"/ip4/127.0.0.1/tcp",
|
||||||
"/ip4/127.0.0.1/ipfs",
|
"/ip4/127.0.0.1/ipfs",
|
||||||
"/ip4/127.0.0.1/ipfs/tcp",
|
"/ip4/127.0.0.1/ipfs/tcp",
|
||||||
"/p2p-circuit/50"
|
"/p2p-circuit/50",
|
||||||
|
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp",
|
||||||
|
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash"
|
||||||
]
|
]
|
||||||
|
|
||||||
PathVectors = [
|
PathVectors = [
|
||||||
|
|
Loading…
Reference in New Issue