Commit 611d2a4f authored by Steven Allen's avatar Steven Allen

address CR

parent d66032c3
......@@ -4,6 +4,8 @@ import (
"fmt"
"net"
"path/filepath"
"runtime"
"strings"
ma "github.com/multiformats/go-multiaddr"
)
......@@ -192,7 +194,11 @@ func DialArgs(m ma.Multiaddr) (string, string, error) {
}
return network, "[" + ip + "]" + ":" + port, nil
case "unix":
return network, filepath.FromSlash(ip), nil
if runtime.GOOS == "windows" {
// convert /c:/... to c:\...
ip = filepath.FromSlash(strings.TrimLeft(ip, "/"))
}
return network, ip, nil
default:
return "", "", fmt.Errorf("%s is not a 'thin waist' address", m)
}
......@@ -264,5 +270,15 @@ func parseUnixNetAddr(a net.Addr) (ma.Multiaddr, error) {
return nil, errIncorrectNetAddr
}
return ma.NewComponent("unix", filepath.ToSlash(ac.Name))
path := ac.Name
if runtime.GOOS == "windows" {
// Convert c:\foobar\... to c:/foobar/...
path = filepath.ToSlash(path)
}
if len(path) == 0 || path[0] != '/' {
// convert "" and "c:/..." to "/..."
path = "/" + path
}
return ma.NewComponent("unix", path)
}
......@@ -2,6 +2,7 @@ package manet
import (
"net"
"runtime"
"testing"
ma "github.com/multiformats/go-multiaddr"
......@@ -65,17 +66,21 @@ func TestFromIP4(t *testing.T) {
}
func TestFromUnix(t *testing.T) {
path := "/c:/foo/bar"
if runtime.GOOS == "windows" {
path = "c:\foo\bar"
}
testConvert(t, "/unix/c:/foo/bar", func() (ma.Multiaddr, error) {
return FromNetAddr(&net.UnixAddr{Name: "/c:/foo/bar", Net: "unix"})
})
testConvert(t, "/unix/foo/bar", func() (ma.Multiaddr, error) {
return FromNetAddr(&net.UnixAddr{Name: "/foo/bar", Net: "unix"})
return FromNetAddr(&net.UnixAddr{Name: path, Net: "unix"})
})
}
func TestToUnix(t *testing.T) {
testToNetAddr(t, "/unix/c:/foo/bar", "unix", "/c:/foo/bar")
testToNetAddr(t, "/unix/foo/bar", "unix", "/foo/bar")
path := "/c:/foo/bar"
if runtime.GOOS == "windows" {
path = "c:\foo\bar"
}
testToNetAddr(t, "/unix/c:/foo/bar", "unix", path)
}
func TestFromIP6(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment