From 9fdfc06f6e9954d12faa853889df7715fe237f16 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Thu, 26 Oct 2023 09:07:49 +0800 Subject: [PATCH] chore: cleanup error using of dialer.DefaultInterface --- common/atomic/value.go | 7 +++++++ config/config.go | 2 -- dns/client.go | 7 +++---- dns/dhcp.go | 3 +-- dns/resolver.go | 3 +-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/common/atomic/value.go b/common/atomic/value.go index 95733533..708fcf90 100644 --- a/common/atomic/value.go +++ b/common/atomic/value.go @@ -12,6 +12,7 @@ func DefaultValue[T any]() T { type TypedValue[T any] struct { value atomic.Value + _ noCopy } func (t *TypedValue[T]) Load() T { @@ -55,3 +56,9 @@ func NewTypedValue[T any](t T) (v TypedValue[T]) { v.Store(t) return } + +type noCopy struct{} + +// Lock is a no-op used by -copylocks checker from `go vet`. +func (*noCopy) Lock() {} +func (*noCopy) Unlock() {} diff --git a/config/config.go b/config/config.go index 97a193a1..994f897d 100644 --- a/config/config.go +++ b/config/config.go @@ -20,7 +20,6 @@ import ( N "github.com/Dreamacro/clash/common/net" "github.com/Dreamacro/clash/common/utils" "github.com/Dreamacro/clash/component/auth" - "github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/fakeip" "github.com/Dreamacro/clash/component/geodata" "github.com/Dreamacro/clash/component/geodata/router" @@ -1048,7 +1047,6 @@ func parseNameServer(servers []string, preferH3 bool) ([]dns.NameServer, error) Net: dnsNetType, Addr: addr, ProxyName: proxyName, - Interface: dialer.DefaultInterface, Params: params, PreferH3: preferH3, }, diff --git a/dns/client.go b/dns/client.go index f228b08e..5cdd1ec0 100644 --- a/dns/client.go +++ b/dns/client.go @@ -8,7 +8,6 @@ import ( "net/netip" "strings" - "github.com/Dreamacro/clash/common/atomic" "github.com/Dreamacro/clash/component/ca" "github.com/Dreamacro/clash/component/dialer" "github.com/Dreamacro/clash/component/resolver" @@ -23,7 +22,7 @@ type client struct { r *Resolver port string host string - iface atomic.TypedValue[string] + iface string proxyAdapter C.ProxyAdapter proxyName string addr string @@ -74,8 +73,8 @@ func (c *client) ExchangeContext(ctx context.Context, m *D.Msg) (*D.Msg, error) } var options []dialer.Option - if c.iface.Load() != "" { - options = append(options, dialer.WithInterface(c.iface.Load())) + if c.iface != "" { + options = append(options, dialer.WithInterface(c.iface)) } conn, err := getDialHandler(c.r, c.proxyAdapter, c.proxyName, options...)(ctx, network, net.JoinHostPort(ip.String(), c.port)) diff --git a/dns/dhcp.go b/dns/dhcp.go index e0373ab4..2fa2e8a4 100644 --- a/dns/dhcp.go +++ b/dns/dhcp.go @@ -8,7 +8,6 @@ import ( "sync" "time" - "github.com/Dreamacro/clash/common/atomic" "github.com/Dreamacro/clash/component/dhcp" "github.com/Dreamacro/clash/component/iface" D "github.com/miekg/dns" @@ -77,7 +76,7 @@ func (d *dhcpClient) resolve(ctx context.Context) ([]dnsClient, error) { for _, item := range dns { nameserver = append(nameserver, NameServer{ Addr: net.JoinHostPort(item.String(), "53"), - Interface: atomic.NewTypedValue(d.ifaceName), + Interface: d.ifaceName, }) } diff --git a/dns/resolver.go b/dns/resolver.go index f0183c16..2851f012 100644 --- a/dns/resolver.go +++ b/dns/resolver.go @@ -7,7 +7,6 @@ import ( "strings" "time" - "github.com/Dreamacro/clash/common/atomic" "github.com/Dreamacro/clash/common/cache" "github.com/Dreamacro/clash/component/fakeip" "github.com/Dreamacro/clash/component/geodata/router" @@ -389,7 +388,7 @@ func (r *Resolver) Invalid() bool { type NameServer struct { Net string Addr string - Interface atomic.TypedValue[string] + Interface string ProxyAdapter C.ProxyAdapter ProxyName string Params map[string]string