all: use set.Set consistently instead of map[T]struct{}

I didn't clean up the more idiomatic map[T]bool with true values, at
least yet.  I just converted the relatively awkward struct{}-valued
maps.

Updates #cleanup

Change-Id: I758abebd2bb1f64bc7a9d0f25c32298f4679c14f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2023-09-09 09:55:57 -07:00
committed by Brad Fitzpatrick
parent d506a55c8a
commit dc7aa98b76
12 changed files with 40 additions and 26 deletions

View File

@ -14,6 +14,7 @@ import (
"go4.org/netipx"
"tailscale.com/net/netmon"
"tailscale.com/types/logger"
"tailscale.com/util/set"
)
// For now this router only supports the WireGuard userspace implementation.
@ -26,7 +27,7 @@ type openbsdRouter struct {
tunname string
local4 netip.Prefix
local6 netip.Prefix
routes map[netip.Prefix]struct{}
routes set.Set[netip.Prefix]
}
func newUserspaceRouter(logf logger.Logf, tundev tun.Device, netMon *netmon.Monitor) (Router, error) {
@ -173,9 +174,9 @@ func (r *openbsdRouter) Set(cfg *Config) error {
}
}
newRoutes := make(map[netip.Prefix]struct{})
newRoutes := set.Set[netip.Prefix]{}
for _, route := range cfg.Routes {
newRoutes[route] = struct{}{}
newRoutes.Add(route)
}
for route := range r.routes {
if _, keep := newRoutes[route]; !keep {