From 8ffc43035179964e8472486339b220ffccafed29 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+rprx@users.noreply.github.com> Date: Sat, 23 Jan 2021 21:06:15 +0000 Subject: [PATCH] Fix VLESS & Trojan fallbacks xver --- proxy/trojan/server.go | 23 ++++++++++------------- proxy/vless/inbound/inbound.go | 23 ++++++++++------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/proxy/trojan/server.go b/proxy/trojan/server.go index 1d64b442..e274b05c 100644 --- a/proxy/trojan/server.go +++ b/proxy/trojan/server.go @@ -500,19 +500,16 @@ func (s *Server) fallback(ctx context.Context, sid errors.ExportOption, err erro postRequest := func() error { defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly) if fb.Xver != 0 { - var remoteAddr, remotePort, localAddr, localPort string - ipType, network := 0, connection.RemoteAddr().Network() - if len(network) >= 3 && network[:3] == "tcp" { - var err error - remoteAddr, remotePort, err = net.SplitHostPort(connection.RemoteAddr().String()) - if err != nil { - return err - } - localAddr, localPort, err = net.SplitHostPort(connection.LocalAddr().String()) - if err != nil { - return err - } - ipType = 4 + ipType := 4 + remoteAddr, remotePort, err := net.SplitHostPort(connection.RemoteAddr().String()) + if err != nil { + ipType = 0 + } + localAddr, localPort, err := net.SplitHostPort(connection.LocalAddr().String()) + if err != nil { + ipType = 0 + } + if ipType == 4 { for i := 0; i < len(remoteAddr); i++ { if remoteAddr[i] == ':' { ipType = 6 diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index d73107d1..073ff279 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -335,19 +335,16 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection i postRequest := func() error { defer timer.SetTimeout(sessionPolicy.Timeouts.DownlinkOnly) if fb.Xver != 0 { - var remoteAddr, remotePort, localAddr, localPort string - ipType, network := 0, connection.RemoteAddr().Network() - if len(network) >= 3 && network[:3] == "tcp" { - var err error - remoteAddr, remotePort, err = net.SplitHostPort(connection.RemoteAddr().String()) - if err != nil { - return err - } - localAddr, localPort, err = net.SplitHostPort(connection.LocalAddr().String()) - if err != nil { - return err - } - ipType = 4 + ipType := 4 + remoteAddr, remotePort, err := net.SplitHostPort(connection.RemoteAddr().String()) + if err != nil { + ipType = 0 + } + localAddr, localPort, err := net.SplitHostPort(connection.LocalAddr().String()) + if err != nil { + ipType = 0 + } + if ipType == 4 { for i := 0; i < len(remoteAddr); i++ { if remoteAddr[i] == ':' { ipType = 6