Unverified Commit 37eceece authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #111 from godcong/master

fix https://github.com/multiformats/go-multiaddr/issues/108
parents 5b1de2f5 bbcf5cbb
......@@ -5,12 +5,16 @@ package multiaddr
const (
P_IP4 = 0x0004
P_TCP = 0x0006
P_DNS4 = 0x0036
P_DNS6 = 0x0037
P_DNSADDR = 0x0038
P_UDP = 0x0111
P_DCCP = 0x0021
P_IP6 = 0x0029
P_IP6ZONE = 0x002A
P_QUIC = 0x01CC
P_SCTP = 0x0084
P_CIRCUIT = 0x0122
P_UDT = 0x012D
P_UTP = 0x012E
P_UNIX = 0x0190
......@@ -23,6 +27,7 @@ const (
P_GARLIC64 = 0x01BE
P_GARLIC32 = 0x01BF
P_P2P_WEBRTC_DIRECT = 0x0114
P_WS = 0x01DD
)
var (
......@@ -42,6 +47,27 @@ var (
Path: false,
Transcoder: TranscoderPort,
}
protoDNS4 = Protocol{
Code: P_DNS4,
Size: LengthPrefixedVarSize,
Name: "dns4",
VCode: CodeToVarint(P_DNS4),
Transcoder: TranscoderDns,
}
protoDNS6 = Protocol{
Code: P_DNS6,
Size: LengthPrefixedVarSize,
Name: "dns6",
VCode: CodeToVarint(P_DNS6),
Transcoder: TranscoderDns,
}
protoDNSADDR = Protocol{
Code: P_DNSADDR,
Size: LengthPrefixedVarSize,
Name: "dnsaddr",
VCode: CodeToVarint(P_DNSADDR),
Transcoder: TranscoderDns,
}
protoUDP = Protocol{
Name: "udp",
Code: P_UDP,
......@@ -81,6 +107,14 @@ var (
Size: 16,
Transcoder: TranscoderPort,
}
protoCIRCUIT = Protocol{
Code: P_CIRCUIT,
Size: 0,
Name: "p2p-circuit",
VCode: CodeToVarint(P_CIRCUIT),
}
protoONION2 = Protocol{
Name: "onion",
Code: P_ONION,
......@@ -154,17 +188,26 @@ var (
Code: P_P2P_WEBRTC_DIRECT,
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
}
protoWS = Protocol{
Name: "ws",
Code: P_WS,
VCode: CodeToVarint(P_WS),
}
)
func init() {
for _, p := range []Protocol{
protoIP4,
protoTCP,
protoDNS4,
protoDNS6,
protoDNSADDR,
protoUDP,
protoDCCP,
protoIP6,
protoIP6ZONE,
protoSCTP,
protoCIRCUIT,
protoONION2,
protoONION3,
protoGARLIC64,
......@@ -177,6 +220,7 @@ func init() {
protoP2P,
protoUNIX,
protoP2P_WEBRTC_DIRECT,
protoWS,
} {
if err := AddProtocol(p); err != nil {
panic(err)
......
......@@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) {
func unixBtS(b []byte) (string, error) {
return string(b), nil
}
var TranscoderDns = NewTranscoderFromFunctions(dnsStB, dnsBtS, dnsVal)
func dnsVal(b []byte) error {
if bytes.IndexByte(b, '/') >= 0 {
return fmt.Errorf("domain name %q contains a slash", string(b))
}
return nil
}
func dnsStB(s string) ([]byte, error) {
return []byte(s), nil
}
func dnsBtS(b []byte) (string, error) {
return string(b), nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment