From e298327ba8d7027808a202538b3f9529842cd196 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 25 Jul 2020 19:37:08 -0700 Subject: [PATCH] wgengine/magicsock: remove overkill, slow reflect.DeepEqual of NetworkMap No need to allocate or compare all the fields we don't care about. --- wgengine/magicsock/magicsock.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index c7902a35d..248c3f5e1 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -1847,8 +1847,20 @@ func (c *Conn) SetDERPMap(dm *tailcfg.DERPMap) { go c.ReSTUN("derp-map-update") } +func nodesEqual(x, y []*tailcfg.Node) bool { + if len(x) != len(y) { + return false + } + for i := range x { + if !x[i].Equal(y[i]) { + return false + } + } + return true +} + // SetNetworkMap is called when the control client gets a new network -// map from the control server. +// map from the control server. It must always be non-nil. // // It should not use the DERPMap field of NetworkMap; that's // conditionally sent to SetDERPMap instead. @@ -1856,7 +1868,7 @@ func (c *Conn) SetNetworkMap(nm *controlclient.NetworkMap) { c.mu.Lock() defer c.mu.Unlock() - if reflect.DeepEqual(nm, c.netMap) { + if c.netMap != nil && nodesEqual(c.netMap.Peers, nm.Peers) { return }