Jim Han 2021-03-01 10:43:27 +08:00 committed by GitHub
parent 4b97edae74
commit 7fb1f65354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import (
"github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net" "github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/net/cnc" "github.com/xtls/xray-core/common/net/cnc"
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/transport/internet" "github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/tls" "github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/pipe" "github.com/xtls/xray-core/transport/pipe"
@ -22,7 +23,7 @@ var (
globalDialerAccess sync.Mutex globalDialerAccess sync.Mutex
) )
func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config) (*http.Client, error) { func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config, sockopt *internet.SocketConfig) (*http.Client, error) {
globalDialerAccess.Lock() globalDialerAccess.Lock()
defer globalDialerAccess.Unlock() defer globalDialerAccess.Unlock()
@ -49,17 +50,24 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C
} }
address := net.ParseAddress(rawHost) address := net.ParseAddress(rawHost)
pconn, err := internet.DialSystem(ctx, net.TCPDestination(address, port), nil) dctx := context.Background()
dctx = session.ContextWithID(dctx, session.IDFromContext(ctx))
dctx = session.ContextWithOutbound(dctx, session.OutboundFromContext(ctx))
pconn, err := internet.DialSystem(dctx, net.TCPDestination(address, port), sockopt)
if err != nil { if err != nil {
newError("failed to dial to " + addr).Base(err).AtError().WriteToLog()
return nil, err return nil, err
} }
cn := gotls.Client(pconn, tlsConfig) cn := gotls.Client(pconn, tlsConfig)
if err := cn.Handshake(); err != nil { if err := cn.Handshake(); err != nil {
newError("failed to dial to " + addr).Base(err).AtError().WriteToLog()
return nil, err return nil, err
} }
if !tlsConfig.InsecureSkipVerify { if !tlsConfig.InsecureSkipVerify {
if err := cn.VerifyHostname(tlsConfig.ServerName); err != nil { if err := cn.VerifyHostname(tlsConfig.ServerName); err != nil {
newError("failed to dial to " + addr).Base(err).AtError().WriteToLog()
return nil, err return nil, err
} }
} }
@ -90,7 +98,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
if tlsConfig == nil { if tlsConfig == nil {
return nil, newError("TLS must be enabled for http transport.").AtWarning() return nil, newError("TLS must be enabled for http transport.").AtWarning()
} }
client, err := getHTTPClient(ctx, dest, tlsConfig) client, err := getHTTPClient(ctx, dest, tlsConfig, streamSettings.SocketSettings)
if err != nil { if err != nil {
return nil, err return nil, err
} }