From ec1160924f51cc39b2ef268f5e71acd279492bb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 7 Jul 2023 12:48:26 +0800 Subject: [PATCH] Fix save FakeIP cache --- route/router.go | 2 +- transport/fakeip/store.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/route/router.go b/route/router.go index 84a7050d..c23c8a45 100644 --- a/route/router.go +++ b/route/router.go @@ -252,7 +252,7 @@ func NewRouter( if fakeIPOptions.Inet6Range != nil { inet6Range = fakeIPOptions.Inet6Range.Build() } - router.fakeIPStore = fakeip.NewStore(router, inet4Range, inet6Range) + router.fakeIPStore = fakeip.NewStore(router, router.logger, inet4Range, inet6Range) } usePlatformDefaultInterfaceMonitor := platformInterface != nil && platformInterface.UsePlatformDefaultInterfaceMonitor() diff --git a/transport/fakeip/store.go b/transport/fakeip/store.go index b2f4c898..c731979e 100644 --- a/transport/fakeip/store.go +++ b/transport/fakeip/store.go @@ -6,12 +6,14 @@ import ( "github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-dns" E "github.com/sagernet/sing/common/exceptions" + "github.com/sagernet/sing/common/logger" ) var _ adapter.FakeIPStore = (*Store)(nil) type Store struct { router adapter.Router + logger logger.Logger inet4Range netip.Prefix inet6Range netip.Prefix storage adapter.FakeIPStorage @@ -19,9 +21,10 @@ type Store struct { inet6Current netip.Addr } -func NewStore(router adapter.Router, inet4Range netip.Prefix, inet6Range netip.Prefix) *Store { +func NewStore(router adapter.Router, logger logger.Logger, inet4Range netip.Prefix, inet6Range netip.Prefix) *Store { return &Store{ router: router, + logger: logger, inet4Range: inet4Range, inet6Range: inet6Range, } @@ -92,10 +95,12 @@ func (s *Store) Create(domain string, strategy dns.DomainStrategy) (netip.Addr, s.inet6Current = nextAddress address = nextAddress } - err := s.storage.FakeIPStore(address, domain) - if err != nil { - return netip.Addr{}, err - } + go func() { + err := s.storage.FakeIPStore(address, domain) + if err != nil { + s.logger.Warn("save FakeIP address pair: ", err) + } + }() return address, nil }