From e5894aba427cf3736039ac9e2369daffff7d0041 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 28 Sep 2020 14:59:10 -0700 Subject: [PATCH] all: keep UserProfiles a slice instead of a map for longer Signed-off-by: Josh Bleecher Snyder --- control/controlclient/direct.go | 5 +---- control/controlclient/netmap.go | 8 +++----- ipn/ipnstate/ipnstate.go | 4 ++-- ipn/local.go | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 7703f36b9..a18757dd5 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -654,7 +654,7 @@ func (c *Direct) PollNetMap(ctx context.Context, maxPolls int, cb func(*NetworkM Peers: resp.Peers, LocalPort: localPort, User: resp.Node.User, - UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfile), + UserProfiles: resp.UserProfiles, Domain: resp.Domain, DNS: resp.DNSConfig, Hostinfo: resp.Node.Hostinfo, @@ -662,9 +662,6 @@ func (c *Direct) PollNetMap(ctx context.Context, maxPolls int, cb func(*NetworkM DERPMap: lastDERPMap, Debug: resp.Debug, } - for _, profile := range resp.UserProfiles { - nm.UserProfiles[profile.ID] = profile - } if resp.Node.MachineAuthorized { nm.MachineStatus = tailcfg.MachineAuthorized } else { diff --git a/control/controlclient/netmap.go b/control/controlclient/netmap.go index 05ad6e2e0..33a1e3eba 100644 --- a/control/controlclient/netmap.go +++ b/control/controlclient/netmap.go @@ -44,11 +44,9 @@ type NetworkMap struct { // ACLs - User tailcfg.UserID - Domain string - // TODO(crawshaw): reduce UserProfiles to []tailcfg.UserProfile? - // There are lots of ways to slice this data, leave it up to users. - UserProfiles map[tailcfg.UserID]tailcfg.UserProfile + User tailcfg.UserID + Domain string + UserProfiles []tailcfg.UserProfile // TODO(crawshaw): Groups []tailcfg.Group // TODO(crawshaw): Capabilities []tailcfg.Capability } diff --git a/ipn/ipnstate/ipnstate.go b/ipn/ipnstate/ipnstate.go index 703dca26c..a3c847109 100644 --- a/ipn/ipnstate/ipnstate.go +++ b/ipn/ipnstate/ipnstate.go @@ -112,7 +112,7 @@ func (sb *StatusBuilder) SetSelfStatus(ss *PeerStatus) { } // AddUser adds a user profile to the status. -func (sb *StatusBuilder) AddUser(id tailcfg.UserID, up tailcfg.UserProfile) { +func (sb *StatusBuilder) AddUser(up tailcfg.UserProfile) { sb.mu.Lock() defer sb.mu.Unlock() if sb.locked { @@ -124,7 +124,7 @@ func (sb *StatusBuilder) AddUser(id tailcfg.UserID, up tailcfg.UserProfile) { sb.st.User = make(map[tailcfg.UserID]tailcfg.UserProfile) } - sb.st.User[id] = up + sb.st.User[up.ID] = up } // AddIP adds a Tailscale IP address to the status. diff --git a/ipn/local.go b/ipn/local.go index 4306eb263..2491b0e31 100644 --- a/ipn/local.go +++ b/ipn/local.go @@ -163,8 +163,8 @@ func (b *LocalBackend) UpdateStatus(sb *ipnstate.StatusBuilder) { // TODO: hostinfo, and its networkinfo // TODO: EngineStatus copy (and deprecate it?) if b.netMap != nil { - for id, up := range b.netMap.UserProfiles { - sb.AddUser(id, up) + for _, up := range b.netMap.UserProfiles { + sb.AddUser(up) } for _, p := range b.netMap.Peers { var lastSeen time.Time