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
07114b1b
Unverified
Commit
07114b1b
authored
Feb 05, 2020
by
Steven Allen
Committed by
GitHub
Feb 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add support for /dns in DialArgs (#63)
parent
d6d94242
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
19 deletions
+29
-19
convert.go
convert.go
+28
-3
convert_test.go
convert_test.go
+1
-0
go.sum
go.sum
+0
-16
No files found.
convert.go
View file @
07114b1b
...
...
@@ -132,6 +132,11 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
network
=
"ip4"
ip
=
c
.
Value
()
return
true
case
ma
.
P_DNS
:
network
=
"ip"
hostname
=
true
ip
=
c
.
Value
()
return
true
case
ma
.
P_DNS4
:
network
=
"ip4"
hostname
=
true
...
...
@@ -147,6 +152,16 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
ip
=
c
.
Value
()
return
false
}
case
"ip"
:
switch
c
.
Protocol
()
.
Code
{
case
ma
.
P_UDP
:
network
=
"udp"
case
ma
.
P_TCP
:
network
=
"tcp"
default
:
return
false
}
port
=
c
.
Value
()
case
"ip4"
:
switch
c
.
Protocol
()
.
Code
{
case
ma
.
P_UDP
:
...
...
@@ -175,6 +190,19 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
return
""
,
""
,
err
}
// If we have a hostname (dns*), we don't want any fancy ipv6 formatting
// logic (zone, brackets, etc.).
if
hostname
{
switch
network
{
case
"ip"
,
"ip4"
,
"ip6"
:
return
network
,
ip
,
nil
case
"tcp"
,
"tcp4"
,
"tcp6"
,
"udp"
,
"udp4"
,
"udp6"
:
return
network
,
ip
+
":"
+
port
,
nil
}
// Hostname is only true when network is one of the above.
panic
(
"unreachable"
)
}
switch
network
{
case
"ip6"
:
if
zone
!=
""
{
...
...
@@ -189,9 +217,6 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
if
zone
!=
""
{
ip
+=
"%"
+
zone
}
if
hostname
{
return
network
,
ip
+
":"
+
port
,
nil
}
return
network
,
"["
+
ip
+
"]"
+
":"
+
port
,
nil
case
"unix"
:
if
runtime
.
GOOS
==
"windows"
{
...
...
convert_test.go
View file @
07114b1b
...
...
@@ -187,6 +187,7 @@ func TestDialArgs(t *testing.T) {
test_error
(
"/ip6zone/foo/ip4/127.0.0.1"
)
// IP4 doesn't take zone
test
(
"/ip6zone/foo/ip6/::1/ip6zone/bar"
,
"ip6"
,
"::1%foo"
)
// IP over IP
test_error
(
"/ip6zone/foo/ip6zone/bar/ip6/::1"
)
// Only one zone per IP6
test
(
"/dns/abc.com/tcp/1234"
,
"tcp"
,
"abc.com:1234"
)
// DNS4:port
test
(
"/dns4/abc.com/tcp/1234"
,
"tcp4"
,
"abc.com:1234"
)
// DNS4:port
test
(
"/dns4/abc.com"
,
"ip4"
,
"abc.com"
)
// Just DNS4
test
(
"/dns6/abc.com/udp/1234"
,
"udp6"
,
"abc.com:1234"
)
// DNS6:port
...
...
go.sum
View file @
07114b1b
github.com/gxed/hashland/keccakpg
v0.0.1 h1:
wrk3uMNaMxbXiHibbPO4S0ymqJMm41WiudyFSs7UnsU=
github.com/gxed/hashland/keccakpg
v0.0.1/go.mod h1:
kRzw3HkwxFU1mpmPP8v1WyQzwdGfmKFJ6tItnhQ67kU=
github.com/gxed/hashland/murmur3
v0.0.1 h1:
SheiaIt0sda5K+8FLz952/1iWS9zrnKsEJaOJu4ZbSc=
github.com/gxed/hashland/murmur3
v0.0.1/go.mod h1:
KjXop02n4/ckmZSnY2+HKcLud/tcmvhST0bie/0lS48=
github.com/minio/blake2b-simd
v0.0.0-20160723061019-3f5f724cb5b1 h1:
lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd
v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:
pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd
v0.0.0-20190131020904-2d45a736cd16 h1:
5W7KhL8HVF3XCFOweFD3BNESdnO8ewyYTFT2R+/b8FQ=
github.com/minio/sha256-simd
v0.0.0-20190131020904-2d45a736cd16/go.mod h1:
2FMWW+8GMoPweT6+pI63m9YE3Lmw4J71hV56Chs1E/U=
github.com/minio/sha256-simd
v0.1.1-0.20190913151208-6de447530771 h1:
MHkK1uRtFbVqvAgvWxafZe54+5uBxLluGylDiKgdhwo=
github.com/minio/sha256-simd
v0.1.1-0.20190913151208-6de447530771/go.mod h1:
B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/mr-tron/base58
v1.1.0 h1:
Y51FGVJ91WBqCEabAi5OPUz38eAx8DakuAm5svLcsfQ=
github.com/mr-tron/base58
v1.1.0/go.mod h1:
xcD2VGqlgYjBdcBLw+TuYLr8afG+Hj8g2eTVqeSzSU8=
github.com/mr-tron/base58
v1.1.2 h1:
ZEw4I2EgPKDJ2iEw0cNmLB3ROrEmkOtXIkaG7wZg+78=
github.com/mr-tron/base58
v1.1.2/go.mod h1:
BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiformats/go-multiaddr
v0.1.0 h1:
fkISCUNDb3xIpCcI6BGlPsQE+ywcxzimOsUnHWnrE74=
github.com/multiformats/go-multiaddr
v0.1.0/go.mod h1:
xKVEak1K9cS1VdmPZW3LSIb6lgmoS58qz/pzqmAxV44=
github.com/multiformats/go-multiaddr
v0.2.0 h1:
lR52sFwcTCuQb6bTfnXF6zA2XfyYvyd+5a9qECv/J90=
github.com/multiformats/go-multiaddr
v0.2.0/go.mod h1:
0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4=
github.com/multiformats/go-multihash
v0.0.1 h1:
HHwN1K12I+XllBCrqKnhX949Orn4oawPkegHMu2vDqQ=
github.com/multiformats/go-multihash
v0.0.1/go.mod h1:
w/5tugSrLEbWqlcgJabL3oHFKTwfvkofsjW2Qa1ct4U=
github.com/multiformats/go-multihash
v0.0.8 h1:
wrYcW5yxSi3dU07n5jnuS5PrNwyHy0zRHGVoUugWvXg=
github.com/multiformats/go-multihash
v0.0.8/go.mod h1:
YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-varint
v0.0.1 h1:
TR/0rdQtnNxuN2IhiB639xC3tWM4IUi7DkTBVTdGW/M=
github.com/multiformats/go-varint
v0.0.1/go.mod h1:
3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE=
github.com/spaolacci/murmur3
v1.1.0 h1:
7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI=
github.com/spaolacci/murmur3
v1.1.0/go.mod h1:
JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
golang.org/x/crypto
v0.0.0-20190211182817-74369b46fc67 h1:
ng3VDlRp5/DHpSWl02R4rM9I+8M2rhmsuLwAMmkLQWE=
golang.org/x/crypto
v0.0.0-20190211182817-74369b46fc67/go.mod h1:
6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto
v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:
djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto
v0.0.0-20190611184440-5c40567a22f8 h1:
1wopBVtVdWnn03fZelqdXTqk7U7zPQCb+T4rbU9ZEoU=
golang.org/x/crypto
v0.0.0-20190611184440-5c40567a22f8/go.mod h1:
yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net
v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:
t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys
v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:
STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys
v0.0.0-20190219092855-153ac476189d h1:
Z0Ahzd7HltpJtjAHHxX8QFP3j1yYgiuvjbjRzDj/KH0=
golang.org/x/sys
v0.0.0-20190219092855-153ac476189d/go.mod h1:
STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys
v0.0.0-20190412213103-97732733099d h1:
+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys
v0.0.0-20190412213103-97732733099d/go.mod h1:
h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text
v0.3.0/go.mod h1:
NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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