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
- func ActivationIdentity(d Device, installKind string) (fingerprint, kind string, ok bool)
- func Arch() string
- func FingerprintClaim(fingerprint string) string
- func HashFingerprint(raw string) string
- func HostFingerprint(host, platform, arch string) string
- func MachineFingerprint(id string) string
- func MachineIDFilesystem(mountinfo string) (string, bool)
- func Platform() string
- type Device
- type HostNames
- type Identity
- type Reading
- type Source
- type SourceError
Constants ¶
const ( Machine = "machine" Hostname = "hostname" )
The kinds a fingerprint hashes.
const ( ReadID = "id" ReadTransient = "transient" )
The kinds of a Reading.
const ( MachineIDTimeout = 2 * time.Second ActivateMachineIDTimeout = 10 * time.Second )
How long a status, and an activation, may spend reading the machine id.
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.
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 ¶
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 ¶
FingerprintClaim is the claim a lease names a device by (fingerprintClaim): lowercase hex SHA-256 of "keygrant-fp|" + fingerprint.
func HashFingerprint ¶
HashFingerprint is a machine's fingerprint from what identifies it (hashFingerprint): lowercase hex SHA-256 of "keygrant|" + raw.
func HostFingerprint ¶
HostFingerprint is the host-name fingerprint of a host name and Node's names for the platform and architecture (hostFingerprint).
func MachineFingerprint ¶
MachineFingerprint is the fingerprint of a machine id (machineFingerprint).
func MachineIDFilesystem ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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 ¶
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