mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-12 05:37:32 +00:00
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:

committed by
Brad Fitzpatrick

parent
d506a55c8a
commit
dc7aa98b76
@@ -54,6 +54,7 @@ import (
|
||||
"tailscale.com/util/clientmetric"
|
||||
"tailscale.com/util/mak"
|
||||
"tailscale.com/util/ringbuffer"
|
||||
"tailscale.com/util/set"
|
||||
"tailscale.com/util/uniq"
|
||||
"tailscale.com/wgengine/capture"
|
||||
)
|
||||
@@ -229,7 +230,7 @@ type Conn struct {
|
||||
// WireGuard. These are not used to filter inbound or outbound
|
||||
// traffic at all, but only to track what state can be cleaned up
|
||||
// in other maps below that are keyed by peer public key.
|
||||
peerSet map[key.NodePublic]struct{}
|
||||
peerSet set.Set[key.NodePublic]
|
||||
|
||||
// nodeOfDisco tracks the networkmap Node entity for each peer
|
||||
// discovery key.
|
||||
@@ -1708,7 +1709,7 @@ func (c *Conn) SetPrivateKey(privateKey key.NodePrivate) error {
|
||||
// then removes any state for old peers.
|
||||
//
|
||||
// The caller passes ownership of newPeers map to UpdatePeers.
|
||||
func (c *Conn) UpdatePeers(newPeers map[key.NodePublic]struct{}) {
|
||||
func (c *Conn) UpdatePeers(newPeers set.Set[key.NodePublic]) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -1718,7 +1719,7 @@ func (c *Conn) UpdatePeers(newPeers map[key.NodePublic]struct{}) {
|
||||
// Clean up any key.NodePublic-keyed maps for peers that no longer
|
||||
// exist.
|
||||
for peer := range oldPeers {
|
||||
if _, ok := newPeers[peer]; !ok {
|
||||
if !newPeers.Contains(peer) {
|
||||
delete(c.derpRoute, peer)
|
||||
delete(c.peerLastDerp, peer)
|
||||
}
|
||||
|
@@ -58,6 +58,7 @@ import (
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/util/cibuild"
|
||||
"tailscale.com/util/racebuild"
|
||||
"tailscale.com/util/set"
|
||||
"tailscale.com/wgengine/filter"
|
||||
"tailscale.com/wgengine/wgcfg"
|
||||
"tailscale.com/wgengine/wgcfg/nmcfg"
|
||||
@@ -306,9 +307,9 @@ func meshStacks(logf logger.Logf, mutateNetmap func(idx int, nm *netmap.NetworkM
|
||||
for i, m := range ms {
|
||||
nm := buildNetmapLocked(i)
|
||||
m.conn.SetNetworkMap(nm)
|
||||
peerSet := make(map[key.NodePublic]struct{}, len(nm.Peers))
|
||||
peerSet := make(set.Set[key.NodePublic], len(nm.Peers))
|
||||
for _, peer := range nm.Peers {
|
||||
peerSet[peer.Key()] = struct{}{}
|
||||
peerSet.Add(peer.Key())
|
||||
}
|
||||
m.conn.UpdatePeers(peerSet)
|
||||
wg, err := nmcfg.WGCfg(nm, logf, netmap.AllowSingleHosts, "")
|
||||
|
Reference in New Issue
Block a user