hostinfo: add SetOSVersion like SetDeviceModel, deprecate ipn.Prefs way

Turns out the iOS client has been only sending the OS version it first
started at. This whole hostinfo-via-prefs mechanism was never a good idea.
Start removing it.

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/2998/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent 98b3fa78aa
commit 81269fad28

@ -20,27 +20,33 @@ import (
"tailscale.com/version" "tailscale.com/version"
) )
var osVersion func() string // non-nil on some platforms
// New returns a partially populated Hostinfo for the current host. // New returns a partially populated Hostinfo for the current host.
func New() *tailcfg.Hostinfo { func New() *tailcfg.Hostinfo {
hostname, _ := os.Hostname() hostname, _ := os.Hostname()
hostname = dnsname.FirstLabel(hostname) hostname = dnsname.FirstLabel(hostname)
var osv string
if osVersion != nil {
osv = osVersion()
}
return &tailcfg.Hostinfo{ return &tailcfg.Hostinfo{
IPNVersion: version.Long, IPNVersion: version.Long,
Hostname: hostname, Hostname: hostname,
OS: version.OS(), OS: version.OS(),
OSVersion: osv, OSVersion: getOSVersion(),
Package: packageType(), Package: packageType(),
GoArch: runtime.GOARCH, GoArch: runtime.GOARCH,
DeviceModel: deviceModel(), DeviceModel: deviceModel(),
} }
} }
var osVersion func() string // non-nil on some platforms
func getOSVersion() string {
if s, _ := osVersionAtomic.Load().(string); s != "" {
return s
}
if osVersion != nil {
return osVersion()
}
return ""
}
func packageType() string { func packageType() string {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
@ -86,11 +92,17 @@ func GetEnvType() EnvType {
return e return e
} }
var deviceModelAtomic atomic.Value // of string var (
deviceModelAtomic atomic.Value // of string
osVersionAtomic atomic.Value // of string
)
// 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) }
// SetOSVersion sets the OS version.
func SetOSVersion(v string) { osVersionAtomic.Store(v) }
func deviceModel() string { func deviceModel() string {
s, _ := deviceModelAtomic.Load().(string) s, _ := deviceModelAtomic.Load().(string)
return s return s

@ -2275,7 +2275,7 @@ func applyPrefsToHostinfo(hi *tailcfg.Hostinfo, prefs *ipn.Prefs) {
if h := prefs.Hostname; h != "" { if h := prefs.Hostname; h != "" {
hi.Hostname = h hi.Hostname = h
} }
if v := prefs.OSVersion; v != "" { if v := prefs.OSVersion; v != "" && hi.OSVersion == "" {
hi.OSVersion = v hi.OSVersion = v
// The Android app annotates when Google Play Services // The Android app annotates when Google Play Services

@ -128,9 +128,15 @@ type Prefs struct {
Hostname string Hostname string
// OSVersion overrides tailcfg.Hostinfo's OSVersion. // OSVersion overrides tailcfg.Hostinfo's OSVersion.
//
// Deprecated: we're in the process of deleting this and using
// hostinfo.SetFoo methods instead.
OSVersion string OSVersion string
// DeviceModel overrides tailcfg.Hostinfo's DeviceModel. // DeviceModel overrides tailcfg.Hostinfo's DeviceModel.
//
// Deprecated: we're in the process of deleting this and using
// hostinfo.SetFoo methods instead.
DeviceModel string DeviceModel string
// NotepadURLs is a debugging setting that opens OAuth URLs in // NotepadURLs is a debugging setting that opens OAuth URLs in

Loading…
Cancel
Save