offline

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: 4 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 offline is what the SDK decides from what the device holds, without asking the server (the reference's offline.ts): whether a lease licenses this build, what a trial shows, which refusal still stands, and when to ask again.

Index

Constants

View Source
const (
	Expired    = "expired"
	Upgrade    = "upgrade"
	Outdated   = "outdated"
	Tampered   = "tampered"
	UnknownKey = "unknown-key"
	Device     = "device"
)

Why a lease does not license this build.

View Source
const (
	AskAgainMs        = 60 * 60_000
	RetryUnansweredMs = 60_000
)

How long to wait before asking again on its own: after an answer without a lease, and after no answer at all.

View Source
const (
	RefusedRevoked  = "revoked"
	RefusedUpgrade  = "upgrade"
	RefusedOutdated = "outdated"
	RefusedDevice   = "device"
)

The refusals the server gives, as stored.

View Source
const (
	Licensed   = "licensed"
	Trial      = "trial"
	ExpiredS   = "expired"
	Invalid    = "invalid"
	Unlicensed = "unlicensed"
	Unknown    = "unknown"
)

The states a status is in.

View Source
const (
	Revoked     = "revoked"
	Offline     = "offline"
	TrialReason = "trial"
	Storage     = "storage"
	RevokedFile = "revoked-file"
)

The reasons a status gives (besides the lease reasons of check.go).

View Source
const DayMs = 86_400_000

DayMs is a day in milliseconds.

View Source
const RenewWithinMs = 7 * 24 * 60 * 60_000

RenewWithinMs is how near its end a valid lease is renewed early.

View Source
const TrialReportMs = DayMs

TrialReportMs is how often, at most, a running trial reports its launch.

Variables

This section is empty.

Functions

func ActivationPatch

func ActivationPatch(key, activationID, leaseText string, c *lease.Claims, now float64, major int, kind string) state.Patch

ActivationPatch is what an activation saves (activationPatch): the key, the activation, the lease, the major heard, the kept major, refusal and wait cleared, and what the install is keyed by (cleared for a kind not known).

func AskDue

func AskDue(s state.State, clockNow float64, force bool) bool

AskDue is whether to ask the server now (askDue): forced; no wait recorded; the device clock before the recorded ask; or the wait over.

func AsksOnValidLease

func AsksOnValidLease(c *lease.Claims, s state.State, major int, now, clockNow float64, journalAsks bool) bool

AsksOnValidLease is whether status(), holding a lease that licenses this build, asks the server now (asksOnValidLease): a newer major than the server last heard on an open lease, the lease near its end, or a journal to report whose wait is not running; and only when the wait allows.

func HeldElsewhere

func HeldElsewhere(v lease.Result, claims []string, canTell bool) bool

HeldElsewhere is whether a licence lease, valid or merely expired, is held to a machine that is not this device (heldElsewhere).

func HeldToAnother

func HeldToAnother(c *lease.Claims, claims []string, canTell bool) bool

HeldToAnother is whether a lease's claims hold it to a machine this run can tell is not this device: only a seat keyed by a machine id (fp, fpk machine), and only when this run can tell who the device is.

func KeptWith

func KeptWith(kept *float64, c *lease.Claims, now float64, major int) *float64

KeptWith is kept after running major on a lease with these claims at now (keptWith): raised to it while the lease carries an open upgrade window and now is before its end, else as it was.

func KeyedBy

func KeyedBy(kind string) state.Patch

KeyedBy is what a check-in with a device of this kind writes of the install's key: a machine id read here keys it (keyedBy).

func Leased

func Leased() state.Patch

Leased is what a new lease from the server clears: any refusal, and the wait.

func MajorOf

func MajorOf(configured *int) int

MajorOf is the major a build runs as (majorOf): the configured one, none read as 1, and never below 1 (a 0.x build is major 1).

func RefusalPatch

func RefusalPatch(refused string, major int, ownClaim *string) state.Patch

RefusalPatch is what storing the server's refusal changes (refusalPatch): revoked drops the lease; upgrade and outdated keep it, with the major refused; device keeps it, with the device's own claim (none when it has none).

func RenewsEarly

func RenewsEarly(c *lease.Claims, now float64) bool

RenewsEarly is whether a valid lease is near enough its end at now to renew it early: less than RenewWithinMs left, or less than half its life when that is shorter.

func StandingRefusal

func StandingRefusal(s state.State, major int, dev *DeviceView) string

StandingRefusal is the stored refusal that still stands for a build running major, or "" (standingRefusal): a device refusal stored with refusedFor only while this run can tell and its own claim is in it; revoked, a device refusal without refusedFor, and one with no refusedMajor always; upgrade for that major and newer; outdated for it and older.

func TrialLeaseValid

func TrialLeaseValid(v lease.Result, product string, claims []string, canTell bool) bool

TrialLeaseValid is whether a verified trial lease runs a trial here (trialLeaseValid): valid, a trial's, this product's, and either not started under a machine id, or this run cannot tell, or its aid is this device's.

func TrialReportDue

func TrialReportDue(s state.State, now float64) bool

TrialReportDue is whether a running trial reports its launch at now, the guarded clock (trialReportDue): neither trialAt nor trialReportedAt within a day before now (one ahead of now is within it).

func Unkeyed

func Unkeyed() state.Patch

Unkeyed is what a deactivated device keeps of its licence: nothing but its trial evidence and clock guard.

Types

type Check

type Check struct {
	OK     bool
	Test   bool
	Claims *lease.Claims // set when OK
	Reason string        // set when not OK
}

Check is what a lease says about this build, offline: OK with whether it is a test licence's and its claims, or the reason it does not license.

func CheckLease

func CheckLease(v lease.Result, product string, major int, holder Holder) Check

CheckLease is a verified licence lease held to this product, this holder and this build's major (checkLease), in order: not valid (expired, unknown-key, else tampered); another product, key (without case) or activation (tampered); held to a machine this run can tell is another (device); below minMajor (outdated); above major (upgrade); else licensed.

type DeviceView

type DeviceView struct {
	OwnClaim *string
	CanTell  bool
}

Who the device is, as the decisions that take one read it: its own claim, and whether this run can tell (nil: no device read).

type Holder

type Holder struct {
	Key          string
	ActivationID string
	Claims       []string // every fp claim this device answers to
	CanTell      bool     // whether this run could tell who the device is
}

Holder is whose a licence lease must be: the key and activation stored, and this device.

type LicensedTo

type LicensedTo struct {
	Name, Email *string
}

LicensedTo is who a licence file is licensed to.

type MeterStatus

type MeterStatus struct {
	Left, Total, Offline, Unsynced int64
	Resets                         bool
}

MeterStatus is one meter as a status shows it (sdk-contract.md 12.8).

type RenewalInput

type RenewalInput struct {
	Response *wire.Response // nil when there was no answer at all
	Check    *Check         // the offline check of the lease a 200 carried, else nil
	AskedAt  float64        // the device clock when the ask was made
	Now      float64        // the time the lease was judged at
	Major    int
	Key      string   // the stored key ("" for none)
	Kept     *float64 // the stored kept major
	Kind     string   // what the device's own fingerprint hashes
	OwnClaim *string
}

RenewalInput is what an ask's answer is judged from (renewal.ts RenewalInput).

type RenewalOutcome

type RenewalOutcome struct {
	Answered bool
	Status   *Status
	Patch    state.Patch
}

RenewalOutcome is what an ask's answer does: whether the server answered at all, the status it gives (nil: none), and what is saved as the answer.

func Renewal

func Renewal(in RenewalInput) RenewalOutcome

Renewal is what a validate's answer saves and says (renewalOutcome): no answer waits a minute; a 5xx or 429 waits an hour; a 200 with a lease that licenses this build, or one the server stands behind for another build or device, is kept; any other 200 waits an hour; a refusal is stored; anything else waits an hour. Every patch is keyed by a machine id read here.

type Status

type Status struct {
	State         string
	Reason        string
	Key           string
	TrialDaysLeft *float64
	TrialEndsAt   *float64
	Test          bool
	Entitlements  lease.Entitlements
	Meters        map[string]MeterStatus
	Source        string
	LicensedTo    *LicensedTo
	Stalled       bool
}

Status is what status() says (LicenseStatus). An empty text is absent; nil or empty maps are absent.

func LeaseStatus

func LeaseStatus(c Check, key string) Status

LeaseStatus is the status a stored licence lease gives, judged offline, when the server gives no verdict (leaseStatus): licensed, with test and its entitlements; expired/offline; invalid with the reason and the key; or invalid/tampered with no key.

func TrialStatusOf

func TrialStatusOf(s state.State, now float64, leaseValid bool, leaseEndsAt *float64, ent lease.Entitlements) Status

TrialStatusOf is a trial's status from what the device holds (trialStatusOf): unlicensed with no trial evidence; expired/trial unless its lease is valid; else trial, ending when the lease was signed to (the stored end only when that is not known), with its days left and its entitlements.

type TrialLease

type TrialLease struct {
	Valid        bool
	EndsAt       *float64 // its exp in ms, when valid
	Entitlements lease.Entitlements
}

TrialLease is what a trial's status reads of its trial lease (trialLeaseOf).

func TrialLeaseOf

func TrialLeaseOf(v lease.Result, product string, claims []string, canTell bool) TrialLease

TrialLeaseOf is a verified trial lease as a status reads it.

Jump to

Keyboard shortcuts

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