mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
ipn/ipnlocal: set the push device token correctly
It would end up resetting whatever hostinfo we had constructed and leave the backend statemachine in a broken state. This fixes that by storing the PushDeviceToken on the LocalBackend and populating it on Hostinfo before passing it to controlclient. Updates tailscale/corp#8940 Updates tailscale/corp#15367 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
0e89245c0f
commit
17b2072b72
@ -53,7 +53,6 @@ func New() *tailcfg.Hostinfo {
|
|||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
Machine: condCall(unameMachine),
|
Machine: condCall(unameMachine),
|
||||||
DeviceModel: deviceModel(),
|
DeviceModel: deviceModel(),
|
||||||
PushDeviceToken: pushDeviceToken(),
|
|
||||||
Cloud: string(cloudenv.Get()),
|
Cloud: string(cloudenv.Get()),
|
||||||
NoLogsNoSupport: envknob.NoLogsNoSupport(),
|
NoLogsNoSupport: envknob.NoLogsNoSupport(),
|
||||||
AllowsUpdate: envknob.AllowsRemoteUpdate(),
|
AllowsUpdate: envknob.AllowsRemoteUpdate(),
|
||||||
@ -166,18 +165,14 @@ func GetEnvType() EnvType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pushDeviceTokenAtomic atomic.Value // of string
|
deviceModelAtomic atomic.Value // of string
|
||||||
deviceModelAtomic atomic.Value // of string
|
osVersionAtomic atomic.Value // of string
|
||||||
osVersionAtomic atomic.Value // of string
|
desktopAtomic atomic.Value // of opt.Bool
|
||||||
desktopAtomic atomic.Value // of opt.Bool
|
packagingType atomic.Value // of string
|
||||||
packagingType atomic.Value // of string
|
appType atomic.Value // of string
|
||||||
appType atomic.Value // of string
|
firewallMode atomic.Value // of string
|
||||||
firewallMode atomic.Value // of string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetPushDeviceToken sets the device token for use in Hostinfo updates.
|
|
||||||
func SetPushDeviceToken(token string) { pushDeviceTokenAtomic.Store(token) }
|
|
||||||
|
|
||||||
// SetDeviceModel sets the device model for use in Hostinfo updates.
|
// SetDeviceModel sets the device model for use in Hostinfo updates.
|
||||||
func SetDeviceModel(model string) { deviceModelAtomic.Store(model) }
|
func SetDeviceModel(model string) { deviceModelAtomic.Store(model) }
|
||||||
|
|
||||||
@ -203,11 +198,6 @@ func deviceModel() string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func pushDeviceToken() string {
|
|
||||||
s, _ := pushDeviceTokenAtomic.Load().(string)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
// FirewallMode returns the firewall mode for the app.
|
// FirewallMode returns the firewall mode for the app.
|
||||||
// It is empty if unset.
|
// It is empty if unset.
|
||||||
func FirewallMode() string {
|
func FirewallMode() string {
|
||||||
|
@ -157,6 +157,7 @@ type LocalBackend struct {
|
|||||||
e wgengine.Engine // non-nil; TODO(bradfitz): remove; use sys
|
e wgengine.Engine // non-nil; TODO(bradfitz): remove; use sys
|
||||||
store ipn.StateStore // non-nil; TODO(bradfitz): remove; use sys
|
store ipn.StateStore // non-nil; TODO(bradfitz): remove; use sys
|
||||||
dialer *tsdial.Dialer // non-nil; TODO(bradfitz): remove; use sys
|
dialer *tsdial.Dialer // non-nil; TODO(bradfitz): remove; use sys
|
||||||
|
pushDeviceToken syncs.AtomicValue[string]
|
||||||
backendLogID logid.PublicID
|
backendLogID logid.PublicID
|
||||||
unregisterNetMon func()
|
unregisterNetMon func()
|
||||||
unregisterHealthWatch func()
|
unregisterHealthWatch func()
|
||||||
@ -2035,22 +2036,19 @@ func (b *LocalBackend) readPoller() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResendHostinfoIfNeeded is called to recompute the Hostinfo and send
|
// GetPushDeviceToken returns the push notification device token.
|
||||||
// the new version to the control server.
|
func (b *LocalBackend) GetPushDeviceToken() string {
|
||||||
func (b *LocalBackend) ResendHostinfoIfNeeded() {
|
return b.pushDeviceToken.Load()
|
||||||
// TODO(maisem,bradfitz): this is all wrong. hostinfo has been modified
|
}
|
||||||
// a dozen ways elsewhere that this omits. This method should be rethought.
|
|
||||||
hi := hostinfo.New()
|
|
||||||
|
|
||||||
b.mu.Lock()
|
// SetPushDeviceToken sets the push notification device token and informs the
|
||||||
applyConfigToHostinfo(hi, b.conf)
|
// controlclient of the new value.
|
||||||
if b.hostinfo != nil {
|
func (b *LocalBackend) SetPushDeviceToken(tk string) {
|
||||||
hi.Services = b.hostinfo.Services
|
old := b.pushDeviceToken.Swap(tk)
|
||||||
|
if old == tk {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
b.hostinfo = hi
|
b.doSetHostinfoFilterServices()
|
||||||
b.mu.Unlock()
|
|
||||||
|
|
||||||
b.doSetHostinfoFilterServices(hi)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyConfigToHostinfo(hi *tailcfg.Hostinfo, c *conffile.Config) {
|
func applyConfigToHostinfo(hi *tailcfg.Hostinfo, c *conffile.Config) {
|
||||||
@ -3172,6 +3170,7 @@ func (b *LocalBackend) doSetHostinfoFilterServices() {
|
|||||||
// the slice with no free capacity.
|
// the slice with no free capacity.
|
||||||
c := len(hi.Services)
|
c := len(hi.Services)
|
||||||
hi.Services = append(hi.Services[:c:c], peerAPIServices...)
|
hi.Services = append(hi.Services[:c:c], peerAPIServices...)
|
||||||
|
hi.PushDeviceToken = b.pushDeviceToken.Load()
|
||||||
cc.SetHostinfo(&hi)
|
cc.SetHostinfo(&hi)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1553,8 +1553,7 @@ func (h *Handler) serveSetPushDeviceToken(w http.ResponseWriter, r *http.Request
|
|||||||
http.Error(w, "invalid JSON body", http.StatusBadRequest)
|
http.Error(w, "invalid JSON body", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hostinfo.SetPushDeviceToken(params.PushDeviceToken)
|
h.b.SetPushDeviceToken(params.PushDeviceToken)
|
||||||
h.b.ResendHostinfoIfNeeded()
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"tailscale.com/client/tailscale/apitype"
|
"tailscale.com/client/tailscale/apitype"
|
||||||
"tailscale.com/hostinfo"
|
|
||||||
"tailscale.com/ipn/ipnlocal"
|
"tailscale.com/ipn/ipnlocal"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/tstest"
|
"tailscale.com/tstest"
|
||||||
@ -77,7 +76,7 @@ func TestSetPushDeviceToken(t *testing.T) {
|
|||||||
if res.StatusCode != 200 {
|
if res.StatusCode != 200 {
|
||||||
t.Errorf("res.StatusCode=%d, want 200. body: %s", res.StatusCode, body)
|
t.Errorf("res.StatusCode=%d, want 200. body: %s", res.StatusCode, body)
|
||||||
}
|
}
|
||||||
if got := hostinfo.New().PushDeviceToken; got != want {
|
if got := h.b.GetPushDeviceToken(); got != want {
|
||||||
t.Errorf("hostinfo.PushDeviceToken=%q, want %q", got, want)
|
t.Errorf("hostinfo.PushDeviceToken=%q, want %q", got, want)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user