From 121eb7b4fcd84248381b6415be30e8a385d9f3cc Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sun, 19 May 2024 23:54:36 -0400 Subject: [PATCH] Splice update timer to 8 hours for inbound timer --- proxy/freedom/freedom.go | 4 +++- proxy/proxy.go | 5 ++++- proxy/vless/encoding/encoding.go | 4 +++- proxy/vless/inbound/inbound.go | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/proxy/freedom/freedom.go b/proxy/freedom/freedom.go index 9e6afc9d..29621c0e 100644 --- a/proxy/freedom/freedom.go +++ b/proxy/freedom/freedom.go @@ -219,10 +219,12 @@ func (h *Handler) Process(ctx context.Context, link *transport.Link, dialer inte defer timer.SetTimeout(plcy.Timeouts.UplinkOnly) if destination.Network == net.Network_TCP { var writeConn net.Conn + var inTimer *signal.ActivityTimer if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Conn != nil && useSplice { writeConn = inbound.Conn + inTimer = inbound.Timer } - return proxy.CopyRawConnIfExist(ctx, conn, writeConn, link.Writer, timer) + return proxy.CopyRawConnIfExist(ctx, conn, writeConn, link.Writer, timer, inTimer) } reader := NewPacketReader(conn, UDPOverride) if err := buf.Copy(reader, output, buf.UpdateActivity(timer)); err != nil { diff --git a/proxy/proxy.go b/proxy/proxy.go index ba909197..db920510 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -470,7 +470,7 @@ func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter) { // CopyRawConnIfExist use the most efficient copy method. // - If caller don't want to turn on splice, do not pass in both reader conn and writer conn // - writer are from *transport.Link -func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net.Conn, writer buf.Writer, timer *signal.ActivityTimer) error { +func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net.Conn, writer buf.Writer, timer *signal.ActivityTimer, inTimer *signal.ActivityTimer) error { readerConn, readCounter, _ := UnwrapRawConn(readerConn) writerConn, _, writeCounter := UnwrapRawConn(writerConn) reader := buf.NewReader(readerConn) @@ -510,6 +510,9 @@ func CopyRawConnIfExist(ctx context.Context, readerConn net.Conn, writerConn net //runtime.Gosched() // necessary time.Sleep(time.Millisecond) // without this, there will be a rare ssl error for freedom splice timer.SetTimeout(8 * time.Hour) // prevent leak, just in case + if inTimer != nil { + inTimer.SetTimeout(8 * time.Hour) + } w, err := tc.ReadFrom(readerConn) if readCounter != nil { readCounter.Add(w) // outbound stats diff --git a/proxy/vless/encoding/encoding.go b/proxy/vless/encoding/encoding.go index cb558584..5954746e 100644 --- a/proxy/vless/encoding/encoding.go +++ b/proxy/vless/encoding/encoding.go @@ -179,8 +179,10 @@ func XtlsRead(reader buf.Reader, writer buf.Writer, timer *signal.ActivityTimer, for { if trafficState.ReaderSwitchToDirectCopy { var writerConn net.Conn + var inTimer *signal.ActivityTimer if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Conn != nil { writerConn = inbound.Conn + inTimer = inbound.Timer if inbound.CanSpliceCopy == 2 { inbound.CanSpliceCopy = 1 } @@ -188,7 +190,7 @@ func XtlsRead(reader buf.Reader, writer buf.Writer, timer *signal.ActivityTimer, ob.CanSpliceCopy = 1 } } - return proxy.CopyRawConnIfExist(ctx, conn, writerConn, writer, timer) + return proxy.CopyRawConnIfExist(ctx, conn, writerConn, writer, timer, inTimer) } buffer, err := reader.ReadMultiBuffer() if !buffer.IsEmpty() { diff --git a/proxy/vless/inbound/inbound.go b/proxy/vless/inbound/inbound.go index d44b8c09..1b31751c 100644 --- a/proxy/vless/inbound/inbound.go +++ b/proxy/vless/inbound/inbound.go @@ -502,6 +502,7 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s sessionPolicy = h.policyManager.ForLevel(request.User.Level) ctx, cancel := context.WithCancel(ctx) timer := signal.CancelAfterInactivity(ctx, cancel, sessionPolicy.Timeouts.ConnectionIdle) + inbound.Timer = timer ctx = policy.ContextWithBufferPolicy(ctx, sessionPolicy.Buffer) link, err := dispatcher.Dispatch(ctx, request.Destination())