lib/dialer: Add env var to disable proxy fallback (fixes #3006)

GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3009
This commit is contained in:
Audrius Butkevicius 2016-04-24 16:30:20 +00:00 committed by Jakob Borg
parent e87c1abd4e
commit 2467678bd4

View File

@ -23,6 +23,7 @@ var (
l = logger.DefaultLogger.NewFacility("dialer", "Dialing connections")
proxyDialer = getDialer(proxy.Direct)
usingProxy = proxyDialer != proxy.Direct
noFallback = os.Getenv("ALL_PROXY_NO_FALLBACK") != ""
)
type dialFunc func(network, addr string) (net.Conn, error)
@ -40,6 +41,9 @@ func init() {
go func() {
time.Sleep(500 * time.Millisecond)
l.Infoln("Proxy settings detected")
if noFallback {
l.Infoln("Proxy fallback disabled")
}
}()
} else {
go func() {
@ -62,6 +66,10 @@ func dialWithFallback(proxyDialFunc dialFunc, fallbackDialFunc dialFunc, network
}
l.Debugf("Dialing %s address %s via proxy - error %s", network, addr, err)
if noFallback {
return conn, err
}
conn, err = fallbackDialFunc(network, addr)
if err == nil {
l.Debugf("Dialing %s address %s via fallback - success, %s -> %s", network, addr, conn.LocalAddr(), conn.RemoteAddr())