Skip to content

Commit 37eceec

Browse files
authored
Merge pull request #111 from godcong/master
fix #108
2 parents 5b1de2f + bbcf5cb commit 37eceec

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

protocols.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ 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
1114
P_IP6ZONE = 0x002A
1215
P_QUIC = 0x01CC
1316
P_SCTP = 0x0084
17+
P_CIRCUIT = 0x0122
1418
P_UDT = 0x012D
1519
P_UTP = 0x012E
1620
P_UNIX = 0x0190
@@ -23,6 +27,7 @@ const (
2327
P_GARLIC64 = 0x01BE
2428
P_GARLIC32 = 0x01BF
2529
P_P2P_WEBRTC_DIRECT = 0x0114
30+
P_WS = 0x01DD
2631
)
2732

2833
var (
@@ -42,6 +47,27 @@ var (
4247
Path: false,
4348
Transcoder: TranscoderPort,
4449
}
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+
}
4571
protoUDP = Protocol{
4672
Name: "udp",
4773
Code: P_UDP,
@@ -81,6 +107,14 @@ var (
81107
Size: 16,
82108
Transcoder: TranscoderPort,
83109
}
110+
111+
protoCIRCUIT = Protocol{
112+
Code: P_CIRCUIT,
113+
Size: 0,
114+
Name: "p2p-circuit",
115+
VCode: CodeToVarint(P_CIRCUIT),
116+
}
117+
84118
protoONION2 = Protocol{
85119
Name: "onion",
86120
Code: P_ONION,
@@ -154,17 +188,26 @@ var (
154188
Code: P_P2P_WEBRTC_DIRECT,
155189
VCode: CodeToVarint(P_P2P_WEBRTC_DIRECT),
156190
}
191+
protoWS = Protocol{
192+
Name: "ws",
193+
Code: P_WS,
194+
VCode: CodeToVarint(P_WS),
195+
}
157196
)
158197

159198
func init() {
160199
for _, p := range []Protocol{
161200
protoIP4,
162201
protoTCP,
202+
protoDNS4,
203+
protoDNS6,
204+
protoDNSADDR,
163205
protoUDP,
164206
protoDCCP,
165207
protoIP6,
166208
protoIP6ZONE,
167209
protoSCTP,
210+
protoCIRCUIT,
168211
protoONION2,
169212
protoONION3,
170213
protoGARLIC64,
@@ -177,6 +220,7 @@ func init() {
177220
protoP2P,
178221
protoUNIX,
179222
protoP2P_WEBRTC_DIRECT,
223+
protoWS,
180224
} {
181225
if err := AddProtocol(p); err != nil {
182226
panic(err)

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)