diff --git a/adapter/router.go b/adapter/router.go index 164a8dd3..ec23d931 100644 --- a/adapter/router.go +++ b/adapter/router.go @@ -46,8 +46,6 @@ type Router interface { PackageManager() tun.PackageManager Rules() []Rule - TimeService - ClashServer() ClashServer SetClashServer(server ClashServer) diff --git a/inbound/shadowsocks.go b/inbound/shadowsocks.go index c3318789..822a5f57 100644 --- a/inbound/shadowsocks.go +++ b/inbound/shadowsocks.go @@ -16,6 +16,7 @@ import ( "github.com/sagernet/sing/common/buf" E "github.com/sagernet/sing/common/exceptions" N "github.com/sagernet/sing/common/network" + "github.com/sagernet/sing/common/ntp" ) func NewShadowsocks(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.ShadowsocksInboundOptions) (adapter.Inbound, error) { @@ -68,7 +69,7 @@ func newShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte case common.Contains(shadowaead.List, options.Method): inbound.service, err = shadowaead.NewService(options.Method, nil, options.Password, udpTimeout, inbound.upstreamContextHandler()) case common.Contains(shadowaead_2022.List, options.Method): - inbound.service, err = shadowaead_2022.NewServiceWithPassword(options.Method, options.Password, udpTimeout, inbound.upstreamContextHandler(), router.TimeFunc()) + inbound.service, err = shadowaead_2022.NewServiceWithPassword(options.Method, options.Password, udpTimeout, inbound.upstreamContextHandler(), ntp.TimeFuncFromContext(ctx)) default: err = E.New("unsupported method: ", options.Method) } diff --git a/inbound/shadowsocks_multi.go b/inbound/shadowsocks_multi.go index 3a998e36..6a1baac2 100644 --- a/inbound/shadowsocks_multi.go +++ b/inbound/shadowsocks_multi.go @@ -18,6 +18,7 @@ import ( E "github.com/sagernet/sing/common/exceptions" F "github.com/sagernet/sing/common/format" N "github.com/sagernet/sing/common/network" + "github.com/sagernet/sing/common/ntp" ) var ( @@ -61,7 +62,7 @@ func newShadowsocksMulti(ctx context.Context, router adapter.Router, logger log. options.Password, udpTimeout, adapter.NewUpstreamContextHandler(inbound.newConnection, inbound.newPacketConnection, inbound), - router.TimeFunc(), + ntp.TimeFuncFromContext(ctx), ) } else if common.Contains(shadowaead.List, options.Method) { service, err = shadowaead.NewMultiService[int]( diff --git a/inbound/vmess.go b/inbound/vmess.go index e65c05a0..89f938fc 100644 --- a/inbound/vmess.go +++ b/inbound/vmess.go @@ -19,6 +19,7 @@ import ( F "github.com/sagernet/sing/common/format" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" + "github.com/sagernet/sing/common/ntp" ) var ( @@ -50,7 +51,7 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg users: options.Users, } var serviceOptions []vmess.ServiceOption - if timeFunc := router.TimeFunc(); timeFunc != nil { + if timeFunc := ntp.TimeFuncFromContext(ctx); timeFunc != nil { serviceOptions = append(serviceOptions, vmess.ServiceWithTimeFunc(timeFunc)) } if options.Transport != nil && options.Transport.Type != "" { diff --git a/ntp/service.go b/ntp/service.go index 3ca1de3c..47f84dfc 100644 --- a/ntp/service.go +++ b/ntp/service.go @@ -18,7 +18,7 @@ import ( "github.com/sagernet/sing/common/ntp" ) -var _ adapter.TimeService = (*Service)(nil) +var _ ntp.TimeService = (*Service)(nil) type Service struct { ctx context.Context diff --git a/outbound/vmess.go b/outbound/vmess.go index 48c9d818..a981464b 100644 --- a/outbound/vmess.go +++ b/outbound/vmess.go @@ -18,6 +18,7 @@ import ( E "github.com/sagernet/sing/common/exceptions" M "github.com/sagernet/sing/common/metadata" N "github.com/sagernet/sing/common/network" + "github.com/sagernet/sing/common/ntp" ) var _ adapter.Outbound = (*VMess)(nil) @@ -77,7 +78,7 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg return nil, E.New("unknown packet encoding: ", options.PacketEncoding) } var clientOptions []vmess.ClientOption - if timeFunc := router.TimeFunc(); timeFunc != nil { + if timeFunc := ntp.TimeFuncFromContext(ctx); timeFunc != nil { clientOptions = append(clientOptions, vmess.ClientWithTimeFunc(timeFunc)) } if options.GlobalPadding { diff --git a/route/router.go b/route/router.go index cb1bd366..c34c5368 100644 --- a/route/router.go +++ b/route/router.go @@ -81,7 +81,7 @@ type Router struct { interfaceMonitor tun.DefaultInterfaceMonitor packageManager tun.PackageManager processSearcher process.Searcher - timeService adapter.TimeService + timeService *ntp.Service pauseManager pause.Manager clashServer adapter.ClashServer v2rayServer adapter.V2RayServer @@ -950,13 +950,6 @@ func (r *Router) PackageManager() tun.PackageManager { return r.packageManager } -func (r *Router) TimeFunc() func() time.Time { - if r.timeService == nil { - return nil - } - return r.timeService.TimeFunc() -} - func (r *Router) ClashServer() adapter.ClashServer { return r.clashServer }