From a62ad44883ee271c2cd57ba665566285e4436aaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 17 Apr 2023 18:22:05 +0800 Subject: [PATCH] Add deadline interface --- route/router.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/route/router.go b/route/router.go index 795e06dc..cb0a60ea 100644 --- a/route/router.go +++ b/route/router.go @@ -31,6 +31,7 @@ import ( "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/buf" "github.com/sagernet/sing/common/bufio" + "github.com/sagernet/sing/common/bufio/deadline" "github.com/sagernet/sing/common/control" E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" @@ -624,6 +625,10 @@ func (r *Router) RouteConnection(ctx context.Context, conn net.Conn, metadata ad r.logger.DebugContext(ctx, "found fakeip domain: ", domain) } + if deadline.NeedAdditionalReadDeadline(conn) { + conn = deadline.NewConn(conn) + } + if metadata.InboundOptions.SniffEnabled { buffer := buf.NewPacket() buffer.FullReset() @@ -729,6 +734,11 @@ func (r *Router) RoutePacketConnection(ctx context.Context, conn N.PacketConn, m r.logger.DebugContext(ctx, "found fakeip domain: ", domain) } + // Currently we don't have deadline usages for UDP connections + /*if deadline.NeedAdditionalReadDeadline(conn) { + conn = deadline.NewPacketConn(bufio.NewNetPacketConn(conn)) + }*/ + if metadata.InboundOptions.SniffEnabled { buffer := buf.NewPacket() buffer.FullReset()