CompareDERPMaps returns true if the given DERPMaps are equivalent. Ordering of slices is ignored. If the first map is nil, the second map must also be nil for them to be considered equivalent. If the second map is nil, the first map can be any value and the function will return true.
(a *tailcfg.DERPMap, b *tailcfg.DERPMap)
| 205 | // considered equivalent. If the second map is nil, the first map can be any |
| 206 | // value and the function will return true. |
| 207 | func CompareDERPMaps(a *tailcfg.DERPMap, b *tailcfg.DERPMap) bool { |
| 208 | if a == nil { |
| 209 | return b == nil |
| 210 | } |
| 211 | if b == nil { |
| 212 | return true |
| 213 | } |
| 214 | if len(a.Regions) != len(b.Regions) { |
| 215 | return false |
| 216 | } |
| 217 | if a.OmitDefaultRegions != b.OmitDefaultRegions { |
| 218 | return false |
| 219 | } |
| 220 | |
| 221 | for id, region := range a.Regions { |
| 222 | other, ok := b.Regions[id] |
| 223 | if !ok { |
| 224 | return false |
| 225 | } |
| 226 | if !compareDERPRegions(region, other) { |
| 227 | return false |
| 228 | } |
| 229 | } |
| 230 | return true |
| 231 | } |
| 232 | |
| 233 | func compareDERPRegions(a *tailcfg.DERPRegion, b *tailcfg.DERPRegion) bool { |
| 234 | if a == nil || b == nil { |