Skip to content

Commit bbcf5cb

Browse files
committed
1 parent 0550a5b commit bbcf5cb

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

protocols.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ package multiaddr
55
const (
66
P_IP4 = 0x0004
77
P_TCP = 0x0006
8+
P_DNS4 = 0x0036
9+
P_DNS6 = 0x0037
10+
P_DNSADDR = 0x0038
811
P_UDP = 0x0111
912
P_DCCP = 0x0021
1013
P_IP6 = 0x0029
@@ -44,6 +47,27 @@ var (
4447
Path: false,
4548
Transcoder: TranscoderPort,
4649
}
50+
protoDNS4 = Protocol{
51+
Code: P_DNS4,
52+
Size: LengthPrefixedVarSize,
53+
Name: "dns4",
54+
VCode: CodeToVarint(P_DNS4),
55+
Transcoder: TranscoderDns,
56+
}
57+
protoDNS6 = Protocol{
58+
Code: P_DNS6,
59+
Size: LengthPrefixedVarSize,
60+
Name: "dns6",
61+
VCode: CodeToVarint(P_DNS6),
62+
Transcoder: TranscoderDns,
63+
}
64+
protoDNSADDR = Protocol{
65+
Code: P_DNSADDR,
66+
Size: LengthPrefixedVarSize,
67+
Name: "dnsaddr",
68+
VCode: CodeToVarint(P_DNSADDR),
69+
Transcoder: TranscoderDns,
70+
}
4771
protoUDP = Protocol{
4872
Name: "udp",
4973
Code: P_UDP,
@@ -175,6 +199,9 @@ func init() {
175199
for _, p := range []Protocol{
176200
protoIP4,
177201
protoTCP,
202+
protoDNS4,
203+
protoDNS6,
204+
protoDNSADDR,
178205
protoUDP,
179206
protoDCCP,
180207
protoIP6,

transcoders.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) {
317317
func unixBtS(b []byte) (string, error) {
318318
return string(b), nil
319319
}
320+
321+
var TranscoderDns = NewTranscoderFromFunctions(dnsStB, dnsBtS, dnsVal)
322+
323+
func dnsVal(b []byte) error {
324+
if bytes.IndexByte(b, '/') >= 0 {
325+
return fmt.Errorf("domain name %q contains a slash", string(b))
326+
}
327+
return nil
328+
}
329+
330+
func dnsStB(s string) ([]byte, error) {
331+
return []byte(s), nil
332+
}
333+
334+
func dnsBtS(b []byte) (string, error) {
335+
return string(b), nil
336+
}

0 commit comments

Comments
 (0)