Revert LRU cache changes

This commit is contained in:
世界 2023-04-19 23:43:14 +08:00
parent d744d03d93
commit 9c6e70b7cc
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 8 additions and 11 deletions

2
go.mod
View file

@ -6,7 +6,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 github.com/fsnotify/fsnotify v1.6.0
github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61 github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97
github.com/sagernet/sing v0.2.4-0.20230418025125-f196b4303e31 github.com/sagernet/sing v0.2.4-0.20230419153323-5fae6fa434c1
golang.org/x/net v0.8.0 golang.org/x/net v0.8.0
golang.org/x/sys v0.7.0 golang.org/x/sys v0.7.0
gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c

4
go.sum
View file

@ -7,8 +7,8 @@ github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61/go.mod h
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 h1:iL5gZI3uFp0X6EslacyapiRz7LLSJyr4RajF/BhMVyE= github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 h1:iL5gZI3uFp0X6EslacyapiRz7LLSJyr4RajF/BhMVyE=
github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY= github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
github.com/sagernet/sing v0.2.4-0.20230418025125-f196b4303e31 h1:qgq8jeY/rbnY9NwYXByO//AP0ByIxnsKUxQx1tOB3W0= github.com/sagernet/sing v0.2.4-0.20230419153323-5fae6fa434c1 h1:CdzNL25lzfVo0NMeghPqsupNsWvkzrbrUt5t8DoDPcQ=
github.com/sagernet/sing v0.2.4-0.20230418025125-f196b4303e31/go.mod h1:Ta8nHnDLAwqySzKhGoKk4ZIB+vJ3GTKj7UPrWYvM+4w= github.com/sagernet/sing v0.2.4-0.20230419153323-5fae6fa434c1/go.mod h1:Ta8nHnDLAwqySzKhGoKk4ZIB+vJ3GTKj7UPrWYvM+4w=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg= github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0= github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=

View file

@ -68,7 +68,7 @@ func NewGVisor(
logger: options.Logger, logger: options.Logger,
} }
if gStack.router != nil { if gStack.router != nil {
gStack.routeMapping = NewRouteMapping(options.Context, options.UDPTimeout) gStack.routeMapping = NewRouteMapping(options.UDPTimeout)
} }
return gStack, nil return gStack, nil
} }

View file

@ -29,7 +29,7 @@ func NewUDPForwarder(ctx context.Context, stack *stack.Stack, handler Handler, u
return &UDPForwarder{ return &UDPForwarder{
ctx: ctx, ctx: ctx,
stack: stack, stack: stack,
udpNat: udpnat.New[netip.AddrPort](ctx, udpTimeout, handler), udpNat: udpnat.New[netip.AddrPort](udpTimeout, handler),
} }
} }

View file

@ -1,8 +1,6 @@
package tun package tun
import ( import (
"context"
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/cache" "github.com/sagernet/sing/common/cache"
) )
@ -11,10 +9,9 @@ type RouteMapping struct {
status *cache.LruCache[RouteSession, RouteAction] status *cache.LruCache[RouteSession, RouteAction]
} }
func NewRouteMapping(ctx context.Context, maxAge int64) *RouteMapping { func NewRouteMapping(maxAge int64) *RouteMapping {
return &RouteMapping{ return &RouteMapping{
status: cache.New( status: cache.New(
cache.WithContext[RouteSession, RouteAction](ctx),
cache.WithAge[RouteSession, RouteAction](maxAge), cache.WithAge[RouteSession, RouteAction](maxAge),
cache.WithUpdateAgeOnGet[RouteSession, RouteAction](), cache.WithUpdateAgeOnGet[RouteSession, RouteAction](),
cache.WithEvict[RouteSession, RouteAction](func(key RouteSession, conn RouteAction) { cache.WithEvict[RouteSession, RouteAction](func(key RouteSession, conn RouteAction) {

View file

@ -65,7 +65,7 @@ func NewSystem(options StackOptions) (Stack, error) {
underPlatform: options.UnderPlatform, underPlatform: options.UnderPlatform,
} }
if stack.router != nil { if stack.router != nil {
stack.routeMapping = NewRouteMapping(options.Context, options.UDPTimeout) stack.routeMapping = NewRouteMapping(options.UDPTimeout)
} }
if len(options.Inet4Address) > 0 { if len(options.Inet4Address) > 0 {
if options.Inet4Address[0].Bits() == 32 { if options.Inet4Address[0].Bits() == 32 {
@ -118,7 +118,7 @@ func (s *System) Start() error {
go s.acceptLoop(tcpListener) go s.acceptLoop(tcpListener)
} }
s.tcpNat = NewNat(s.ctx, time.Second*time.Duration(s.udpTimeout)) s.tcpNat = NewNat(s.ctx, time.Second*time.Duration(s.udpTimeout))
s.udpNat = udpnat.New[netip.AddrPort](s.ctx, s.udpTimeout, s.handler) s.udpNat = udpnat.New[netip.AddrPort](s.udpTimeout, s.handler)
go s.tunLoop() go s.tunLoop()
return nil return nil
} }