mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-09 14:50:56 +00:00
Create a correct URL is more difficult than just slapping on a scheme (fixes #2316)
This commit is contained in:
parent
48c34b7234
commit
08c8d679ac
@ -63,13 +63,13 @@ func (e *addressLister) addresses(includePrivateIPV4 bool) []string {
|
|||||||
|
|
||||||
if addr.IP == nil || addr.IP.IsUnspecified() {
|
if addr.IP == nil || addr.IP.IsUnspecified() {
|
||||||
// Address like 0.0.0.0:22000 or [::]:22000 or :22000; include as is.
|
// 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) {
|
} else if isPublicIPv4(addr.IP) || isPublicIPv6(addr.IP) {
|
||||||
// A public address; include as is.
|
// 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() {
|
} else if includePrivateIPV4 && addr.IP.To4().IsGlobalUnicast() {
|
||||||
// A private IPv4 address.
|
// 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()
|
return ip.IsGlobalUnicast()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tcpAddr(host string) string {
|
||||||
|
u := url.URL{
|
||||||
|
Scheme: "tcp",
|
||||||
|
Host: host,
|
||||||
|
}
|
||||||
|
return u.String()
|
||||||
|
}
|
||||||
|
@ -9,9 +9,9 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -293,14 +293,14 @@ func convertV11V12(cfg *Configuration) {
|
|||||||
// Change listen address schema
|
// Change listen address schema
|
||||||
for i, addr := range cfg.Options.ListenAddress {
|
for i, addr := range cfg.Options.ListenAddress {
|
||||||
if len(addr) > 0 && !strings.HasPrefix(addr, "tcp://") {
|
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 i, device := range cfg.Devices {
|
||||||
for j, addr := range device.Addresses {
|
for j, addr := range device.Addresses {
|
||||||
if addr != "dynamic" && addr != "" {
|
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)
|
return string(bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func tcpAddr(host string) string {
|
||||||
|
u := url.URL{
|
||||||
|
Scheme: "tcp",
|
||||||
|
Host: host,
|
||||||
|
}
|
||||||
|
return u.String()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user