File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ package multiaddr
5
5
const (
6
6
P_IP4 = 0x0004
7
7
P_TCP = 0x0006
8
+ P_DNS4 = 0x0036
9
+ P_DNS6 = 0x0037
10
+ P_DNSADDR = 0x0038
8
11
P_UDP = 0x0111
9
12
P_DCCP = 0x0021
10
13
P_IP6 = 0x0029
44
47
Path : false ,
45
48
Transcoder : TranscoderPort ,
46
49
}
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
+ }
47
71
protoUDP = Protocol {
48
72
Name : "udp" ,
49
73
Code : P_UDP ,
@@ -175,6 +199,9 @@ func init() {
175
199
for _ , p := range []Protocol {
176
200
protoIP4 ,
177
201
protoTCP ,
202
+ protoDNS4 ,
203
+ protoDNS6 ,
204
+ protoDNSADDR ,
178
205
protoUDP ,
179
206
protoDCCP ,
180
207
protoIP6 ,
Original file line number Diff line number Diff line change @@ -317,3 +317,20 @@ func unixStB(s string) ([]byte, error) {
317
317
func unixBtS (b []byte ) (string , error ) {
318
318
return string (b ), nil
319
319
}
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
+ }
You can’t perform that action at this time.
0 commit comments