Class LiveControlTokenFile
The per-start control token file (ADR-078): <root>/Typhon/runtime/control-<boundPort>.token (on POSIX
$XDG_RUNTIME_DIR/typhon/ when set), holding the token as 64 hex characters, readable by the user alone.
The engine writes it when it binds its live port and deletes it at shutdown; a local Workbench reads it to authenticate.
public static class LiveControlTokenFile
- Inheritance
-
LiveControlTokenFile
- Inherited Members
Remarks
The root follows DatabaseRegistry.DefaultDirectory's resolution (LocalAppData on Windows; $XDG_DATA_HOME, falling back to
~/.local/share, elsewhere). It is resolved here rather than through that class because this library sits below Typhon.Engine
and both the engine and the Workbench need the same path. Whoever can read the user's local data directory can control the engine: the same
trust boundary as the Workbench's bootstrap token (ADR-048).
Properties
DataDirectory
<LocalAppData on Windows; $XDG_DATA_HOME, else ~/.local/share, on POSIX>/Typhon/runtime.
public static string DataDirectory { get; }
Property Value
DefaultDirectory
Where a new token is written: the POSIX runtime directory (RuntimeDirectory) when there is one, otherwise the data directory (DataDirectory). A reader looks in both, in that order (ReadDirectories()).
public static string DefaultDirectory { get; }
Property Value
DirectoryOverride
Redirects the token directory away from DefaultDirectory. For tests.
public static string DirectoryOverride { get; set; }
Property Value
EffectiveDirectory
DirectoryOverride when set, otherwise DefaultDirectory.
public static string EffectiveDirectory { get; }
Property Value
RuntimeDirectory
$XDG_RUNTIME_DIR/typhon on POSIX when the variable is set: per-user, mode 0700, tmpfs, cleared at logout — where a per-start secret belongs.
null on Windows or without the variable.
public static string RuntimeDirectory { get; }
Property Value
Methods
Delete(int)
Deletes the token file for boundPort, if any. Never throws.
public static void Delete(int boundPort)
Parameters
boundPortint
PathFor(int)
The token file of the live listener bound to boundPort.
public static string PathFor(int boundPort)
Parameters
boundPortint
Returns
ReadDirectories()
Where a reader looks, in order: DirectoryOverride alone when set; otherwise the runtime directory (when there is one), then the data
directory — an engine started without $XDG_RUNTIME_DIR (a service manager that sets none) and a Workbench started with it still meet.
public static string[] ReadDirectories()
Returns
- string[]
TryRead(int, out LiveControlToken)
Reads the token for boundPort: of the valid files in ReadDirectories(), the most recently written — a stale one left
by an earlier engine never shadows the fresh one, even when the writer could not see the other directory to delete it (an engine started without
$XDG_RUNTIME_DIR). Directory order breaks a tie. False when no file is present, readable and 64 hex characters.
public static bool TryRead(int boundPort, out LiveControlToken token)
Parameters
boundPortinttokenLiveControlToken
Returns
WriteNew(int)
Generates a fresh random token and writes it atomically (temporary file, then a move) for boundPort, replacing any previous one.
A file for the same port left in the other read directory is deleted: readers look in the runtime directory first, so a stale token there — an
engine that crashed under a session with $XDG_RUNTIME_DIR, restarted by a service manager without it — would shadow this one.
public static LiveControlToken WriteNew(int boundPort)
Parameters
boundPortint
Returns
WriteOwnerOnly(string, string)
Writes content atomically (temporary file, then a move) so that only the current user can read it: on POSIX the directory is
0700 and the file 0600 from its creation — never world-readable, not even for the instant before a chmod. On Windows the per-user profile directory
already carries an owner-only ACL. Shared by every per-user secret file (this token, the Workbench's bootstrap token).
public static void WriteOwnerOnly(string path, string content)