github.com/Uhtred009/v2ray-core-1@v4.31.2+incompatible/transport/internet/tcp/dialer.go (about) 1 // +build !confonly 2 3 package tcp 4 5 import ( 6 "context" 7 8 "v2ray.com/core/common" 9 "v2ray.com/core/common/net" 10 "v2ray.com/core/common/session" 11 "v2ray.com/core/transport/internet" 12 "v2ray.com/core/transport/internet/tls" 13 "v2ray.com/core/transport/internet/xtls" 14 ) 15 16 // Dial dials a new TCP connection to the given destination. 17 func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.MemoryStreamConfig) (internet.Connection, error) { 18 newError("dialing TCP to ", dest).WriteToLog(session.ExportIDToError(ctx)) 19 conn, err := internet.DialSystem(ctx, dest, streamSettings.SocketSettings) 20 if err != nil { 21 return nil, err 22 } 23 24 if config := tls.ConfigFromStreamSettings(streamSettings); config != nil { 25 tlsConfig := config.GetTLSConfig(tls.WithDestination(dest)) 26 /* 27 if config.IsExperiment8357() { 28 conn = tls.UClient(conn, tlsConfig) 29 } else { 30 conn = tls.Client(conn, tlsConfig) 31 } 32 */ 33 conn = tls.Client(conn, tlsConfig) 34 } else if config := xtls.ConfigFromStreamSettings(streamSettings); config != nil { 35 xtlsConfig := config.GetXTLSConfig(xtls.WithDestination(dest)) 36 conn = xtls.Client(conn, xtlsConfig) 37 } 38 39 tcpSettings := streamSettings.ProtocolSettings.(*Config) 40 if tcpSettings.HeaderSettings != nil { 41 headerConfig, err := tcpSettings.HeaderSettings.GetInstance() 42 if err != nil { 43 return nil, newError("failed to get header settings").Base(err).AtError() 44 } 45 auth, err := internet.CreateConnectionAuthenticator(headerConfig) 46 if err != nil { 47 return nil, newError("failed to create header authenticator").Base(err).AtError() 48 } 49 conn = auth.Client(conn) 50 } 51 return internet.Connection(conn), nil 52 } 53 54 func init() { 55 common.Must(internet.RegisterTransportDialer(protocolName, Dial)) 56 }