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
ef212b51
Unverified
Commit
ef212b51
authored
Nov 29, 2018
by
Steven Allen
Committed by
GitHub
Nov 29, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #49 from multiformats/feat/support-dns-in-DialArgs
Feat: support hostnames in DialArgs() function
parents
f0af4033
3504e962
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
1 deletion
+29
-1
convert.go
convert.go
+19
-1
convert_test.go
convert_test.go
+4
-0
package.json
package.json
+6
-0
No files found.
convert.go
View file @
ef212b51
...
...
@@ -5,6 +5,7 @@ import (
"net"
ma
"github.com/multiformats/go-multiaddr"
madns
"github.com/multiformats/go-multiaddr-dns"
)
var
errIncorrectNetAddr
=
fmt
.
Errorf
(
"incorrect network addr conversion"
)
...
...
@@ -93,11 +94,14 @@ func FromIP(ip net.IP) (ma.Multiaddr, error) {
return
FromIPAndZone
(
ip
,
""
)
}
// DialArgs is a convenience function returning arguments for use in net.Dial
// DialArgs is a convenience function that returns network and address as
// expected by net.Dial. See https://godoc.org/net#Dial for an overview of
// possible return values (we do not support the unix* ones yet).
func
DialArgs
(
m
ma
.
Multiaddr
)
(
string
,
string
,
error
)
{
var
(
zone
,
network
,
ip
,
port
string
err
error
hostname
bool
)
ma
.
ForEach
(
m
,
func
(
c
ma
.
Component
)
bool
{
...
...
@@ -123,6 +127,16 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
network
=
"ip4"
ip
=
c
.
Value
()
return
true
case
madns
.
Dns4Protocol
.
Code
:
network
=
"ip4"
hostname
=
true
ip
=
c
.
Value
()
return
true
case
madns
.
Dns6Protocol
.
Code
:
network
=
"ip6"
hostname
=
true
ip
=
c
.
Value
()
return
true
}
case
"ip4"
:
switch
c
.
Protocol
()
.
Code
{
...
...
@@ -151,6 +165,7 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
if
err
!=
nil
{
return
""
,
""
,
err
}
switch
network
{
case
"ip6"
:
if
zone
!=
""
{
...
...
@@ -165,6 +180,9 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
if
zone
!=
""
{
ip
+=
"%"
+
zone
}
if
hostname
{
return
network
,
ip
+
":"
+
port
,
nil
}
return
network
,
"["
+
ip
+
"]"
+
":"
+
port
,
nil
default
:
return
""
,
""
,
fmt
.
Errorf
(
"%s is not a 'thin waist' address"
,
m
)
...
...
convert_test.go
View file @
ef212b51
...
...
@@ -168,4 +168,8 @@ 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
(
"/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
test
(
"/dns6/abc.com"
,
"ip6"
,
"abc.com"
)
// Just DNS6
}
package.json
View file @
ef212b51
...
...
@@ -12,6 +12,12 @@
"hash"
:
"QmRKLtwMw131aK7ugC3G7ybpumMz78YrJe5dzneyindvG1"
,
"name"
:
"go-multiaddr"
,
"version"
:
"1.3.6"
},
{
"author"
:
"lgierth"
,
"hash"
:
"QmT4zgnKCyZBpRyxzsvZqUjzUkMWLJ2pZCw7uk6M6Kto5m"
,
"name"
:
"go-multiaddr-dns"
,
"version"
:
"0.2.6"
}
],
"gxVersion"
:
"0.6.0"
,
...
...
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