mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 07:12:27 +00:00
lib/dialer: Register dialer for socks URL scheme (fixes #4515)
GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4579
This commit is contained in:
parent
8fd2937a58
commit
ece1defb2f
@ -21,8 +21,8 @@ import (
|
||||
|
||||
var (
|
||||
l = logger.DefaultLogger.NewFacility("dialer", "Dialing connections")
|
||||
proxyDialer = getDialer(proxy.Direct)
|
||||
usingProxy = proxyDialer != proxy.Direct
|
||||
proxyDialer proxy.Dialer
|
||||
usingProxy bool
|
||||
noFallback = os.Getenv("ALL_PROXY_NO_FALLBACK") != ""
|
||||
)
|
||||
|
||||
@ -30,6 +30,11 @@ type dialFunc func(network, addr string) (net.Conn, error)
|
||||
|
||||
func init() {
|
||||
l.SetDebug("dialer", strings.Contains(os.Getenv("STTRACE"), "dialer") || os.Getenv("STTRACE") == "all")
|
||||
|
||||
proxy.RegisterDialerType("socks", socksDialerFunction)
|
||||
proxyDialer = getDialer(proxy.Direct)
|
||||
usingProxy = proxyDialer != proxy.Direct
|
||||
|
||||
if usingProxy {
|
||||
http.DefaultTransport = &http.Transport{
|
||||
Dial: Dial,
|
||||
@ -78,6 +83,20 @@ func dialWithFallback(proxyDialFunc dialFunc, fallbackDialFunc dialFunc, network
|
||||
return conn, err
|
||||
}
|
||||
|
||||
// This is a rip off of proxy.FromURL for "socks" URL scheme
|
||||
func socksDialerFunction(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error) {
|
||||
var auth *proxy.Auth
|
||||
if u.User != nil {
|
||||
auth = new(proxy.Auth)
|
||||
auth.User = u.User.Username()
|
||||
if p, ok := u.User.Password(); ok {
|
||||
auth.Password = p
|
||||
}
|
||||
}
|
||||
|
||||
return proxy.SOCKS5("tcp", u.Host, auth, forward)
|
||||
}
|
||||
|
||||
// This is a rip off of proxy.FromEnvironment with a custom forward dialer
|
||||
func getDialer(forward proxy.Dialer) proxy.Dialer {
|
||||
allProxy := os.Getenv("all_proxy")
|
||||
|
Loading…
Reference in New Issue
Block a user