Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
37eceece
Unverified
Commit
37eceece
authored
Sep 18, 2019
by
Steven Allen
Committed by
GitHub
Sep 18, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #111 from godcong/master
fix
https://github.com/multiformats/go-multiaddr/issues/108
parents
5b1de2f5
bbcf5cbb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
0 deletions
+61
-0
protocols.go
protocols.go
+44
-0
transcoders.go
transcoders.go
+17
-0
No files found.
protocols.go
View file @
37eceece
...
...
@@ -5,12 +5,16 @@ 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
P_IP6ZONE
=
0x002A
P_QUIC
=
0x01CC
P_SCTP
=
0x0084
P_CIRCUIT
=
0x0122
P_UDT
=
0x012D
P_UTP
=
0x012E
P_UNIX
=
0x0190
...
...
@@ -23,6 +27,7 @@ const (
P_GARLIC64
=
0x01BE
P_GARLIC32
=
0x01BF
P_P2P_WEBRTC_DIRECT
=
0x0114
P_WS
=
0x01DD
)
var
(
...
...
@@ -42,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
,
...
...
@@ -81,6 +107,14 @@ var (
Size
:
16
,
Transcoder
:
TranscoderPort
,
}
protoCIRCUIT
=
Protocol
{
Code
:
P_CIRCUIT
,
Size
:
0
,
Name
:
"p2p-circuit"
,
VCode
:
CodeToVarint
(
P_CIRCUIT
),
}
protoONION2
=
Protocol
{
Name
:
"onion"
,
Code
:
P_ONION
,
...
...
@@ -154,17 +188,26 @@ var (
Code
:
P_P2P_WEBRTC_DIRECT
,
VCode
:
CodeToVarint
(
P_P2P_WEBRTC_DIRECT
),
}
protoWS
=
Protocol
{
Name
:
"ws"
,
Code
:
P_WS
,
VCode
:
CodeToVarint
(
P_WS
),
}
)
func
init
()
{
for
_
,
p
:=
range
[]
Protocol
{
protoIP4
,
protoTCP
,
protoDNS4
,
protoDNS6
,
protoDNSADDR
,
protoUDP
,
protoDCCP
,
protoIP6
,
protoIP6ZONE
,
protoSCTP
,
protoCIRCUIT
,
protoONION2
,
protoONION3
,
protoGARLIC64
,
...
...
@@ -177,6 +220,7 @@ func init() {
protoP2P
,
protoUNIX
,
protoP2P_WEBRTC_DIRECT
,
protoWS
,
}
{
if
err
:=
AddProtocol
(
p
);
err
!=
nil
{
panic
(
err
)
...
...
transcoders.go
View file @
37eceece
...
...
@@ -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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment