From 2acd206821d52cbd43e5bda20fac35ad0c6526a7 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Mon, 1 Sep 2025 10:47:22 -0400 Subject: [PATCH] Direct/Freedom outbound: Use proxy.IsRAWTransport(conn) (#5074) --- proxy/freedom/freedom.go | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index f8d64812..9429e27a 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -26,7 +26,6 @@ import ( "github.com/xtls/xray-core/transport" "github.com/xtls/xray-core/transport/internet" "github.com/xtls/xray-core/transport/internet/stat" - "github.com/xtls/xray-core/transport/internet/tls" ) var useSplice bool @@ -212,16 +211,14 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte responseDone := func() error { defer timer.SetTimeout(plcy.Timeouts.UplinkOnly) - if destination.Network == net.Network_TCP { + if destination.Network == net.Network_TCP && useSplice && proxy.IsRAWTransport(conn) { // it would be tls conn in special use case of MITM, we need to let link handle traffic var writeConn net.Conn var inTimer *signal.ActivityTimer - if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Conn != nil && useSplice { + if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Conn != nil { writeConn = inbound.Conn inTimer = inbound.Timer } - if !isTLSConn(conn) { // it would be tls conn in special use case of MITM, we need to let link handle traffic - return proxy.CopyRawConnIfExist(ctx, conn, writeConn, link.Writer, timer, inTimer) - } + return proxy.CopyRawConnIfExist(ctx, conn, writeConn, link.Writer, timer, inTimer) } var reader buf.Reader if destination.Network == net.Network_TCP { @@ -246,22 +243,6 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte return nil } -func isTLSConn(conn stat.Connection) bool { - if conn != nil { - statConn, ok := conn.(*stat.CounterConnection) - if ok { - conn = statConn.Connection - } - if _, ok := conn.(*tls.Conn); ok { - return true - } - if _, ok := conn.(*tls.UConn); ok { - return true - } - } - return false -} - func NewPacketReader(conn net.Conn, UDPOverride net.Destination, DialDest net.Destination) buf.Reader { iConn := conn statConn, ok := iConn.(*stat.CounterConnection)