device

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package device is who the device is: the fingerprints the SDK sends, the claims a lease names a device by, and the default fingerprinter's reading of the machine id (the reference's adapters.ts, device.ts, machine-id.ts).

Index

Constants

View Source
const (
	Machine  = "machine"
	Hostname = "hostname"
)

The kinds a fingerprint hashes.

View Source
const (
	ReadID          = "id"
	ReadUnavailable = "unavailable"
	ReadTransient   = "transient"
)

The kinds of a Reading.

View Source
const (
	MachineIDTimeout         = 2 * time.Second
	ActivateMachineIDTimeout = 10 * time.Second
)

How long a status, and an activation, may spend reading the machine id.

View Source
const BootSlackMs = 5_000

BootSlackMs is how far before the boot time an id may have been written and still count as written at this boot.

View Source
const UnknownHost = "unknown-host"

UnknownHost is what is hashed when not even the host name can be read.

Variables

This section is empty.

Functions

func ActivationIdentity

func ActivationIdentity(d Device, installKind string) (fingerprint, kind string, ok bool)

ActivationIdentity is the fingerprint an activation is made under, and what it hashes; nil when there is none (activationIdentity): the device's own; else, unless the install is keyed by a machine id or there is no host-name alternate, the host name's.

func Arch

func Arch() string

Arch is Node's name for this architecture (os.arch()): x64 for amd64, ia32 for 386, and arm and arm64 as they are (sdk-contract.md section 4 names these four). Any other GOARCH is passed as it is.

func FingerprintClaim

func FingerprintClaim(fingerprint string) string

FingerprintClaim is the claim a lease names a device by (fingerprintClaim): lowercase hex SHA-256 of "keygrant-fp|" + fingerprint.

func HashFingerprint

func HashFingerprint(raw string) string

HashFingerprint is a machine's fingerprint from what identifies it (hashFingerprint): lowercase hex SHA-256 of "keygrant|" + raw.

func HostFingerprint

func HostFingerprint(host, platform, arch string) string

HostFingerprint is the host-name fingerprint of a host name and Node's names for the platform and architecture (hostFingerprint).

func MachineFingerprint

func MachineFingerprint(id string) string

MachineFingerprint is the fingerprint of a machine id (machineFingerprint).

func MachineIDFilesystem

func MachineIDFilesystem(mountinfo string) (string, bool)

MachineIDFilesystem is the type of the filesystem /etc/machine-id is on, from /proc/self/mountinfo (machineIdFilesystem): the mount whose mount point is the longest prefix of the path on a path boundary; of several at that point, the one on top. False when no line can be read so.

func Platform

func Platform() string

Platform is Node's name for this platform (os.platform()), so the host-name fingerprint is the same whichever SDK reads it: win32 for windows, sunos for solaris and illumos, and GOOS as it is for the others Node names alike (darwin, linux, freebsd, openbsd, aix).

Types

type Device

type Device struct {
	Own          *string  // this run's own fingerprint, nil when it cannot be told
	Kind         string   // what Own hashes; "" when unknown, or with no Own
	CanTell      bool     // Own is not nil (and the device is held)
	Fingerprints []string // Own first, then the alternates, none twice
	Claims       []string // their fp claims
	OwnClaim     *string  // the claim of Own alone
	Hostname     *string  // the host-name fingerprint to activate under, or nil
}

Device is who this device is, for holding a lease to it and telling the server (device.ts Device).

func From

func From(identity Identity, installKind string, deviceHold bool, claimOf func(string) string) Device

From is who this device is (deviceFrom), from what its fingerprinter said, on an install keyed as installKind ("" for none), held to its device or not. Install memory: once a machine id keyed this install, a host-name answer is "cannot tell". Not held: no kind, no own claim, and cannot tell.

type HostNames

type HostNames struct {
	Host, Platform, Arch string
}

HostNames are what a host-name fingerprint hashes, with Node's names for the platform and architecture.

func SystemHostNames

func SystemHostNames() *HostNames

SystemHostNames are this machine's host names, or nil when the host name cannot be read.

type Identity

type Identity struct {
	Fingerprint *string
	Kind        string
	Alternates  []string
}

Identity is who the device is, as a fingerprinter answers (DeviceIdentity): its fingerprint (nil when it cannot be told this time), what that hashes ("" when the fingerprinter does not say), and other fingerprints it answers to.

func IdentityOf

func IdentityOf(r Reading, host *HostNames) Identity

IdentityOf is who this device is, as the default fingerprinter answers, from a reading of its machine id and its host names (identityOf): an id is the machine id's fingerprint, kind machine, the host name's an alternate (none when the same); unavailable is the host name's, kind hostname, no alternate; transient is no fingerprint, the host name's an alternate.

type Reading

type Reading struct {
	Kind string // "id", "unavailable" or "transient"
	ID   string
}

Reading is what reading the machine id gave (MachineIdReading): an id, none to read (unavailable), or a read that did not finish (transient).

func ReadMachineID

func ReadMachineID(ctx context.Context, src Source, timeout time.Duration) Reading

ReadMachineID is the machine's id from src, or why there is none (readMachineId): on macOS the IOPlatformUUID from ioreg; elsewhere /etc/machine-id, else /var/lib/dbus/machine-id, but none for an id on a filesystem held in memory or written at this boot. Never fails, and never takes much longer than timeout.

func ReadSystem

func ReadSystem(ctx context.Context, timeout time.Duration) Reading

ReadSystem is this machine's id, read as ReadMachineID reads it.

type Source

type Source interface {
	// Platform is Node's name for the platform ("darwin", "linux", ...).
	Platform() string
	// Run is a command's standard output, killed at timeout.
	Run(ctx context.Context, command string, args []string, timeout time.Duration) (string, error)
	// ReadFile is a file's text.
	ReadFile(path string) (string, error)
	// ModTimeMs is when a file's content was last written (ms).
	ModTimeMs(path string) (float64, error)
}

Source is where the machine id is read from on macOS and Linux (and anything else not Windows): the real system, or one a test scripts (MachineIdSource). Windows reads the registry API instead (machineid_windows.go).

type SourceError

type SourceError struct {
	Code     string
	ExitCode *int
	Killed   bool
	Signal   string
}

SourceError is a read that failed as execFile and fs fail: an errno text (ENOENT), an exit code, or a process killed by a signal or its time box.

func (*SourceError) Error

func (e *SourceError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL