diff --git a/proxy/trojan/client.go b/proxy/trojan/client.go index 1586aeaf1..0b96abaae 100644 --- a/proxy/trojan/client.go +++ b/proxy/trojan/client.go @@ -10,6 +10,7 @@ import ( "v2ray.com/core/common" "v2ray.com/core/common/buf" "v2ray.com/core/common/net" + "v2ray.com/core/common/platform" "v2ray.com/core/common/protocol" "v2ray.com/core/common/retry" "v2ray.com/core/common/session" @@ -107,6 +108,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter } else { // enable XTLS only if making TCP request if xtlsConn, ok := iConn.(*xtls.Conn); ok { xtlsConn.RPRX = true + xtlsConn.SHOW = trojanXTLSShow connWriter.Flow = account.Flow if account.Flow == XRD { xtlsConn.DirectMode = true @@ -185,4 +187,11 @@ func init() { common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { return NewClient(ctx, config.(*ClientConfig)) })) + + const defaultFlagValue = "NOT_DEFINED_AT_ALL" + + xtlsShow := platform.NewEnvFlag("v2ray.trojan.xtls.show").GetValue(func() string { return defaultFlagValue }) + if xtlsShow == "true" { + trojanXTLSShow = true + } } diff --git a/proxy/trojan/protocol.go b/proxy/trojan/protocol.go index 5c271ae80..35189dafe 100644 --- a/proxy/trojan/protocol.go +++ b/proxy/trojan/protocol.go @@ -17,6 +17,8 @@ var ( protocol.AddressFamilyByte(0x04, net.AddressFamilyIPv6), protocol.AddressFamilyByte(0x03, net.AddressFamilyDomain), ) + + trojanXTLSShow = false ) const ( diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 747401d1a..237e36f42 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -15,6 +15,7 @@ import ( "v2ray.com/core/common/errors" "v2ray.com/core/common/log" "v2ray.com/core/common/net" + "v2ray.com/core/common/platform" "v2ray.com/core/common/protocol" udp_proto "v2ray.com/core/common/protocol/udp" "v2ray.com/core/common/retry" @@ -32,6 +33,13 @@ func init() { common.Must(common.RegisterConfig((*ServerConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) { return NewServer(ctx, config.(*ServerConfig)) })) + + const defaultFlagValue = "NOT_DEFINED_AT_ALL" + + xtlsShow := platform.NewEnvFlag("v2ray.trojan.xtls.show").GetValue(func() string { return defaultFlagValue }) + if xtlsShow == "true" { + trojanXTLSShow = true + } } // Server is an inbound connection handler that handles messages in trojan protocol. @@ -208,6 +216,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet } if xtlsConn, ok := iConn.(*xtls.Conn); ok { xtlsConn.RPRX = true + xtlsConn.SHOW = trojanXTLSShow if clientReader.Flow == XRD { xtlsConn.DirectMode = true }