From f06e64c56287d242eba420e927232263b82c241e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 11 Sep 2023 19:30:49 -0700 Subject: [PATCH] wgengine: use set.HandleSet in another place I guess we missed this one earlier when we unified the various copies into set.HandleSet. Updates #cleanup Change-Id: I7e6de9ce16e8fc4846abf384dfcc8eaec4d99e60 Signed-off-by: Brad Fitzpatrick --- wgengine/userspace.go | 7 +++---- wgengine/wgengine.go | 5 ----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/wgengine/userspace.go b/wgengine/userspace.go index 62d40d336..a8a9917bb 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -133,7 +133,7 @@ type userspaceEngine struct { peerSequence []key.NodePublic endpoints []tailcfg.Endpoint pendOpen map[flowtrack.Tuple]*pendingOpenFlow // see pendopen.go - networkMapCallbacks map[*someHandle]NetworkMapCallback + networkMapCallbacks set.HandleSet[NetworkMapCallback] tsIPByIPPort map[netip.AddrPort]netip.Addr // allows registration of IP:ports as belonging to a certain Tailscale IP for whois lookups // pongCallback is the map of response handlers waiting for disco or TSMP @@ -1162,10 +1162,9 @@ func (e *userspaceEngine) AddNetworkMapCallback(cb NetworkMapCallback) func() { e.mu.Lock() defer e.mu.Unlock() if e.networkMapCallbacks == nil { - e.networkMapCallbacks = make(map[*someHandle]NetworkMapCallback) + e.networkMapCallbacks = make(set.HandleSet[NetworkMapCallback]) } - h := new(someHandle) - e.networkMapCallbacks[h] = cb + h := e.networkMapCallbacks.Add(cb) return func() { e.mu.Lock() defer e.mu.Unlock() diff --git a/wgengine/wgengine.go b/wgengine/wgengine.go index c5b2969e7..5d98c2ca6 100644 --- a/wgengine/wgengine.go +++ b/wgengine/wgengine.go @@ -42,11 +42,6 @@ type Status struct { // into network map updates. type NetworkMapCallback func(*netmap.NetworkMap) -// someHandle is allocated so its pointer address acts as a unique -// map key handle. (It needs to have non-zero size for Go to guarantee -// the pointer is unique.) -type someHandle struct{ _ byte } - // ErrNoChanges is returned by Engine.Reconfig if no changes were made. var ErrNoChanges = errors.New("no changes made to Engine config")