ipn/ipnlocal: only call UpdateEndpoints when the endpoints change

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder
2021-09-15 12:10:15 -07:00
committed by Josh Bleecher Snyder
parent 5b02ad16b9
commit 7421ba91ec
2 changed files with 27 additions and 20 deletions

View File

@@ -620,11 +620,16 @@ func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
es := b.parseWgStatusLocked(s)
cc := b.cc
b.engineStatus = es
b.endpoints = append([]tailcfg.Endpoint{}, s.LocalAddrs...)
needUpdateEndpoints := !endpointsEqual(s.LocalAddrs, b.endpoints)
if needUpdateEndpoints {
b.endpoints = append([]tailcfg.Endpoint{}, s.LocalAddrs...)
}
b.mu.Unlock()
if cc != nil {
cc.UpdateEndpoints(0, s.LocalAddrs)
if needUpdateEndpoints {
cc.UpdateEndpoints(0, s.LocalAddrs)
}
b.stateMachine()
}
@@ -635,6 +640,18 @@ func (b *LocalBackend) setWgengineStatus(s *wgengine.Status, err error) {
b.send(ipn.Notify{Engine: &es})
}
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
}
func (b *LocalBackend) SetNotifyCallback(notify func(ipn.Notify)) {
b.mu.Lock()
defer b.mu.Unlock()