From 2b2437bf7c518243c985246ae7bfb1a7fdd58c28 Mon Sep 17 00:00:00 2001 From: Julien Viard de Galbert Date: Fri, 16 Apr 2021 16:53:27 +0200 Subject: [PATCH] Add discoveredEndpointsAreEqual --- pkg/mesh/mesh.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/mesh/mesh.go b/pkg/mesh/mesh.go index 9c2ef11..978aa80 100644 --- a/pkg/mesh/mesh.go +++ b/pkg/mesh/mesh.go @@ -697,7 +697,7 @@ func nodesAreEqual(a, b *Node) bool { // Ignore LastSeen when comparing equality we want to check if the nodes are // equivalent. However, we do want to check if LastSeen has transitioned // between valid and invalid. - return string(a.Key) == string(b.Key) && ipNetsEqual(a.WireGuardIP, b.WireGuardIP) && ipNetsEqual(a.InternalIP, b.InternalIP) && a.Leader == b.Leader && a.Location == b.Location && a.Name == b.Name && subnetsEqual(a.Subnet, b.Subnet) && a.Ready() == b.Ready() && a.PersistentKeepalive == b.PersistentKeepalive + return string(a.Key) == string(b.Key) && ipNetsEqual(a.WireGuardIP, b.WireGuardIP) && ipNetsEqual(a.InternalIP, b.InternalIP) && a.Leader == b.Leader && a.Location == b.Location && a.Name == b.Name && subnetsEqual(a.Subnet, b.Subnet) && a.Ready() == b.Ready() && a.PersistentKeepalive == b.PersistentKeepalive && discoveredEndpointsAreEqual(a.DiscoveredEndpoints, b.DiscoveredEndpoints) } func peersAreEqual(a, b *Peer) bool { @@ -766,6 +766,24 @@ func subnetsEqual(a, b *net.IPNet) bool { return true } +func discoveredEndpointsAreEqual(a, b map[string]*wireguard.Endpoint) bool { + if a == nil && b == nil { + return true + } + if (a != nil) != (b != nil) { + return false + } + if len(a) != len(b) { + return false + } + for k := range a { + if !a[k].Equal(b[k]) { + return false + } + } + return true +} + func linkByIndex(index int) (netlink.Link, error) { link, err := netlink.LinkByIndex(index) if err != nil {