mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-22 12:58:37 +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:
parent
1047d11102
commit
9706c9f4ff
@ -1003,7 +1003,9 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
|
|||||||
if persist == c.persist {
|
if persist == c.persist {
|
||||||
newPersist := persist.AsStruct()
|
newPersist := persist.AsStruct()
|
||||||
newPersist.NodeID = nm.SelfNode.StableID()
|
newPersist.NodeID = nm.SelfNode.StableID()
|
||||||
newPersist.UserProfile = nm.UserProfiles[nm.User()]
|
if up, ok := nm.UserProfiles[nm.User()]; ok {
|
||||||
|
newPersist.UserProfile = *up.AsStruct()
|
||||||
|
}
|
||||||
|
|
||||||
c.persist = newPersist.View()
|
c.persist = newPersist.View()
|
||||||
persist = c.persist
|
persist = c.persist
|
||||||
|
@ -77,7 +77,7 @@ type mapSession struct {
|
|||||||
peers map[tailcfg.NodeID]tailcfg.NodeView
|
peers map[tailcfg.NodeID]tailcfg.NodeView
|
||||||
lastDNSConfig *tailcfg.DNSConfig
|
lastDNSConfig *tailcfg.DNSConfig
|
||||||
lastDERPMap *tailcfg.DERPMap
|
lastDERPMap *tailcfg.DERPMap
|
||||||
lastUserProfile map[tailcfg.UserID]tailcfg.UserProfile
|
lastUserProfile map[tailcfg.UserID]tailcfg.UserProfileView
|
||||||
lastPacketFilterRules views.Slice[tailcfg.FilterRule] // concatenation of all namedPacketFilters
|
lastPacketFilterRules views.Slice[tailcfg.FilterRule] // concatenation of all namedPacketFilters
|
||||||
namedPacketFilters map[string]views.Slice[tailcfg.FilterRule]
|
namedPacketFilters map[string]views.Slice[tailcfg.FilterRule]
|
||||||
lastParsedPacketFilter []filter.Match
|
lastParsedPacketFilter []filter.Match
|
||||||
@ -104,7 +104,7 @@ func newMapSession(privateNodeKey key.NodePrivate, nu NetmapUpdater, controlKnob
|
|||||||
privateNodeKey: privateNodeKey,
|
privateNodeKey: privateNodeKey,
|
||||||
publicNodeKey: privateNodeKey.Public(),
|
publicNodeKey: privateNodeKey.Public(),
|
||||||
lastDNSConfig: new(tailcfg.DNSConfig),
|
lastDNSConfig: new(tailcfg.DNSConfig),
|
||||||
lastUserProfile: map[tailcfg.UserID]tailcfg.UserProfile{},
|
lastUserProfile: map[tailcfg.UserID]tailcfg.UserProfileView{},
|
||||||
|
|
||||||
// Non-nil no-op defaults, to be optionally overridden by the caller.
|
// Non-nil no-op defaults, to be optionally overridden by the caller.
|
||||||
logf: logger.Discard,
|
logf: logger.Discard,
|
||||||
@ -294,7 +294,7 @@ func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, up := range resp.UserProfiles {
|
for _, up := range resp.UserProfiles {
|
||||||
ms.lastUserProfile[up.ID] = up
|
ms.lastUserProfile[up.ID] = up.View()
|
||||||
}
|
}
|
||||||
|
|
||||||
if dm := resp.DERPMap; dm != nil {
|
if dm := resp.DERPMap; dm != nil {
|
||||||
@ -837,7 +837,7 @@ func (ms *mapSession) netmap() *netmap.NetworkMap {
|
|||||||
PrivateKey: ms.privateNodeKey,
|
PrivateKey: ms.privateNodeKey,
|
||||||
MachineKey: ms.machinePubKey,
|
MachineKey: ms.machinePubKey,
|
||||||
Peers: peerViews,
|
Peers: peerViews,
|
||||||
UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfile),
|
UserProfiles: make(map[tailcfg.UserID]tailcfg.UserProfileView),
|
||||||
Domain: ms.lastDomain,
|
Domain: ms.lastDomain,
|
||||||
DomainAuditLogID: ms.lastDomainAuditLogID,
|
DomainAuditLogID: ms.lastDomainAuditLogID,
|
||||||
DNS: *ms.lastDNSConfig,
|
DNS: *ms.lastDNSConfig,
|
||||||
|
@ -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.
|
// 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) {
|
func (b *LocalBackend) WhoIsNodeKey(k key.NodePublic) (n tailcfg.NodeView, u tailcfg.UserProfile, ok bool) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
@ -1314,11 +1326,12 @@ func (b *LocalBackend) WhoIsNodeKey(k key.NodePublic) (n tailcfg.NodeView, u tai
|
|||||||
return n, u, false
|
return n, u, false
|
||||||
}
|
}
|
||||||
if self := b.netMap.SelfNode; self.Valid() && self.Key() == k {
|
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 {
|
for _, n := range b.peers {
|
||||||
if n.Key() == k {
|
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
|
return n, u, ok
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1388,11 +1401,11 @@ func (b *LocalBackend) WhoIs(proto string, ipp netip.AddrPort) (n tailcfg.NodeVi
|
|||||||
}
|
}
|
||||||
n = b.netMap.SelfNode
|
n = b.netMap.SelfNode
|
||||||
}
|
}
|
||||||
u, ok = b.netMap.UserProfiles[n.User()]
|
up, ok := b.netMap.UserProfiles[n.User()]
|
||||||
if !ok {
|
if !ok {
|
||||||
return failf("no userprofile for node %v", n.Key())
|
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
|
// 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 {
|
if netMap != nil {
|
||||||
newProfile := netMap.UserProfiles[netMap.User()]
|
newProfile := profileFromView(netMap.UserProfiles[netMap.User()])
|
||||||
if newLoginName := newProfile.LoginName; newLoginName != "" {
|
if newLoginName := newProfile.LoginName; newLoginName != "" {
|
||||||
if !oldp.Persist().Valid() {
|
if !oldp.Persist().Valid() {
|
||||||
b.logf("active login: %s", newLoginName)
|
b.logf("active login: %s", newLoginName)
|
||||||
@ -5803,7 +5816,7 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
|
|||||||
}
|
}
|
||||||
var login string
|
var login string
|
||||||
if nm != nil {
|
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.netMap = nm
|
||||||
b.updatePeersFromNetmapLocked(nm)
|
b.updatePeersFromNetmapLocked(nm)
|
||||||
|
@ -1052,13 +1052,13 @@ func TestWhoIs(t *testing.T) {
|
|||||||
Addresses: []netip.Prefix{netip.MustParsePrefix("100.200.200.200/32")},
|
Addresses: []netip.Prefix{netip.MustParsePrefix("100.200.200.200/32")},
|
||||||
}).View(),
|
}).View(),
|
||||||
},
|
},
|
||||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||||
10: {
|
10: (&tailcfg.UserProfile{
|
||||||
DisplayName: "Myself",
|
DisplayName: "Myself",
|
||||||
},
|
}).View(),
|
||||||
20: {
|
20: (&tailcfg.UserProfile{
|
||||||
DisplayName: "Peer",
|
DisplayName: "Peer",
|
||||||
},
|
}).View(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -2754,12 +2754,12 @@ func TestTCPHandlerForDstWithVIPService(t *testing.T) {
|
|||||||
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
|
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
|
||||||
},
|
},
|
||||||
}).View(),
|
}).View(),
|
||||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||||
tailcfg.UserID(1): {
|
tailcfg.UserID(1): (&tailcfg.UserProfile{
|
||||||
LoginName: "someone@example.com",
|
LoginName: "someone@example.com",
|
||||||
DisplayName: "Some One",
|
DisplayName: "Some One",
|
||||||
ProfilePicURL: "https://example.com/photo.jpg",
|
ProfilePicURL: "https://example.com/photo.jpg",
|
||||||
},
|
}).View(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -327,12 +327,12 @@ func TestServeConfigServices(t *testing.T) {
|
|||||||
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
|
tailcfg.NodeAttrServiceHost: []tailcfg.RawMessage{tailcfg.RawMessage(svcIPMapJSON)},
|
||||||
},
|
},
|
||||||
}).View(),
|
}).View(),
|
||||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||||
tailcfg.UserID(1): {
|
tailcfg.UserID(1): (&tailcfg.UserProfile{
|
||||||
LoginName: "someone@example.com",
|
LoginName: "someone@example.com",
|
||||||
DisplayName: "Some One",
|
DisplayName: "Some One",
|
||||||
ProfilePicURL: "https://example.com/photo.jpg",
|
ProfilePicURL: "https://example.com/photo.jpg",
|
||||||
},
|
}).View(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -905,12 +905,12 @@ func newTestBackend(t *testing.T) *LocalBackend {
|
|||||||
SelfNode: (&tailcfg.Node{
|
SelfNode: (&tailcfg.Node{
|
||||||
Name: "example.ts.net",
|
Name: "example.ts.net",
|
||||||
}).View(),
|
}).View(),
|
||||||
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfile{
|
UserProfiles: map[tailcfg.UserID]tailcfg.UserProfileView{
|
||||||
tailcfg.UserID(1): {
|
tailcfg.UserID(1): (&tailcfg.UserProfile{
|
||||||
LoginName: "someone@example.com",
|
LoginName: "someone@example.com",
|
||||||
DisplayName: "Some One",
|
DisplayName: "Some One",
|
||||||
ProfilePicURL: "https://example.com/photo.jpg",
|
ProfilePicURL: "https://example.com/photo.jpg",
|
||||||
},
|
}).View(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
b.peers = map[tailcfg.NodeID]tailcfg.NodeView{
|
b.peers = map[tailcfg.NodeID]tailcfg.NodeView{
|
||||||
|
@ -367,7 +367,7 @@ func (sb *StatusBuilder) MutateSelfStatus(f func(*PeerStatus)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddUser adds a user profile to the status.
|
// AddUser adds a user profile to the status.
|
||||||
func (sb *StatusBuilder) AddUser(id tailcfg.UserID, up tailcfg.UserProfile) {
|
func (sb *StatusBuilder) AddUser(id tailcfg.UserID, up tailcfg.UserProfileView) {
|
||||||
if sb.locked {
|
if sb.locked {
|
||||||
log.Printf("[unexpected] ipnstate: AddUser after Locked")
|
log.Printf("[unexpected] ipnstate: AddUser after Locked")
|
||||||
return
|
return
|
||||||
@ -377,7 +377,7 @@ func (sb *StatusBuilder) AddUser(id tailcfg.UserID, up tailcfg.UserProfile) {
|
|||||||
sb.st.User = make(map[tailcfg.UserID]tailcfg.UserProfile)
|
sb.st.User = make(map[tailcfg.UserID]tailcfg.UserProfile)
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.st.User[id] = up
|
sb.st.User[id] = *up.AsStruct()
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddIP adds a Tailscale IP address to the status.
|
// AddIP adds a Tailscale IP address to the status.
|
||||||
|
@ -76,7 +76,9 @@ type NetworkMap struct {
|
|||||||
// If this is empty, then data-plane audit logging is disabled.
|
// If this is empty, then data-plane audit logging is disabled.
|
||||||
DomainAuditLogID string
|
DomainAuditLogID string
|
||||||
|
|
||||||
UserProfiles map[tailcfg.UserID]tailcfg.UserProfile
|
// UserProfiles contains the profile information of UserIDs referenced
|
||||||
|
// in SelfNode and Peers.
|
||||||
|
UserProfiles map[tailcfg.UserID]tailcfg.UserProfileView
|
||||||
|
|
||||||
// MaxKeyDuration describes the MaxKeyDuration setting for the tailnet.
|
// MaxKeyDuration describes the MaxKeyDuration setting for the tailnet.
|
||||||
MaxKeyDuration time.Duration
|
MaxKeyDuration time.Duration
|
||||||
@ -289,7 +291,12 @@ func (nm *NetworkMap) PeerWithStableID(pid tailcfg.StableNodeID) (_ tailcfg.Node
|
|||||||
func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
|
func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
|
||||||
fmt.Fprintf(buf, "netmap: self: %v auth=%v",
|
fmt.Fprintf(buf, "netmap: self: %v auth=%v",
|
||||||
nm.NodeKey.ShortString(), nm.GetMachineStatus())
|
nm.NodeKey.ShortString(), nm.GetMachineStatus())
|
||||||
login := nm.UserProfiles[nm.User()].LoginName
|
|
||||||
|
var login string
|
||||||
|
up, ok := nm.UserProfiles[nm.User()]
|
||||||
|
if ok {
|
||||||
|
login = up.LoginName()
|
||||||
|
}
|
||||||
if login == "" {
|
if login == "" {
|
||||||
if nm.User().IsZero() {
|
if nm.User().IsZero() {
|
||||||
login = "?"
|
login = "?"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user