mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-06 14:17:23 +02:00
ipn/ipnlocal, net/dns: use slices.Equal to simplify code (#16641)
Signed-off-by: jishudashu <979260390@qq.com>
This commit is contained in:
parent
47b5f10165
commit
23a0398136
@ -2166,7 +2166,7 @@ func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
|
|||||||
es := b.parseWgStatusLocked(s)
|
es := b.parseWgStatusLocked(s)
|
||||||
cc := b.cc
|
cc := b.cc
|
||||||
b.engineStatus = es
|
b.engineStatus = es
|
||||||
needUpdateEndpoints := !endpointsEqual(s.LocalAddrs, b.endpoints)
|
needUpdateEndpoints := !slices.Equal(s.LocalAddrs, b.endpoints)
|
||||||
if needUpdateEndpoints {
|
if needUpdateEndpoints {
|
||||||
b.endpoints = append([]tailcfg.Endpoint{}, s.LocalAddrs...)
|
b.endpoints = append([]tailcfg.Endpoint{}, s.LocalAddrs...)
|
||||||
}
|
}
|
||||||
@ -2192,18 +2192,6 @@ func (b *LocalBackend) broadcastStatusChanged() {
|
|||||||
b.statusLock.Unlock()
|
b.statusLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func endpointsEqual(x, y []tailcfg.Endpoint) bool {
|
|
||||||
if len(x) != len(y) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for i := range x {
|
|
||||||
if x[i] != y[i] {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNotifyCallback sets the function to call when the backend has something to
|
// SetNotifyCallback sets the function to call when the backend has something to
|
||||||
// notify the frontend about. Only one callback can be set at a time, so calling
|
// notify the frontend about. Only one callback can be set at a time, so calling
|
||||||
// this function will replace the previous callback.
|
// this function will replace the previous callback.
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
"slices"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"tailscale.com/control/controlknobs"
|
"tailscale.com/control/controlknobs"
|
||||||
@ -181,19 +182,7 @@ func sameResolverNames(a, b []*dnstype.Resolver) bool {
|
|||||||
if a[i].Addr != b[i].Addr {
|
if a[i].Addr != b[i].Addr {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !sameIPs(a[i].BootstrapResolution, b[i].BootstrapResolution) {
|
if !slices.Equal(a[i].BootstrapResolution, b[i].BootstrapResolution) {
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
func sameIPs(a, b []netip.Addr) bool {
|
|
||||||
if len(a) != len(b) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
for i := range a {
|
|
||||||
if a[i] != b[i] {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user