service library
A logbook's one writer, which other processes send entries to over a Unix socket. It checks two things before it adds anything: that the sender's user may write the entry's kind, and that the entry names the tip of its chain as previous.
A request is the bytes to record, which start with a header the service reads and keeps:
<kind>\n<previous>\n<the rest>
<kind> is a name the sender table lists for the sender's user, and
<previous> is the id of the entry before this one in its chain, or
- to start a chain. An entry's id is the sha256 of its bytes, header
and all (ObjectId): a sender can compute it before sending, and every
reader and every copy of the logbook computes the same one. The 96 bytes
the logbook chains its entries with are its own check, and never an id
here. The sender closes its side when it has sent the request, and the
service answers one line: ok <id>, or refused <why>, which for an
entry that is not its chain's tip names the tip, so the sender can read it
and try again, and for bytes the logbook already holds is
refused duplicate <id>. What it refuses it does not add.
The service reads the sender's user from the socket, as the kernel
reports it, never from the request. On every start it adds an entry of
kind started holding the sender table in force, so the logbook shows
who was allowed to write what. Each started names the one before it as
previous, so no two are the same bytes. Which names exist is the table's to say,
and every kind means nothing to the service but two.
A trajectory's chain is owned. An entry of kind
Kind.usersAssignedToTrajectory starts it and names the one user who
may extend it, its loop user, and the user that wears its suit. No
trajectory is assigned twice, and no user is in use by two open
trajectories. Straight after one it accepts, the service writes a
users-assigned-uids root of its own recording the two users' uids, so a
restart never looks them up again; an open trajectory without one gets one
at the next start. An entry of kind Kind.missionEnded closes every chain of
its mission, and one of kind Kind.trajectoryClosed every chain of one
trajectory, even one whose users are not assigned yet. A kind the table
lists as attaching starts a chain that names its parent entry on its
first body line, and belongs to that entry's trajectory. Every other chain takes an entry from any user the
table lets send its kind. Who owns what is read back from the logbook on
every start, so a restart refuses exactly what the live service did.
An entry whose bytes are missing or corrupt is a hole: the logbook
recorded it, but not what it said, so not which chain it extended. A
chain the hole starts, or whose tip comes before it, is refused
refused hole <id> until the hole's bytes are sent again, which keeps
them and answers ok <id>. A mission-ended or trajectory-closed
closes whatever it names even when a hole cuts its chain.
Classes
- Kind
-
The kind of an entry, the first line of its bytes: a name of letters,
digits,
.,_and-. Never-, which reads as "no previous entry". A sender never writes started, which only the service writes. - LogbookService
-
The writer of logbook, listening on
socket. - SenderTable
-
Which kinds each user may send: a line per user, the user's name or id
and then the kinds, separated by spaces. Blank lines and lines starting
with
#are skipped. - SocketUserReader
-
Reads the user on the other end of a Unix-domain socket from the kernel:
Linux's
SO_PEERCRED, macOS'sLOCAL_PEERCRED. - UserId
- A user id that names one real user: never one the kernel uses to say it does not know the user.
Enums
- OwnershipKind
-
The kinds that decide who owns a chain: the only kinds whose body the
service reads, and none of them can attach. Every other kind is plain to
this release, so a sender table naming another release's ownership kind
starts fine and silently owns nothing;
bin/ownership_kinds.dartprints these so a deploy can refuse that table.