Browse Source

Add V2RAY_TROJAN_XTLS_SHOW (#391)

When using trojan, you can set the environment variable V2RAY_TROJAN_XTLS_SHOW=true to display the output of XTLS
Arthur Morgan 5 years ago
parent
commit
e2392491d6
3 changed files with 20 additions and 0 deletions
  1. 9 0
      proxy/trojan/client.go
  2. 2 0
      proxy/trojan/protocol.go
  3. 9 0
      proxy/trojan/server.go

+ 9 - 0
proxy/trojan/client.go

@@ -10,6 +10,7 @@ import (
 	"v2ray.com/core/common"
 	"v2ray.com/core/common"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/buf"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
+	"v2ray.com/core/common/platform"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/retry"
 	"v2ray.com/core/common/retry"
 	"v2ray.com/core/common/session"
 	"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
 		} else { // enable XTLS only if making TCP request
 			if xtlsConn, ok := iConn.(*xtls.Conn); ok {
 			if xtlsConn, ok := iConn.(*xtls.Conn); ok {
 				xtlsConn.RPRX = true
 				xtlsConn.RPRX = true
+				xtlsConn.SHOW = trojanXTLSShow
 				connWriter.Flow = account.Flow
 				connWriter.Flow = account.Flow
 				if account.Flow == XRD {
 				if account.Flow == XRD {
 					xtlsConn.DirectMode = true
 					xtlsConn.DirectMode = true
@@ -185,4 +187,11 @@ func init() {
 	common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
 	common.Must(common.RegisterConfig((*ClientConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
 		return NewClient(ctx, config.(*ClientConfig))
 		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
+	}
 }
 }

+ 2 - 0
proxy/trojan/protocol.go

@@ -17,6 +17,8 @@ var (
 		protocol.AddressFamilyByte(0x04, net.AddressFamilyIPv6),
 		protocol.AddressFamilyByte(0x04, net.AddressFamilyIPv6),
 		protocol.AddressFamilyByte(0x03, net.AddressFamilyDomain),
 		protocol.AddressFamilyByte(0x03, net.AddressFamilyDomain),
 	)
 	)
+
+	trojanXTLSShow = false
 )
 )
 
 
 const (
 const (

+ 9 - 0
proxy/trojan/server.go

@@ -15,6 +15,7 @@ import (
 	"v2ray.com/core/common/errors"
 	"v2ray.com/core/common/errors"
 	"v2ray.com/core/common/log"
 	"v2ray.com/core/common/log"
 	"v2ray.com/core/common/net"
 	"v2ray.com/core/common/net"
+	"v2ray.com/core/common/platform"
 	"v2ray.com/core/common/protocol"
 	"v2ray.com/core/common/protocol"
 	udp_proto "v2ray.com/core/common/protocol/udp"
 	udp_proto "v2ray.com/core/common/protocol/udp"
 	"v2ray.com/core/common/retry"
 	"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) {
 	common.Must(common.RegisterConfig((*ServerConfig)(nil), func(ctx context.Context, config interface{}) (interface{}, error) {
 		return NewServer(ctx, config.(*ServerConfig))
 		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.
 // 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 {
 			if xtlsConn, ok := iConn.(*xtls.Conn); ok {
 				xtlsConn.RPRX = true
 				xtlsConn.RPRX = true
+				xtlsConn.SHOW = trojanXTLSShow
 				if clientReader.Flow == XRD {
 				if clientReader.Flow == XRD {
 					xtlsConn.DirectMode = true
 					xtlsConn.DirectMode = true
 				}
 				}