From 310a938511f499b11f9dcc40d4f51db22b8f1ef1 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Wed, 30 Dec 2020 08:10:26 +0000 Subject: [PATCH] VLESS & VMess are not ready to accept FullCone yet --- app/proxyman/inbound/worker.go | 4 +++- common/buf/buffer.go | 2 ++ main/run.go | 24 ++++++++++++++++++++++++ proxy/shadowsocks/server.go | 8 ++++---- proxy/socks/server.go | 8 ++++---- proxy/trojan/server.go | 8 ++++---- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/app/proxyman/inbound/worker.go b/app/proxyman/inbound/worker.go index 4c561977..c42a5b5a 100644 --- a/app/proxyman/inbound/worker.go +++ b/app/proxyman/inbound/worker.go @@ -279,7 +279,9 @@ func (w *udpWorker) callback(b *buf.Buffer, source net.Destination, originalDest src: source, } if originalDest.IsValid() { - //id.dest = originalDest + if !buf.Cone { + id.dest = originalDest + } b.UDP = &originalDest } conn, existing := w.getConnection(id) diff --git a/common/buf/buffer.go b/common/buf/buffer.go index a9745b8e..7f636350 100644 --- a/common/buf/buffer.go +++ b/common/buf/buffer.go @@ -14,6 +14,8 @@ const ( var pool = bytespool.GetPool(Size) +var Cone = true + // Buffer is a recyclable allocation of a byte array. Buffer.Release() recycles // the buffer into an internal buffer pool, in order to recreate a buffer more // quickly. diff --git a/main/run.go b/main/run.go index 4d307f05..d1b929ff 100644 --- a/main/run.go +++ b/main/run.go @@ -13,6 +13,10 @@ import ( "strings" "syscall" + "github.com/golang/protobuf/proto" + + "github.com/xtls/xray-core/app/proxyman" + "github.com/xtls/xray-core/common/buf" "github.com/xtls/xray-core/common/cmdarg" "github.com/xtls/xray-core/common/platform" "github.com/xtls/xray-core/core" @@ -176,6 +180,26 @@ func startXray() (core.Server, error) { return nil, newError("failed to load config files: [", configFiles.String(), "]").Base(err) } + v, t := false, false + for _, outbound := range config.Outbound { + s := strings.ToLower(outbound.ProxySettings.Type) + l := len(s) + if l >= 16 && s[11:16] == "vless" || l >= 16 && s[11:16] == "vmess" { + v = true + continue + } + if l >= 17 && s[11:17] == "trojan" || l >= 22 && s[11:22] == "shadowsocks" { + var m proxyman.SenderConfig + proto.Unmarshal(outbound.SenderSettings.Value, &m) + if m.MultiplexSettings == nil || !m.MultiplexSettings.Enabled { + t = true + } + } + } + if v && !t { + buf.Cone = false + } + server, err := core.New(config) if err != nil { return nil, newError("failed to create server").Base(err) diff --git a/proxy/shadowsocks/server.go b/proxy/shadowsocks/server.go index 13ee9bf7..50e2217e 100644 --- a/proxy/shadowsocks/server.go +++ b/proxy/shadowsocks/server.go @@ -103,7 +103,7 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection } inbound.User = s.user - var dest net.Destination + var dest *net.Destination reader := buf.NewPacketReader(conn) for { @@ -144,12 +144,12 @@ func (s *Server) handlerUDPPayload(ctx context.Context, conn internet.Connection data.UDP = &destination - if dest.Network == 0 { - dest = request.Destination() // JUST FOLLOW THE FIRST PACKET + if !buf.Cone || dest == nil { + dest = &destination } currentPacketCtx = protocol.ContextWithRequestHeader(currentPacketCtx, request) - udpServer.Dispatch(currentPacketCtx, dest, data) + udpServer.Dispatch(currentPacketCtx, *dest, data) } } diff --git a/proxy/socks/server.go b/proxy/socks/server.go index a8b00522..f9013da6 100644 --- a/proxy/socks/server.go +++ b/proxy/socks/server.go @@ -222,7 +222,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection, newError("client UDP connection from ", inbound.Source).WriteToLog(session.ExportIDToError(ctx)) } - var dest net.Destination + var dest *net.Destination reader := buf.NewPacketReader(conn) for { @@ -260,12 +260,12 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn internet.Connection, payload.UDP = &destination - if dest.Network == 0 { - dest = destination // JUST FOLLOW THE FIRST PACKET + if !buf.Cone || dest == nil { + dest = &destination } currentPacketCtx = protocol.ContextWithRequestHeader(currentPacketCtx, request) - udpServer.Dispatch(currentPacketCtx, dest, payload) + udpServer.Dispatch(currentPacketCtx, *dest, payload) } } } diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index cdc5a9a7..c73d4e2f 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -256,7 +256,7 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade inbound := session.InboundFromContext(ctx) user := inbound.User - var dest net.Destination + var dest *net.Destination for { select { @@ -280,12 +280,12 @@ func (s *Server) handleUDPPayload(ctx context.Context, clientReader *PacketReade }) newError("tunnelling request to ", p.Target).WriteToLog(session.ExportIDToError(ctx)) - if dest.Network == 0 { - dest = p.Target // JUST FOLLOW THE FIRST PACKET + if !buf.Cone || dest == nil { + dest = &p.Target } for _, b := range p.Buffer { - udpServer.Dispatch(ctx, dest, b) + udpServer.Dispatch(ctx, *dest, b) } } }