Skip to main content

Module machine

Module machine 

Source
Expand description

The presence publisher’s decisions, apart from its I/O. Given what just happened (Event) and the time (Now), Machine::next settles the state, says what to do (Action) and how long to wait before the next Event::Due. Nothing here reads a clock, a random number or the network, so every rule is tested with a fake clock; super::Driver runs it against the relay.

stateentered onnext try
signed_outno MuxBus sign-ina sign-in (a local recheck every minute, no request)
publishingthe record was storeda minute, or a change of the snapshot
retryingunreachable, 5xx, 429, any other status5 s doubling to 5 min, full jitter; a 429’s Retry-After
unsupported404, no presence routeabout 5 min; at once on a sign-in, a network change, a wake, or a new relay version
rejected400 or 41010 min or more
signed_offa goodbye was stored at a sign-outa sign-in
offthis install doesn’t publish (super::policy)turned on

Outside publishing a change of the snapshot only marks it dirty: the next try sends the latest one, no sooner. A 409 means the relay already has a newer record of this install’s, which is as good as storing this one.

A goodbye (a v3 record, gone) is due when something was published and the relay takes v2 or later (Machine::farewell): an older relay would refuse v3, so it gets none. Turning publishing off says it here (Action::Goodbye); a sign-out and a quit say it from outside, and a sign-out tells the machine with Event::Goodbye.

Two refusals get an immediate second try before rejected: a record the relay can’t parse is sent again one version down, v4 then v2 then v1 (an older relay knows no agent lines, an older one still no states), and the version it took is then kept for that relay for Config::v1_memory; a record whose time the relay refuses is sent again stamped with the relay’s clock, learned from the Date of every answer.

Structs§

Config 🔒
The waits, apart so tests can shorten them.
Farewell 🔒
A goodbye is due, stamped on the relay’s clock as far as it is known.
Followups 🔒
The second tries already spent on the record being sent.
Log 🔒
Machine 🔒
Now 🔒
The time, as the driver read it. mono_ms only ever grows and drives the waits; wall_ms is this computer’s clock, for the status and the record; rand is uniform in [0, 1), for jitter.
Step 🔒

Enums§

Action 🔒
Answer 🔒
What the relay made of one record.
Event 🔒

Constants§

CLOCK_NOTE_AFTER_MS 🔒
A clock further than this from the relay’s is shown in the status.
LIVE 🔒
LIVE_VERSION 🔒
The version a fresh try sends to a relay not known to be older.
MALFORMED_RECORD 🔒
The relay’s error for a record it can’t parse, which is what a relay that predates the record’s version answers.

Functions§

classify 🔒
What the relay’s status and error mean for the publisher.
goodbye_text 🔒
minutes 🔒
“12 min”, rounded, at least 1.
ms 🔒
off_text 🔒
scaled 🔒
step_down 🔒
The version to try after v was refused as malformed, if any.