http2 tunnel support socks5 proxy from env all_proxy
Signed-off-by: Asutorufa <16442314+Asutorufa@users.noreply.github.com>
This commit is contained in:
parent
5aaab967a3
commit
0ff20abdcd
|
@ -7,6 +7,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/net/proxy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DialEdgeWithH2Mux makes a TLS connection to a Cloudflare edge node
|
// DialEdgeWithH2Mux makes a TLS connection to a Cloudflare edge node
|
||||||
|
@ -17,15 +18,26 @@ func DialEdge(
|
||||||
edgeTCPAddr *net.TCPAddr,
|
edgeTCPAddr *net.TCPAddr,
|
||||||
localIP net.IP,
|
localIP net.IP,
|
||||||
) (net.Conn, error) {
|
) (net.Conn, error) {
|
||||||
// Inherit from parent context so we can cancel (Ctrl-C) while dialing
|
|
||||||
dialCtx, dialCancel := context.WithTimeout(ctx, timeout)
|
|
||||||
defer dialCancel()
|
|
||||||
|
|
||||||
dialer := net.Dialer{}
|
dialer := net.Dialer{}
|
||||||
if localIP != nil {
|
if localIP != nil {
|
||||||
dialer.LocalAddr = &net.TCPAddr{IP: localIP, Port: 0}
|
dialer.LocalAddr = &net.TCPAddr{IP: localIP, Port: 0}
|
||||||
}
|
}
|
||||||
edgeConn, err := dialer.DialContext(dialCtx, "tcp", edgeTCPAddr.String())
|
proxyDialer := proxy.FromEnvironmentUsing(&dialer)
|
||||||
|
|
||||||
|
var edgeConn net.Conn
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctxDialer, ok := proxyDialer.(interface {
|
||||||
|
DialContext(context.Context, string, string) (net.Conn, error)
|
||||||
|
})
|
||||||
|
if ok {
|
||||||
|
// Inherit from parent context so we can cancel (Ctrl-C) while dialing
|
||||||
|
dialCtx, dialCancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer dialCancel()
|
||||||
|
edgeConn, err = ctxDialer.DialContext(dialCtx, "tcp", edgeTCPAddr.String())
|
||||||
|
} else {
|
||||||
|
edgeConn, err = proxyDialer.Dial("tcp", edgeTCPAddr.String())
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, newDialError(err, "DialContext error")
|
return nil, newDialError(err, "DialContext error")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue