types/netmap: deprecate NetworkMap.MachineStatus, add accessor method

Step 1 of deleting it, per TODO.

Updates #cleanup

Change-Id: I1d3d0165ae5d8b20610227d60640997b73568733
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9436/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 0f3c279b86
commit fb5ceb03e3

@ -253,7 +253,7 @@ func (i *jsIPN) run(jsCallbacks js.Value) {
NodeKey: nm.NodeKey.String(),
MachineKey: nm.MachineKey.String(),
},
MachineStatus: jsMachineStatus[nm.MachineStatus],
MachineStatus: jsMachineStatus[nm.GetMachineStatus()],
},
Peers: mapSlice(nm.Peers, func(p tailcfg.NodeView) jsNetMapPeerNode {
name := p.Name()

@ -3812,7 +3812,7 @@ func (b *LocalBackend) nextStateLocked() ipn.State {
// NetMap must be non-nil for us to get here.
// The node key expired, need to relogin.
return ipn.NeedsLogin
case netMap.MachineStatus != tailcfg.MachineAuthorized:
case netMap.GetMachineStatus() != tailcfg.MachineAuthorized:
// TODO(crawshaw): handle tailcfg.MachineInvalid
return ipn.NeedsMachineAuth
case state == ipn.NeedsMachineAuth:

@ -40,7 +40,10 @@ type NetworkMap struct {
// MachineStatus is either tailcfg.MachineAuthorized or tailcfg.MachineUnauthorized,
// depending on SelfNode.MachineAuthorized.
// TODO(bradfitz): remove this field and make it a method.
//
// Deprecated: use GetMachineStatus instead. This field exists still
// exists (as of 2023-09-13) for some tests in other repos that haven't
// yet been migrated. TODO(bradfitz): remove this field.
MachineStatus tailcfg.MachineStatus
MachineKey key.MachinePublic
@ -106,6 +109,23 @@ func (nm *NetworkMap) AnyPeersAdvertiseRoutes() bool {
return false
}
// GetMachineStatus returns the MachineStatus of the local node.
func (nm *NetworkMap) GetMachineStatus() tailcfg.MachineStatus {
if nm.MachineStatus != tailcfg.MachineUnknown {
// For now (2023-09-13), let the deprecated MachineStatus field take
// precedence. This is a migration mechanism while we update tests &
// code cross-repo.
return nm.MachineStatus
}
if !nm.SelfNode.Valid() {
return tailcfg.MachineUnknown
}
if nm.SelfNode.MachineAuthorized() {
return tailcfg.MachineAuthorized
}
return tailcfg.MachineUnauthorized
}
// PeerByTailscaleIP returns a peer's Node based on its Tailscale IP.
//
// If nm is nil or no peer is found, ok is false.
@ -211,7 +231,7 @@ func (nm *NetworkMap) PeerWithStableID(pid tailcfg.StableNodeID) (_ tailcfg.Node
// in equalConciseHeader in sync.
func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
fmt.Fprintf(buf, "netmap: self: %v auth=%v",
nm.NodeKey.ShortString(), nm.MachineStatus)
nm.NodeKey.ShortString(), nm.GetMachineStatus())
login := nm.UserProfiles[nm.User()].LoginName
if login == "" {
if nm.User().IsZero() {
@ -229,7 +249,7 @@ func (nm *NetworkMap) printConciseHeader(buf *strings.Builder) {
// used by printConciseHeader.
func (a *NetworkMap) equalConciseHeader(b *NetworkMap) bool {
if a.NodeKey != b.NodeKey ||
a.MachineStatus != b.MachineStatus ||
a.GetMachineStatus() != b.GetMachineStatus() ||
a.User() != b.User() ||
len(a.Addresses) != len(b.Addresses) {
return false

Loading…
Cancel
Save