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 ...@@ -5,12 +5,16 @@ package multiaddr
const ( const (
P_IP4 = 0x0004 P_IP4 = 0x0004
P_TCP = 0x0006 P_TCP = 0x0006
P_DNS4 = 0x0036
P_DNS6 = 0x0037
P_DNSADDR = 0x0038
P_UDP = 0x0111 P_UDP = 0x0111
P_DCCP = 0x0021 P_DCCP = 0x0021
P_IP6 = 0x0029 P_IP6 = 0x0029
P_IP6ZONE = 0x002A P_IP6ZONE = 0x002A
P_QUIC = 0x01CC P_QUIC = 0x01CC
P_SCTP = 0x0084 P_SCTP = 0x0084
P_CIRCUIT = 0x0122
P_UDT = 0x012D P_UDT = 0x012D
P_UTP = 0x012E P_UTP = 0x012E
P_UNIX = 0x0190 P_UNIX = 0x0190
...@@ -23,6 +27,7 @@ const ( ...@@ -23,6 +27,7 @@ const (
P_GARLIC64 = 0x01BE P_GARLIC64 = 0x01BE
P_GARLIC32 = 0x01BF P_GARLIC32 = 0x01BF
P_P2P_WEBRTC_DIRECT = 0x0114 P_P2P_WEBRTC_DIRECT = 0x0114
P_WS = 0x01DD
) )
var ( var (
...@@ -42,6 +47,27 @@ var ( ...@@ -42,6 +47,27 @@ var (
Path: false, Path: false,
Transcoder: TranscoderPort, 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{ protoUDP = Protocol{
Name: "udp", Name: "udp",
Code: P_UDP, Code: P_UDP,
...@@ -81,6 +107,14 @@ var ( ...@@ -81,6 +107,14 @@ var (
Size: 16, Size: 16,
Transcoder: TranscoderPort, Transcoder: TranscoderPort,
} }
protoCIRCUIT = Protocol{
Code: P_CIRCUIT,
Size: 0,
Name: "p2p-circuit",
VCode: CodeToVarint(P_CIRCUIT),
}
protoONION2 = Protocol{ protoONION2 = Protocol{
Name: "onion", Name: "onion",
Code: P_ONION, Code: P_ONION,
...@@ -154,17 +188,26 @@ var ( ...@@ -154,17 +188,26 @@ var (
Code: P_P2P_WEBRTC_DIRECT, Code: P_P2P_WEBRTC_DIRECT,
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT), VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
} }
protoWS = Protocol{
Name: "ws",
Code: P_WS,
VCode: CodeToVarint(P_WS),
}
) )
func init() { func init() {
for _, p := range []Protocol{ for _, p := range []Protocol{
protoIP4, protoIP4,
protoTCP, protoTCP,
protoDNS4,
protoDNS6,
protoDNSADDR,
protoUDP, protoUDP,
protoDCCP, protoDCCP,
protoIP6, protoIP6,
protoIP6ZONE, protoIP6ZONE,
protoSCTP, protoSCTP,
protoCIRCUIT,
protoONION2, protoONION2,
protoONION3, protoONION3,
protoGARLIC64, protoGARLIC64,
...@@ -177,6 +220,7 @@ func init() { ...@@ -177,6 +220,7 @@ func init() {
protoP2P, protoP2P,
protoUNIX, protoUNIX,
protoP2P_WEBRTC_DIRECT, protoP2P_WEBRTC_DIRECT,
protoWS,
} { } {
if err := AddProtocol(p); err != nil { if err := AddProtocol(p); err != nil {
panic(err) panic(err)
......
...@@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) { ...@@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) {
func unixBtS(b []byte) (string, error) { func unixBtS(b []byte) (string, error) {
return string(b), nil 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