mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
types/netmap,*: pass around UserProfiles as views (pointers) instead
Smaller. Updates tailscale/corp#26058 (@andrew-d noticed during this) Change-Id: Id33cddd171aaf8f042073b6d3c183b0a746e9931 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
1047d11102
commit
9706c9f4ff
@@ -1305,6 +1305,18 @@ func peerStatusFromNode(ps *ipnstate.PeerStatus, n tailcfg.NodeView) {
|
||||
}
|
||||
}
|
||||
|
||||
func profileFromView(v tailcfg.UserProfileView) tailcfg.UserProfile {
|
||||
if v.Valid() {
|
||||
return tailcfg.UserProfile{
|
||||
ID: v.ID(),
|
||||
LoginName: v.LoginName(),
|
||||
DisplayName: v.DisplayName(),
|
||||
ProfilePicURL: v.ProfilePicURL(),
|
||||
}
|
||||
}
|
||||
return tailcfg.UserProfile{}
|
||||
}
|
||||
|
||||
// WhoIsNodeKey returns the peer info of given public key, if it exists.
|
||||
func (b *LocalBackend) WhoIsNodeKey(k key.NodePublic) (n tailcfg.NodeView, u tailcfg.UserProfile, ok bool) {
|
||||
b.mu.Lock()
|
||||
@@ -1314,11 +1326,12 @@ func (b *LocalBackend) WhoIsNodeKey(k key.NodePublic) (n tailcfg.NodeView, u tai
|
||||
return n, u, false
|
||||
}
|
||||
if self := b.netMap.SelfNode; self.Valid() && self.Key() == k {
|
||||
return self, b.netMap.UserProfiles[self.User()], true
|
||||
return self, profileFromView(b.netMap.UserProfiles[self.User()]), true
|
||||
}
|
||||
for _, n := range b.peers {
|
||||
if n.Key() == k {
|
||||
u, ok = b.netMap.UserProfiles[n.User()]
|
||||
up, ok := b.netMap.UserProfiles[n.User()]
|
||||
u = profileFromView(up)
|
||||
return n, u, ok
|
||||
}
|
||||
}
|
||||
@@ -1388,11 +1401,11 @@ func (b *LocalBackend) WhoIs(proto string, ipp netip.AddrPort) (n tailcfg.NodeVi
|
||||
}
|
||||
n = b.netMap.SelfNode
|
||||
}
|
||||
u, ok = b.netMap.UserProfiles[n.User()]
|
||||
up, ok := b.netMap.UserProfiles[n.User()]
|
||||
if !ok {
|
||||
return failf("no userprofile for node %v", n.Key())
|
||||
}
|
||||
return n, u, true
|
||||
return n, profileFromView(up), true
|
||||
}
|
||||
|
||||
// PeerCaps returns the capabilities that remote src IP has to
|
||||
@@ -4193,7 +4206,7 @@ func (b *LocalBackend) setPrefsLockedOnEntry(newp *ipn.Prefs, unlock unlockOnce)
|
||||
}
|
||||
}
|
||||
if netMap != nil {
|
||||
newProfile := netMap.UserProfiles[netMap.User()]
|
||||
newProfile := profileFromView(netMap.UserProfiles[netMap.User()])
|
||||
if newLoginName := newProfile.LoginName; newLoginName != "" {
|
||||
if !oldp.Persist().Valid() {
|
||||
b.logf("active login: %s", newLoginName)
|
||||
@@ -5803,7 +5816,7 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
|
||||
}
|
||||
var login string
|
||||
if nm != nil {
|
||||
login = cmp.Or(nm.UserProfiles[nm.User()].LoginName, "<missing-profile>")
|
||||
login = cmp.Or(profileFromView(nm.UserProfiles[nm.User()]).LoginName, "<missing-profile>")
|
||||
}
|
||||
b.netMap = nm
|
||||
b.updatePeersFromNetmapLocked(nm)
|
||||
|
@@ -1052,13 +1052,13 @@ func TestWhoIs(t *testing.T) {
|
||||
Addresses: []netip.Prefix{netip.MustParsePrefix("100.200.200.200/32")},
|
||||
}).View(),
|
||||
},
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
||||
10: {
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||
10: (&tailcfg.UserProfile{
|
||||
DisplayName: "Myself",
|
||||
},
|
||||
20: {
|
||||
}).View(),
|
||||
20: (&tailcfg.UserProfile{
|
||||
DisplayName: "Peer",
|
||||
},
|
||||
}).View(),
|
||||
},
|
||||
})
|
||||
tests := []struct {
|
||||
@@ -2754,12 +2754,12 @@ func TestTCPHandlerForDstWithVIPService(t *testing.T) {
|
||||
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
|
||||
},
|
||||
}).View(),
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
||||
tailcfg.UserID(1): {
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||
tailcfg.UserID(1): (&tailcfg.UserProfile{
|
||||
LoginName: "someone@example.com",
|
||||
DisplayName: "Some One",
|
||||
ProfilePicURL: "https://example.com/photo.jpg",
|
||||
},
|
||||
}).View(),
|
||||
},
|
||||
},
|
||||
)
|
||||
|
@@ -327,12 +327,12 @@ func TestServeConfigServices(t *testing.T) {
|
||||
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
|
||||
},
|
||||
}).View(),
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
||||
tailcfg.UserID(1): {
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||
tailcfg.UserID(1): (&tailcfg.UserProfile{
|
||||
LoginName: "someone@example.com",
|
||||
DisplayName: "Some One",
|
||||
ProfilePicURL: "https://example.com/photo.jpg",
|
||||
},
|
||||
}).View(),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -905,12 +905,12 @@ func newTestBackend(t *testing.T) *LocalBackend {
|
||||
SelfNode: (&tailcfg.Node{
|
||||
Name: "example.ts.net",
|
||||
}).View(),
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
||||
tailcfg.UserID(1): {
|
||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||
tailcfg.UserID(1): (&tailcfg.UserProfile{
|
||||
LoginName: "someone@example.com",
|
||||
DisplayName: "Some One",
|
||||
ProfilePicURL: "https://example.com/photo.jpg",
|
||||
},
|
||||
}).View(),
|
||||
},
|
||||
}
|
||||
b.peers = map[tailcfg.NodeID]tailcfg.NodeView{
|
||||
|
Reference in New Issue
Block a user