From d42354ab192ac8634fc7cd42660f7f2c6ffe5ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 3 May 2022 16:23:34 +0800 Subject: [PATCH] Fixes --- cli/portal/portal-v2board/main.go | 16 +-- cli/ss-local/main.go | 18 +-- cli/trojan-local/main.go | 16 +-- cli/trojan-server/main.go | 14 +-- common/cache/cache.go | 106 ------------------ common/cache/cache_test.go | 70 ------------ common/cache/lrucache.go | 68 +++++++++-- common/exceptions/error.go | 9 +- common/geosite/matcher.go | 2 +- common/metadata/addr.go | 8 +- common/udpnat/service.go | 27 ++++- go.mod | 21 ++-- go.sum | 36 +++--- protocol/shadowsocks/none.go | 2 +- protocol/shadowsocks/shadowaead/service.go | 12 +- .../shadowsocks/shadowaead_2022/service.go | 19 ++-- protocol/socks/conn.go | 2 +- protocol/socks/protocol.go | 4 +- transport/mixed/listener.go | 2 +- 19 files changed, 159 insertions(+), 293 deletions(-) delete mode 100644 common/cache/cache.go delete mode 100644 common/cache/cache_test.go diff --git a/cli/portal/portal-v2board/main.go b/cli/portal/portal-v2board/main.go index c7f14af..c13ca27 100644 --- a/cli/portal/portal-v2board/main.go +++ b/cli/portal/portal-v2board/main.go @@ -130,7 +130,7 @@ func (i *TrojanInstance) Start() error { trojanConfig, err := i.GetTrojanConfig(context.Background()) if err != nil { - return E.CauseF(err, i.id, ": read trojan config") + return E.Cause(err, i.id, ": read trojan config") } if trojanConfig.SNI != "" { @@ -140,7 +140,7 @@ func (i *TrojanInstance) Start() error { if acmeManager != nil { certificate, err := acmeManager.GetKeyPair(i.domain) if err != nil { - return E.CauseF(err, i.id, ": generate certificate") + return E.Cause(err, i.id, ": generate certificate") } i.tlsConfig.Certificates = []tls.Certificate{*certificate} acmeManager.RegisterUpdateListener(i.domain, func(certificate *tls.Certificate) { @@ -152,7 +152,7 @@ func (i *TrojanInstance) Start() error { Port: int(trojanConfig.LocalPort), }) if err != nil { - return E.CauseF(err, i.id, ": listen at tcp:", trojanConfig.LocalPort, ", check server configuration!") + return E.Cause(err, i.id, ": listen at tcp:", trojanConfig.LocalPort, ", check server configuration!") } if common.IsEmpty(i.tlsConfig.Certificates) { @@ -199,7 +199,7 @@ func (i *TrojanInstance) loopRequests() { for { conn, err := i.listener.Accept() if err != nil { - logrus.Debug(E.CauseF(err, i.id, ": listener exited")) + logrus.Debug(E.Cause(err, i.id, ": listener exited")) return } go func() { @@ -218,13 +218,13 @@ func (i *TrojanInstance) loopReload() { for range i.reloadTicker.C { err := i.reloadUsers() if err != nil { - i.HandleError(E.CauseF(err, "reload user")) + i.HandleError(E.Cause(err, "reload user")) } traffics := i.user.ReadTraffics() if len(traffics) > 0 { err = i.ReportTrojanTraffic(context.Background(), traffics) if err != nil { - i.HandleError(E.CauseF(err, "report traffic")) + i.HandleError(E.Cause(err, "report traffic")) } } } @@ -234,7 +234,7 @@ func (i *TrojanInstance) reloadUsers() error { logrus.Debug(i.id, ": fetching users...") userList, err := i.GetTrojanUserList(context.Background()) if err != nil { - return E.CauseF(err, i.id, ": get user list") + return E.Cause(err, i.id, ": get user list") } if len(userList.Users) == 0 { logrus.Warn(i.id, ": empty users") @@ -244,7 +244,7 @@ func (i *TrojanInstance) reloadUsers() error { for id, password := range userList.Users { err = i.service.AddUser(id, password) if err != nil { - logrus.Warn(E.CauseF(err, i.id, ": add user")) + logrus.Warn(E.Cause(err, i.id, ": add user")) } } diff --git a/cli/ss-local/main.go b/cli/ss-local/main.go index ee66599..0a72171 100644 --- a/cli/ss-local/main.go +++ b/cli/ss-local/main.go @@ -69,24 +69,24 @@ func main() { }, } - command.Flags().StringVarP(&f.Server, "server", "s", "", "Set the server’s hostname or IP.") - command.Flags().Uint16VarP(&f.ServerPort, "server-port", "p", 0, "Set the server’s port number.") - command.Flags().StringVarP(&f.Bind, "local-address", "b", "", "Set the local address.") - command.Flags().Uint16VarP(&f.LocalPort, "local-port", "l", 0, "Set the local port number.") - command.Flags().StringVarP(&f.Password, "password", "k", "", "Set the password. The server and the client should use the same password.") - command.Flags().StringVar(&f.Key, "key", "", "Set the key directly. The key should be encoded with URL-safe Base64.") + command.Flags().StringVarP(&f.Server, "server", "s", "", "Store the server’s hostname or IP.") + command.Flags().Uint16VarP(&f.ServerPort, "server-port", "p", 0, "Store the server’s port number.") + command.Flags().StringVarP(&f.Bind, "local-address", "b", "", "Store the local address.") + command.Flags().Uint16VarP(&f.LocalPort, "local-port", "l", 0, "Store the local port number.") + command.Flags().StringVarP(&f.Password, "password", "k", "", "Store the password. The server and the client should use the same password.") + command.Flags().StringVar(&f.Key, "key", "", "Store the key directly. The key should be encoded with URL-safe Base64.") var supportedCiphers []string supportedCiphers = append(supportedCiphers, shadowsocks.MethodNone) supportedCiphers = append(supportedCiphers, shadowaead_2022.List...) supportedCiphers = append(supportedCiphers, shadowaead.List...) - command.Flags().StringVarP(&f.Method, "encrypt-method", "m", "", "Set the cipher.\n\nSupported ciphers:\n\n"+strings.Join(supportedCiphers, "\n")) + command.Flags().StringVarP(&f.Method, "encrypt-method", "m", "", "Store the cipher.\n\nSupported ciphers:\n\n"+strings.Join(supportedCiphers, "\n")) command.Flags().BoolVar(&f.TCPFastOpen, "fast-open", false, `Enable TCP fast open. Only available with Linux kernel > 3.7.0.`) command.Flags().StringVarP(&f.Transproxy, "transproxy", "t", "", "Enable transparent proxy support. [possible values: redirect, tproxy]") - command.Flags().IntVar(&f.FWMark, "fwmark", 0, "Set outbound socket mark.") - command.Flags().StringVar(&f.Bypass, "bypass", "", "Set bypass country.") + command.Flags().IntVar(&f.FWMark, "fwmark", 0, "Store outbound socket mark.") + command.Flags().StringVar(&f.Bypass, "bypass", "", "Store bypass country.") command.Flags().StringVarP(&f.ConfigFile, "config", "c", "", "Use a configuration file.") command.Flags().BoolVarP(&f.Verbose, "verbose", "v", false, "Enable verbose mode.") command.Flags().BoolVar(&f.UseSystemRNG, "use-system-rng", false, "Use system random number generator.") diff --git a/cli/trojan-local/main.go b/cli/trojan-local/main.go index 73b92e5..50de22a 100644 --- a/cli/trojan-local/main.go +++ b/cli/trojan-local/main.go @@ -54,15 +54,15 @@ func main() { }, } - command.Flags().StringVarP(&f.Server, "server", "s", "", "Set the server’s hostname or IP.") - command.Flags().Uint16VarP(&f.ServerPort, "server-port", "p", 0, "Set the server’s port number.") - command.Flags().StringVarP(&f.ServerName, "server-name", "n", "", "Set the server name.") - command.Flags().StringVarP(&f.Bind, "local-address", "b", "", "Set the local address.") - command.Flags().Uint16VarP(&f.LocalPort, "local-port", "l", 0, "Set the local port number.") - command.Flags().StringVarP(&f.Password, "password", "k", "", "Set the password. The server and the client should use the same password.") - command.Flags().BoolVarP(&f.Insecure, "insecure", "i", false, "Set insecure.") + command.Flags().StringVarP(&f.Server, "server", "s", "", "Store the server’s hostname or IP.") + command.Flags().Uint16VarP(&f.ServerPort, "server-port", "p", 0, "Store the server’s port number.") + command.Flags().StringVarP(&f.ServerName, "server-name", "n", "", "Store the server name.") + command.Flags().StringVarP(&f.Bind, "local-address", "b", "", "Store the local address.") + command.Flags().Uint16VarP(&f.LocalPort, "local-port", "l", 0, "Store the local port number.") + command.Flags().StringVarP(&f.Password, "password", "k", "", "Store the password. The server and the client should use the same password.") + command.Flags().BoolVarP(&f.Insecure, "insecure", "i", false, "Store insecure.") command.Flags().StringVarP(&f.ConfigFile, "config", "c", "", "Use a configuration file.") - command.Flags().BoolVarP(&f.Verbose, "verbose", "v", false, "Set verbose mode.") + command.Flags().BoolVarP(&f.Verbose, "verbose", "v", false, "Store verbose mode.") err := command.Execute() if err != nil { diff --git a/cli/trojan-server/main.go b/cli/trojan-server/main.go index 3776714..6cd3d15 100644 --- a/cli/trojan-server/main.go +++ b/cli/trojan-server/main.go @@ -54,14 +54,14 @@ func main() { }, } - command.Flags().StringVarP(&f.Server, "server", "s", "", "Set the server’s hostname or IP.") - command.Flags().Uint16VarP(&f.ServerPort, "server-port", "p", 0, "Set the server’s port number.") - command.Flags().StringVarP(&f.Bind, "local-address", "b", "", "Set the local address.") - command.Flags().Uint16VarP(&f.LocalPort, "local-port", "l", 0, "Set the local port number.") - command.Flags().StringVarP(&f.Password, "password", "k", "", "Set the password. The server and the client should use the same password.") - command.Flags().BoolVarP(&f.Insecure, "insecure", "i", false, "Set insecure.") + command.Flags().StringVarP(&f.Server, "server", "s", "", "Store the server’s hostname or IP.") + command.Flags().Uint16VarP(&f.ServerPort, "server-port", "p", 0, "Store the server’s port number.") + command.Flags().StringVarP(&f.Bind, "local-address", "b", "", "Store the local address.") + command.Flags().Uint16VarP(&f.LocalPort, "local-port", "l", 0, "Store the local port number.") + command.Flags().StringVarP(&f.Password, "password", "k", "", "Store the password. The server and the client should use the same password.") + command.Flags().BoolVarP(&f.Insecure, "insecure", "i", false, "Store insecure.") command.Flags().StringVarP(&f.ConfigFile, "config", "c", "", "Use a configuration file.") - command.Flags().BoolVarP(&f.Verbose, "verbose", "v", false, "Set verbose mode.") + command.Flags().BoolVarP(&f.Verbose, "verbose", "v", false, "Store verbose mode.") err := command.Execute() if err != nil { diff --git a/common/cache/cache.go b/common/cache/cache.go deleted file mode 100644 index 6b252c2..0000000 --- a/common/cache/cache.go +++ /dev/null @@ -1,106 +0,0 @@ -package cache - -import ( - "runtime" - "sync" - "time" -) - -// Cache store element with a expired time -type Cache struct { - *cache -} - -type cache struct { - mapping sync.Map - janitor *janitor -} - -type element struct { - Expired time.Time - Payload interface{} -} - -// Put element in Cache with its ttl -func (c *cache) Put(key interface{}, payload interface{}, ttl time.Duration) { - c.mapping.Store(key, &element{ - Payload: payload, - Expired: time.Now().Add(ttl), - }) -} - -// Get element in Cache, and drop when it expired -func (c *cache) Get(key interface{}) interface{} { - item, exist := c.mapping.Load(key) - if !exist { - return nil - } - elm := item.(*element) - // expired - if time.Since(elm.Expired) > 0 { - c.mapping.Delete(key) - return nil - } - return elm.Payload -} - -// GetWithExpire element in Cache with Expire Time -func (c *cache) GetWithExpire(key interface{}) (payload interface{}, expired time.Time) { - item, exist := c.mapping.Load(key) - if !exist { - return - } - elm := item.(*element) - // expired - if time.Since(elm.Expired) > 0 { - c.mapping.Delete(key) - return - } - return elm.Payload, elm.Expired -} - -func (c *cache) cleanup() { - c.mapping.Range(func(k, v interface{}) bool { - key := k.(string) - elm := v.(*element) - if time.Since(elm.Expired) > 0 { - c.mapping.Delete(key) - } - return true - }) -} - -type janitor struct { - interval time.Duration - stop chan struct{} -} - -func (j *janitor) process(c *cache) { - ticker := time.NewTicker(j.interval) - for { - select { - case <-ticker.C: - c.cleanup() - case <-j.stop: - ticker.Stop() - return - } - } -} - -func stopJanitor(c *Cache) { - c.janitor.stop <- struct{}{} -} - -// New return *Cache -func New(interval time.Duration) *Cache { - j := &janitor{ - interval: interval, - stop: make(chan struct{}), - } - c := &cache{janitor: j} - go j.process(c) - C := &Cache{c} - runtime.SetFinalizer(C, stopJanitor) - return C -} diff --git a/common/cache/cache_test.go b/common/cache/cache_test.go deleted file mode 100644 index cf4a391..0000000 --- a/common/cache/cache_test.go +++ /dev/null @@ -1,70 +0,0 @@ -package cache - -import ( - "runtime" - "testing" - "time" - - "github.com/stretchr/testify/assert" -) - -func TestCache_Basic(t *testing.T) { - interval := 200 * time.Millisecond - ttl := 20 * time.Millisecond - c := New(interval) - c.Put("int", 1, ttl) - c.Put("string", "a", ttl) - - i := c.Get("int") - assert.Equal(t, i.(int), 1, "should recv 1") - - s := c.Get("string") - assert.Equal(t, s.(string), "a", "should recv 'a'") -} - -func TestCache_TTL(t *testing.T) { - interval := 200 * time.Millisecond - ttl := 20 * time.Millisecond - now := time.Now() - c := New(interval) - c.Put("int", 1, ttl) - c.Put("int2", 2, ttl) - - i := c.Get("int") - _, expired := c.GetWithExpire("int2") - assert.Equal(t, i.(int), 1, "should recv 1") - assert.True(t, now.Before(expired)) - - time.Sleep(ttl * 2) - i = c.Get("int") - j, _ := c.GetWithExpire("int2") - assert.Nil(t, i, "should recv nil") - assert.Nil(t, j, "should recv nil") -} - -func TestCache_AutoCleanup(t *testing.T) { - interval := 10 * time.Millisecond - ttl := 15 * time.Millisecond - c := New(interval) - c.Put("int", 1, ttl) - - time.Sleep(ttl * 2) - i := c.Get("int") - j, _ := c.GetWithExpire("int") - assert.Nil(t, i, "should recv nil") - assert.Nil(t, j, "should recv nil") -} - -func TestCache_AutoGC(t *testing.T) { - sign := make(chan struct{}) - go func() { - interval := 10 * time.Millisecond - ttl := 15 * time.Millisecond - c := New(interval) - c.Put("int", 1, ttl) - sign <- struct{}{} - }() - - <-sign - runtime.GC() -} diff --git a/common/cache/lrucache.go b/common/cache/lrucache.go index 454a410..45a8f8b 100644 --- a/common/cache/lrucache.go +++ b/common/cache/lrucache.go @@ -9,19 +9,58 @@ import ( "github.com/sagernet/sing/common/list" ) +type Option[K comparable, V any] func(*LruCache[K, V]) + +type EvictCallback[K comparable, V any] func(key K, value V) + +func WithEvict[K comparable, V any](cb EvictCallback[K, V]) Option[K, V] { + return func(l *LruCache[K, V]) { + l.onEvict = cb + } +} + +func WithUpdateAgeOnGet[K comparable, V any]() Option[K, V] { + return func(l *LruCache[K, V]) { + l.updateAgeOnGet = true + } +} + +func WithAge[K comparable, V any](maxAge int64) Option[K, V] { + return func(l *LruCache[K, V]) { + l.maxAge = maxAge + } +} + +func WithSize[K comparable, V any](maxSize int) Option[K, V] { + return func(l *LruCache[K, V]) { + l.maxSize = maxSize + } +} + +func WithStale[K comparable, V any](stale bool) Option[K, V] { + return func(l *LruCache[K, V]) { + l.staleReturn = stale + } +} + type LruCache[K comparable, V any] struct { maxAge int64 + maxSize int mu sync.Mutex cache map[K]*list.Element[*entry[K, V]] lru list.List[*entry[K, V]] // Front is least-recent updateAgeOnGet bool + staleReturn bool + onEvict EvictCallback[K, V] } -func NewLRU[K comparable, V any](maxAge int64, updateAgeOnGet bool) LruCache[K, V] { - lc := LruCache[K, V]{ - maxAge: maxAge, - updateAgeOnGet: updateAgeOnGet, - cache: make(map[K]*list.Element[*entry[K, V]]), +func New[K comparable, V any](options ...Option[K, V]) *LruCache[K, V] { + lc := &LruCache[K, V]{ + cache: make(map[K]*list.Element[*entry[K, V]]), + } + + for _, option := range options { + option(lc) } return lc @@ -111,6 +150,12 @@ func (c *LruCache[K, V]) StoreWithExpire(key K, value V, expires time.Time) { } else { e := &entry[K, V]{key: key, value: value, expires: expires.Unix()} c.cache[key] = c.lru.PushBack(e) + + if c.maxSize > 0 { + if len := c.lru.Len(); len > c.maxSize { + c.deleteElement(c.lru.Front()) + } + } } c.maybeDeleteOldest() @@ -141,7 +186,7 @@ func (c *LruCache[K, V]) get(key K) *entry[K, V] { return nil } - if c.maxAge > 0 && le.Value.expires <= time.Now().Unix() { + if !c.staleReturn && c.maxAge > 0 && le.Value.expires <= time.Now().Unix() { c.deleteElement(le) c.maybeDeleteOldest() @@ -168,9 +213,11 @@ func (c *LruCache[K, V]) Delete(key K) { } func (c *LruCache[K, V]) maybeDeleteOldest() { - now := time.Now().Unix() - for le := c.lru.Front(); le != nil && le.Value.expires <= now; le = c.lru.Front() { - c.deleteElement(le) + if !c.staleReturn && c.maxAge > 0 { + now := time.Now().Unix() + for le := c.lru.Front(); le != nil && le.Value.expires <= now; le = c.lru.Front() { + c.deleteElement(le) + } } } @@ -178,6 +225,9 @@ func (c *LruCache[K, V]) deleteElement(le *list.Element[*entry[K, V]]) { c.lru.Remove(le) e := le.Value delete(c.cache, e.key) + if c.onEvict != nil { + c.onEvict(e.key, e.value) + } } type entry[K comparable, V any] struct { diff --git a/common/exceptions/error.go b/common/exceptions/error.go index 95c0cb6..6c86d1a 100644 --- a/common/exceptions/error.go +++ b/common/exceptions/error.go @@ -42,14 +42,7 @@ func New(message ...any) error { return errors.New(fmt.Sprint(message...)) } -func Cause(cause error, message string) Exception { - if cause == nil { - return nil - } - return exception{message, cause} -} - -func CauseF(cause error, message ...any) Exception { +func Cause(cause error, message ...any) Exception { return exception{fmt.Sprint(message), cause} } diff --git a/common/geosite/matcher.go b/common/geosite/matcher.go index 50cd330..e5c402d 100644 --- a/common/geosite/matcher.go +++ b/common/geosite/matcher.go @@ -37,7 +37,7 @@ func NewMatcher(domains []string) (*Matcher, error) { domain = domain[7:] pattern, err := regexp.Compile(domain) if err != nil { - return nil, E.CauseF(err, "compile regex rule ", domain) + return nil, E.Cause(err, "compile regex rule ", domain) } regex = append(regex, pattern) } diff --git a/common/metadata/addr.go b/common/metadata/addr.go index c0575ca..9b930f6 100644 --- a/common/metadata/addr.go +++ b/common/metadata/addr.go @@ -107,7 +107,7 @@ func AddrPortFromNetAddr(netAddr net.Addr) *AddrPort { func AddrFromIP(ip net.IP) Addr { addr, _ := netip.AddrFromSlice(ip) - if addr.Is4() { + if addr.Is4() || addr.Is4In6() { return Addr4(addr.As4()) } else { return Addr16(addr.As16()) @@ -115,7 +115,7 @@ func AddrFromIP(ip net.IP) Addr { } func AddrFromAddr(addr netip.Addr) Addr { - if addr.Is4() { + if addr.Is4() && addr.Is4In6() { return Addr4(addr.As4()) } else { return Addr16(addr.As16()) @@ -145,7 +145,7 @@ func (a Addr4) Fqdn() string { } func (a Addr4) String() string { - return net.IP(a[:]).String() + return netip.AddrFrom4(a).String() } type Addr16 [16]byte @@ -163,7 +163,7 @@ func (a Addr16) Fqdn() string { } func (a Addr16) String() string { - return net.IP(a[:]).String() + return netip.AddrFrom16(a).String() } type AddrFqdn string diff --git a/common/udpnat/service.go b/common/udpnat/service.go index 0bc05a5..34f30ea 100644 --- a/common/udpnat/service.go +++ b/common/udpnat/service.go @@ -5,6 +5,7 @@ import ( "io" "net" "os" + "sync" "time" "github.com/sagernet/sing/common" @@ -21,13 +22,16 @@ type Handler interface { } type Service[K comparable] struct { - nat cache.LruCache[K, *conn] + nat *cache.LruCache[K, *conn] handler Handler } -func New[K comparable](maxAge int64, handler Handler) Service[K] { - return Service[K]{ - nat: cache.NewLRU[K, *conn](maxAge, true), +func New[K comparable](maxAge int64, handler Handler) *Service[K] { + return &Service[K]{ + nat: cache.New( + cache.WithAge[K, *conn](maxAge), + cache.WithUpdateAgeOnGet[K, *conn](), + ), handler: handler, } } @@ -52,8 +56,17 @@ func (s *Service[T]) NewContextPacket(ctx context.Context, key T, writer func() if err != nil { s.handler.HandleError(err) } + c.Close() + s.nat.Delete(key) }() } + c.access.Lock() + if common.Done(c.ctx) { + s.nat.Delete(key) + c.access.Unlock() + s.NewContextPacket(ctx, key, writer, buffer, metadata) + return + } ctx, done := context.WithCancel(c.ctx) p := packet{ done: done, @@ -61,6 +74,7 @@ func (s *Service[T]) NewContextPacket(ctx context.Context, key T, writer func() destination: metadata.Destination, } c.data <- p + c.access.Unlock() <-ctx.Done() } @@ -71,6 +85,7 @@ type packet struct { } type conn struct { + access sync.Mutex ctx context.Context cancel context.CancelFunc data chan packet @@ -96,7 +111,11 @@ func (c *conn) WritePacket(buffer *buf.Buffer, destination *M.AddrPort) error { } func (c *conn) Close() error { + c.access.Lock() + defer c.access.Unlock() + c.cancel() + common.Close(c.source) select { case <-c.data: return os.ErrClosed diff --git a/go.mod b/go.mod index 96ca220..1896a97 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/sagernet/sing go 1.18 require ( - github.com/cloudflare/cloudflare-go v0.30.0 + github.com/cloudflare/cloudflare-go v0.38.0 github.com/go-acme/lego/v4 v4.6.0 github.com/go-resty/resty/v2 v2.7.0 github.com/openacid/low v0.1.21 @@ -12,41 +12,36 @@ require ( github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 - github.com/stretchr/testify v1.7.1 github.com/ulikunitz/xz v0.5.10 github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e - github.com/v2fly/v2ray-core/v5 v5.0.3 + github.com/v2fly/v2ray-core/v5 v5.0.5 github.com/vishvananda/netlink v1.1.0 golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 - golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 + golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba golang.zx2c4.com/wireguard v0.0.0-20220407013110-ef5c587f782d google.golang.org/protobuf v1.28.0 lukechampine.com/blake3 v1.1.7 ) require ( + github.com/adrg/xdg v0.4.0 // indirect github.com/cenkalti/backoff/v4 v4.1.1 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect github.com/golang/protobuf v1.5.2 // indirect + github.com/google/go-querystring v1.1.0 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/klauspost/cpuid/v2 v2.0.12 // indirect - github.com/kr/text v0.2.0 // indirect - github.com/miekg/dns v1.1.45 // indirect - github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect + github.com/miekg/dns v1.1.48 // indirect github.com/oschwald/maxminddb-golang v1.9.0 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect - golang.org/x/mod v0.4.2 // indirect + golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect golang.org/x/text v0.3.7 // indirect golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect - golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 // indirect + golang.org/x/tools v0.1.9 // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect - gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect gopkg.in/square/go-jose.v2 v2.6.0 // indirect - gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 7f995eb..197ab62 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OpenDNS/vegadns2client v0.0.0-20180418235048-a3fa4a771d87/go.mod h1:iGLljf5n9GjT6kc0HBvyI1nOKnGQbNB66VzSNbK5iks= +github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls= +github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E= github.com/akamai/AkamaiOPEN-edgegrid-golang v1.1.1/go.mod h1:kX6YddBkXqqywAe8c9LyvgTCyFuZCTMF4cRPQhc3Fy8= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -67,8 +69,8 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/cloudflare-go v0.20.0/go.mod h1:sPWL/lIC6biLEdyGZwBQ1rGQKF1FhM7N60fuNiFdYTI= -github.com/cloudflare/cloudflare-go v0.30.0 h1:ho2ObQ1iZfjMqP9RcovvT1Jwp/ZW4Ji5baWVwl2T//A= -github.com/cloudflare/cloudflare-go v0.30.0/go.mod h1:B55yGpU9NdzhWPYu0CDq8smftKrqB/PSDQAdIBEKApw= +github.com/cloudflare/cloudflare-go v0.38.0 h1:Qf/oVlDmQgb4RfCxqkR0hJoEUQKHvDE4A09MHWssa/w= +github.com/cloudflare/cloudflare-go v0.38.0/go.mod h1:tWDVF03nA9VS9TvFRTrOeY78uSFQzS+n429EcBZszzg= github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= @@ -78,7 +80,6 @@ github.com/cpu/goacmedns v0.1.1/go.mod h1:MuaouqEhPAHxsbqjgnck5zeghuwBP1dLnPoobe github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -159,9 +160,10 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= +github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= +github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -241,8 +243,6 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labbsr0x/bindman-dns-webhook v1.0.2/go.mod h1:p6b+VCXIR8NYKpDr8/dg1HKfQoRHCdcsROXKvmoehKA= github.com/labbsr0x/goh v1.0.1/go.mod h1:8K2UhVoaWXcCU7Lxoa2omWnC8gyW8px7/lmO61c027w= github.com/labstack/echo/v4 v4.2.1/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg= @@ -275,8 +275,8 @@ github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvr github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.43/go.mod h1:+evo5L0630/F6ca/Z9+GAqzhjGyn8/c+TBaOyfEl0V4= -github.com/miekg/dns v1.1.45 h1:g5fRIhm9nx7g8osrAvgb16QJfmyMsyOCb+J7LSv+Qzk= -github.com/miekg/dns v1.1.45/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= +github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ= +github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= @@ -295,8 +295,6 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/namedotcom/go v0.0.0-20180403034216-08470befbe04/go.mod h1:5sN+Lt1CaY4wsPvgQH/jsuJi4XO2ssZbdsIizr4CVC8= github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= -github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nrdcg/auroradns v1.0.1/go.mod h1:y4pc0i9QXYlFCWrhWrUSIETnZgrf4KuwjDIWmmXo3JI= github.com/nrdcg/desec v0.6.0/go.mod h1:wybWg5cRrNmtXLYpUCPCLvz4jfFNEGZQEnoUiX9WqcY= github.com/nrdcg/dnspod-go v0.4.0/go.mod h1:vZSoFSFeQVm2gWLMkyX61LZ8HI3BaqtHZWgPTGKr6KQ= @@ -410,7 +408,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.287/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.287/go.mod h1:CuOaLxOQr477GhMWAQPYQFUJrsZbW+ZqkAgP2uHDZXg= @@ -423,8 +420,8 @@ github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e h1:5QefA066A1tF8gHIiADmOVOV5LS43gt3ONnlEl3xkwI= github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e/go.mod h1:5t19P9LBIrNamL6AcMQOncg/r10y3Pc01AbHeMhwlpU= -github.com/v2fly/v2ray-core/v5 v5.0.3 h1:2rnJ9vZbBQ7V4upWsoUVYGoqZl4grrx8SxOReKx+jjc= -github.com/v2fly/v2ray-core/v5 v5.0.3/go.mod h1:zhDdsUJcNE8LcLRA3l7fEQ6QLuveD4/OLbQM2CceSHM= +github.com/v2fly/v2ray-core/v5 v5.0.5 h1:S9K9F1t9HMzrW3fzVYUu3cAVXArlkrkOnMresObncP0= +github.com/v2fly/v2ray-core/v5 v5.0.5/go.mod h1:Rv8eq9KRQWZt177euFJb7i2MOqrzfokVmuHGhlfo/zw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= @@ -500,8 +497,9 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 h1:LQmS1nU0twXLA96Kt7U9qtHJEbBk3z6Q0V4UXjZkpr4= +golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -605,8 +603,9 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32 h1:Js08h5hqB5xyWR789+QqueR6sDE8mk+YvpETZ+F6X9Y= -golang.org/x/sys v0.0.0-20220429233432-b5fbb4746d32/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba h1:AyHWHCBVlIYI5rgEM3o+1PLd0sLPcIAoaUckGQMaWtw= +golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -662,8 +661,9 @@ golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapK golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= golang.org/x/tools v0.0.0-20200410194907-79a7a3126eef/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2 h1:BonxutuHCTL0rBDnZlKjpGIQFTjyUVTexFOdWkB6Fg0= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.9 h1:j9KsMiaP1c3B0OTQGth0/k+miLGTgLsAFUCrF2vLcF8= +golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -725,8 +725,6 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= -gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE= diff --git a/protocol/shadowsocks/none.go b/protocol/shadowsocks/none.go index 7abd9a5..fa33a1f 100644 --- a/protocol/shadowsocks/none.go +++ b/protocol/shadowsocks/none.go @@ -155,7 +155,7 @@ func (c *nonePacketConn) WritePacket(buffer *buf.Buffer, addrPort *M.AddrPort) e type NoneService struct { handler Handler - udp udpnat.Service[netip.AddrPort] + udp *udpnat.Service[netip.AddrPort] } func NewNoneService(udpTimeout int64, handler Handler) Service { diff --git a/protocol/shadowsocks/shadowaead/service.go b/protocol/shadowsocks/shadowaead/service.go index 0d929d7..608542b 100644 --- a/protocol/shadowsocks/shadowaead/service.go +++ b/protocol/shadowsocks/shadowaead/service.go @@ -27,8 +27,8 @@ type Service struct { key []byte secureRNG io.Reader replayFilter replay.Filter - udpNat udpnat.Service[netip.AddrPort] handler shadowsocks.Handler + udpNat *udpnat.Service[netip.AddrPort] } func NewService(method string, key []byte, password []byte, secureRNG io.Reader, replayFilter bool, udpTimeout int64, handler shadowsocks.Handler) (shadowsocks.Service, error) { @@ -36,8 +36,8 @@ func NewService(method string, key []byte, password []byte, secureRNG io.Reader, name: method, secureRNG: secureRNG, handler: handler, + udpNat: udpnat.New[netip.AddrPort](udpTimeout, handler), } - s.udpNat = udpnat.New[netip.AddrPort](udpTimeout, s) if replayFilter { s.replayFilter = replay.NewBloomRing() } @@ -244,11 +244,3 @@ func (w *serverPacketWriter) WritePacket(buffer *buf.Buffer, destination *M.Addr buffer.Extend(c.Overhead()) return w.PacketConn.WritePacket(buffer, w.source) } - -func (s *Service) NewPacketConnection(ctx context.Context, conn socks.PacketConn, metadata M.Metadata) error { - return s.handler.NewPacketConnection(ctx, conn, metadata) -} - -func (s *Service) HandleError(err error) { - s.handler.HandleError(err) -} diff --git a/protocol/shadowsocks/shadowaead_2022/service.go b/protocol/shadowsocks/shadowaead_2022/service.go index 04bbf90..c973f1c 100644 --- a/protocol/shadowsocks/shadowaead_2022/service.go +++ b/protocol/shadowsocks/shadowaead_2022/service.go @@ -38,8 +38,8 @@ type Service struct { psk [KeySaltSize]byte replayFilter replay.Filter handler shadowsocks.Handler - udpNat udpnat.Service[uint64] - sessions cache.LruCache[uint64, *serverUDPSession] + udpNat *udpnat.Service[uint64] + sessions *cache.LruCache[uint64, *serverUDPSession] } func NewService(method string, psk [KeySaltSize]byte, secureRNG io.Reader, udpTimeout int64, handler shadowsocks.Handler) (shadowsocks.Service, error) { @@ -49,7 +49,11 @@ func NewService(method string, psk [KeySaltSize]byte, secureRNG io.Reader, udpTi secureRNG: secureRNG, replayFilter: replay.NewCuckoo(60), handler: handler, - sessions: cache.NewLRU[uint64, *serverUDPSession](udpTimeout, true), + udpNat: udpnat.New[uint64](udpTimeout, handler), + sessions: cache.New[uint64, *serverUDPSession]( + cache.WithAge[uint64, *serverUDPSession](udpTimeout), + cache.WithUpdateAgeOnGet[uint64, *serverUDPSession](), + ), } switch method { @@ -69,7 +73,6 @@ func NewService(method string, psk [KeySaltSize]byte, secureRNG io.Reader, udpTi s.udpCipher = newXChacha20Poly1305(s.psk[:]) } - s.udpNat = udpnat.New[uint64](udpTimeout, s) return s, nil } @@ -445,11 +448,3 @@ func (m *Service) newUDPSession() *serverUDPSession { } return session } - -func (s *Service) NewPacketConnection(ctx context.Context, conn socks.PacketConn, metadata M.Metadata) error { - return s.handler.NewPacketConnection(ctx, conn, metadata) -} - -func (s *Service) HandleError(err error) { - s.handler.HandleError(err) -} diff --git a/protocol/socks/conn.go b/protocol/socks/conn.go index 63591f4..ba6f5c6 100644 --- a/protocol/socks/conn.go +++ b/protocol/socks/conn.go @@ -15,7 +15,7 @@ type AssociateConn struct { dest *M.AddrPort } -func NewAssociateConn(conn net.Conn, packetConn net.Conn, destination *M.AddrPort) net.PacketConn { +func NewAssociateConn(conn net.Conn, packetConn net.Conn, destination *M.AddrPort) *AssociateConn { return &AssociateConn{ Conn: packetConn, conn: conn, diff --git a/protocol/socks/protocol.go b/protocol/socks/protocol.go index e466df3..08f2ded 100644 --- a/protocol/socks/protocol.go +++ b/protocol/socks/protocol.go @@ -49,7 +49,7 @@ func ReadAuthRequest(reader io.Reader) (*AuthRequest, error) { } methods, err := rw.ReadBytes(reader, int(methodLen)) if err != nil { - return nil, E.CauseF(err, "read socks auth methods, length ", methodLen) + return nil, E.Cause(err, "read socks auth methods, length ", methodLen) } request := &AuthRequest{ version, @@ -65,7 +65,7 @@ func ReadAuthRequest0(reader io.Reader) (*AuthRequest, error) { } methods, err := rw.ReadBytes(reader, int(methodLen)) if err != nil { - return nil, E.CauseF(err, "read socks auth methods, length ", methodLen) + return nil, E.Cause(err, "read socks auth methods, length ", methodLen) } request := &AuthRequest{ Version5, diff --git a/transport/mixed/listener.go b/transport/mixed/listener.go index 819ecec..ad11f9a 100644 --- a/transport/mixed/listener.go +++ b/transport/mixed/listener.go @@ -34,7 +34,7 @@ type Listener struct { bindAddr netip.Addr handler Handler authenticator auth.Authenticator - udpNat udpnat.Service[netip.AddrPort] + udpNat *udpnat.Service[netip.AddrPort] } func NewListener(bind netip.AddrPort, authenticator auth.Authenticator, transproxy redir.TransproxyMode, udpTimeout int64, handler Handler) *Listener {