Commit bbcf5cbb authored by godcong's avatar godcong
parent 0550a5ba
......@@ -5,6 +5,9 @@ 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
......@@ -44,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,
......@@ -175,6 +199,9 @@ func init() {
for _, p := range []Protocol{
protoIP4,
protoTCP,
protoDNS4,
protoDNS6,
protoDNSADDR,
protoUDP,
protoDCCP,
protoIP6,
......
......@@ -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