Documentation
¶
Overview ¶
Package state is what the SDK keeps on disk (sdk-contract.md 5.5): the stored state, a JSON object every KeyGrant SDK reads and writes the same way, how a save lands on it (merge.go), and the clock guard (clock.go).
The state is kept as the JSON object it is, so the fields another SDK version wrote travel through a save untouched, and read through typed getters: a known field of the wrong type reads as absent (sdk-contract.md 5.5, "a typed port").
Index ¶
- Constants
- Variables
- func ClockCorrection(clockNow float64, lastSeen *float64, claims *SignedAt, heldIat *float64, ...) *float64
- func GuardedNow(clockNow float64, lastSeen *float64) float64
- func NumberOf(v any) (float64, bool)
- func Outdated(stored *float64, stamp Stamp) bool
- func SavedLastSeen(stored *float64, clockNow float64, guard *float64) float64
- func Superseded(latest State, asked Asked) string
- type About
- type Asked
- type Basis
- type Patch
- type SignedAt
- type Stamp
- type State
- func (s State) Clone() State
- func (s State) Filled(field string) (string, bool)
- func (s State) Num(field string) (float64, bool)
- func (s State) NumPtr(field string) *float64
- func (s State) Text(field string) (string, bool)
- func (s State) TextPtr(field string) *string
- func (s State) Texts(field string) ([]string, bool)
- func (s State) With(p Patch) State
Constants ¶
const ( Key = "key" ActivationID = "activationId" Lease = "lease" TrialStart = "trialStart" TrialEndsAt = "trialEndsAt" TrialLease = "trialLease" TrialAt = "trialAt" LastSeen = "lastSeen" CheckedMajor = "checkedMajor" KeptMajor = "keptMajor" BackoffSince = "backoffSince" BackoffMs = "backoffMs" Refused = "refused" RefusedMajor = "refusedMajor" RefusedFor = "refusedFor" DeviceKind = "deviceKind" VerdictAt = "verdictAt" TrialReportedAt = "trialReportedAt" LicenseFile = "licenseFile" Spends = "spends" MeterFigures = "meterFigures" Rev = "rev" )
The state's fields (sdk-contract.md 5.5). Times are milliseconds.
const ClockToleranceMs = 60 * 60_000
ClockToleranceMs is how far the clock guard may run ahead of the time the server signed a fresh lease before it is brought back.
Variables ¶
var RetiredFields = []string{"purchaseToken", "purchaseTokenAt", "claimAskedAt"}
RetiredFields are what an earlier version stored to buy from the app with no key typed: no save keeps them.
Functions ¶
func ClockCorrection ¶
func ClockCorrection(clockNow float64, lastSeen *float64, claims *SignedAt, heldIat *float64, key, activationID string) *float64
ClockCorrection is where the clock guard is brought back to on a lease the server has just signed, or nil to leave it (clockCorrection): only a lease for this key (without case) and activation, no older than the one held, when the guard is MORE than ClockToleranceMs past its iat; to the device clock, never below iat.
func GuardedNow ¶
GuardedNow is now by the clock guard: never earlier than the latest time the device has seen (guardedNow).
func NumberOf ¶
NumberOf is a value of the state as a number: as JSON read it, or as this process wrote it; false for anything else.
func Outdated ¶
Outdated is whether a stored stamp is a NEWER answer than stamp's: saved since that asker read the state (another stamp than the one it saw), and asked for later than it (outdated).
func SavedLastSeen ¶
SavedLastSeen is the latest time seen a save writes: the guard brought back exactly as given when there is one, else never earlier than what is stored nor than the device clock (savedLastSeen).
func Superseded ¶
Superseded is whether an ask's answer is out of date by the time it is saved: "activation" when the state names another activation, or none; "answer" when a newer answer about the same activation has been saved; "" otherwise.
Types ¶
type About ¶
type About struct {
ActivationID *string
}
About names the activation a save that is no answer is about.
type Basis ¶
Basis is what a save is based on (merge.ts Basis): the answer to an ask, an activation's answer, a note about an activation, or a trial answer. The zero Basis is unbased.
type Patch ¶
Patch is a change to a state: a field set to nil is cleared, a field not in the map is left as it is (the reference's Partial<StoredState>, undefined clearing).
func TrialOnly ¶
TrialOnly is only the trial evidence of a patch: what lands on another activation. A field the patch clears stays cleared.
func WithoutVerdict ¶
WithoutVerdict is a patch without the verdict fields: what of an out-of-date answer is still saved.
type Stamp ¶
Stamp is when something was asked of the server (guarded device clock, ms), and the stored stamp of that kind the asker saw (nil: none).
type State ¶
State is a stored state: absent fields are not in the map.
func Merged ¶
Merged is a patch merged onto the state as stored now, by what it is based on (merge.ts merged): stamped (an answer or an activation with verdictAt, a trial answer with trialAt); a save about an activation no longer stored keeps only its trial evidence; an answer older than the stored one loses its verdict fields; a trial answer older than the stored one loses its end and lease; the trial start only moves earlier; the kept major of the stored activation only moves up; the retired fields are left out.