Skip to content

Commit

Permalink
Revert LRU cache changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Apr 19, 2023
1 parent d744d03 commit 9c6e70b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0
github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61
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/sys v0.7.0
gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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/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.2.4-0.20230418025125-f196b4303e31 h1:qgq8jeY/rbnY9NwYXByO//AP0ByIxnsKUxQx1tOB3W0=
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 h1:CdzNL25lzfVo0NMeghPqsupNsWvkzrbrUt5t8DoDPcQ=
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/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
Expand Down
2 changes: 1 addition & 1 deletion gvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func NewGVisor(
logger: options.Logger,
}
if gStack.router != nil {
gStack.routeMapping = NewRouteMapping(options.Context, options.UDPTimeout)
gStack.routeMapping = NewRouteMapping(options.UDPTimeout)
}
return gStack, nil
}
Expand Down
2 changes: 1 addition & 1 deletion gvisor_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewUDPForwarder(ctx context.Context, stack *stack.Stack, handler Handler, u
return &UDPForwarder{
ctx: ctx,
stack: stack,
udpNat: udpnat.New[netip.AddrPort](ctx, udpTimeout, handler),
udpNat: udpnat.New[netip.AddrPort](udpTimeout, handler),
}
}

Expand Down
5 changes: 1 addition & 4 deletions route_mapping.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package tun

import (
"context"

"github.com/sagernet/sing/common"
"github.com/sagernet/sing/common/cache"
)
Expand All @@ -11,10 +9,9 @@ type RouteMapping struct {
status *cache.LruCache[RouteSession, RouteAction]
}

func NewRouteMapping(ctx context.Context, maxAge int64) *RouteMapping {
func NewRouteMapping(maxAge int64) *RouteMapping {
return &RouteMapping{
status: cache.New(
cache.WithContext[RouteSession, RouteAction](ctx),
cache.WithAge[RouteSession, RouteAction](maxAge),
cache.WithUpdateAgeOnGet[RouteSession, RouteAction](),
cache.WithEvict[RouteSession, RouteAction](func(key RouteSession, conn RouteAction) {
Expand Down
4 changes: 2 additions & 2 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewSystem(options StackOptions) (Stack, error) {
underPlatform: options.UnderPlatform,
}
if stack.router != nil {
stack.routeMapping = NewRouteMapping(options.Context, options.UDPTimeout)
stack.routeMapping = NewRouteMapping(options.UDPTimeout)
}
if len(options.Inet4Address) > 0 {
if options.Inet4Address[0].Bits() == 32 {
Expand Down Expand Up @@ -118,7 +118,7 @@ func (s *System) Start() error {
go s.acceptLoop(tcpListener)
}
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()
return nil
}
Expand Down

0 comments on commit 9c6e70b

Please sign in to comment.