wgengine/magicsock: remove overkill, slow reflect.DeepEqual of NetworkMap

No need to allocate or compare all the fields we don't care about.
This commit is contained in:
Brad Fitzpatrick 2020-07-25 19:37:08 -07:00
parent be3ca5cbfd
commit e298327ba8

View File

@ -1847,8 +1847,20 @@ func (c *Conn) SetDERPMap(dm *tailcfg.DERPMap) {
go c.ReSTUN("derp-map-update") 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 // 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 // It should not use the DERPMap field of NetworkMap; that's
// conditionally sent to SetDERPMap instead. // conditionally sent to SetDERPMap instead.
@ -1856,7 +1868,7 @@ func (c *Conn) SetNetworkMap(nm *controlclient.NetworkMap) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
if reflect.DeepEqual(nm, c.netMap) { if c.netMap != nil && nodesEqual(c.netMap.Peers, nm.Peers) {
return return
} }