From d17041621942eef8789ab1d3748cf3718b8061fc Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Thu, 11 Feb 2021 15:37:02 +0000 Subject: [PATCH] Add environment variable XRAY_CONE_DISABLED option --- core/xray.go | 3 ++- proxy/vless/outbound/outbound.go | 4 +++- proxy/vmess/outbound/outbound.go | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/core/xray.go b/core/xray.go index 6208963c..fd8e5c4e 100644 --- a/core/xray.go +++ b/core/xray.go @@ -2,6 +2,7 @@ package core import ( "context" + "os" "reflect" "sync" @@ -179,7 +180,7 @@ func NewWithContext(ctx context.Context, config *Config) (*Instance, error) { } func initInstanceWithConfig(config *Config, server *Instance) (bool, error) { - server.ctx = context.WithValue(server.ctx, "cone", true) + server.ctx = context.WithValue(server.ctx, "cone", os.Getenv("XRAY_CONE_DISABLED") != "true") if config.Transport != nil { features.PrintDeprecatedFeatureWarning("global transport settings") diff --git a/proxy/vless/outbound/outbound.go b/proxy/vless/outbound/outbound.go index 543595f7..48164db3 100644 --- a/proxy/vless/outbound/outbound.go +++ b/proxy/vless/outbound/outbound.go @@ -49,6 +49,7 @@ type Handler struct { serverList *protocol.ServerList serverPicker protocol.ServerPicker policyManager policy.Manager + cone bool } // New creates a new VLess outbound handler. @@ -67,6 +68,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) { serverList: serverList, serverPicker: protocol.NewRoundRobinServerPicker(serverList), policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager), + cone: ctx.Value("cone").(bool), } return handler, nil @@ -176,7 +178,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte clientReader := link.Reader // .(*pipe.Reader) clientWriter := link.Writer // .(*pipe.Writer) - if request.Command == protocol.RequestCommandUDP { + if request.Command == protocol.RequestCommandUDP && h.cone { request.Command = protocol.RequestCommandMux request.Address = net.DomainAddress("v1.mux.cool") request.Port = net.Port(666) diff --git a/proxy/vmess/outbound/outbound.go b/proxy/vmess/outbound/outbound.go index 854f3e8b..0ffa28f8 100644 --- a/proxy/vmess/outbound/outbound.go +++ b/proxy/vmess/outbound/outbound.go @@ -29,6 +29,7 @@ type Handler struct { serverList *protocol.ServerList serverPicker protocol.ServerPicker policyManager policy.Manager + cone bool } // New creates a new VMess outbound handler. @@ -47,6 +48,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) { serverList: serverList, serverPicker: protocol.NewRoundRobinServerPicker(serverList), policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager), + cone: ctx.Value("cone").(bool), } return handler, nil @@ -123,7 +125,7 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte ctx, cancel := context.WithCancel(ctx) timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle) - if request.Command == protocol.RequestCommandUDP { + if request.Command == protocol.RequestCommandUDP && h.cone { request.Command = protocol.RequestCommandMux request.Address = net.DomainAddress("v1.mux.cool") request.Port = net.Port(666)