Merge pull request #2423 from calmh/urls

Create a correct URL is more difficult than just slapping on a scheme (fixes #2316)
This commit is contained in:
Audrius Butkevicius 2015-10-30 20:50:32 +00:00
commit 1fac2f686d
2 changed files with 22 additions and 6 deletions

View File

@ -63,13 +63,13 @@ func (e *addressLister) addresses(includePrivateIPV4 bool) []string {
if addr.IP == nil || addr.IP.IsUnspecified() {
// Address like 0.0.0.0:22000 or [::]:22000 or :22000; include as is.
addrs = append(addrs, "tcp://"+addr.String())
addrs = append(addrs, tcpAddr(addr.String()))
} else if isPublicIPv4(addr.IP) || isPublicIPv6(addr.IP) {
// A public address; include as is.
addrs = append(addrs, "tcp://"+addr.String())
addrs = append(addrs, tcpAddr(addr.String()))
} else if includePrivateIPV4 && addr.IP.To4().IsGlobalUnicast() {
// A private IPv4 address.
addrs = append(addrs, "tcp://"+addr.String())
addrs = append(addrs, tcpAddr(addr.String()))
}
}
@ -117,3 +117,11 @@ func isPublicIPv6(ip net.IP) bool {
return ip.IsGlobalUnicast()
}
func tcpAddr(host string) string {
u := url.URL{
Scheme: "tcp",
Host: host,
}
return u.String()
}

View File

@ -9,9 +9,9 @@ package config
import (
"encoding/xml"
"fmt"
"io"
"math/rand"
"net/url"
"os"
"path/filepath"
"reflect"
@ -293,14 +293,14 @@ func convertV11V12(cfg *Configuration) {
// Change listen address schema
for i, addr := range cfg.Options.ListenAddress {
if len(addr) > 0 && !strings.HasPrefix(addr, "tcp://") {
cfg.Options.ListenAddress[i] = fmt.Sprintf("tcp://%s", addr)
cfg.Options.ListenAddress[i] = tcpAddr(addr)
}
}
for i, device := range cfg.Devices {
for j, addr := range device.Addresses {
if addr != "dynamic" && addr != "" {
cfg.Devices[i].Addresses[j] = fmt.Sprintf("tcp://%s", addr)
cfg.Devices[i].Addresses[j] = tcpAddr(addr)
}
}
}
@ -499,3 +499,11 @@ func randomString(l int) string {
}
return string(bs)
}
func tcpAddr(host string) string {
u := url.URL{
Scheme: "tcp",
Host: host,
}
return u.String()
}