Othernet-Project/librarian

[New API] System state API

Opened this issue · 0 comments

Librarian should provide an API for two-way update and querying of global system state and its synchronization between the browser and the server. The system state encompasses all information about the internal state of the Librarian application, as well as the information about the lower levels of the stack (e.g., networking, tuner, storage).

This information is normally collected and updated by background tasks started by different components (e.g., ondd, netinterfaces, diskspace), and is stored in a central location in memory. Updates to the global states may be announced using events. The state can be queried directly by server-side code, and also by the client-side code using a JSON REST API.

Client-side code will poll the application state on regular basis, and keep it up to date. Whenever the state changes, an event is filed to notify any components listening for a change. Client-side code may also update the system state with appropriate authorization.

The update/query APIs should be mirrored between server and client as much as possible.

In addition to system state, the user-specific state may be mixed in when querying, depending on the context (e.g., it only makes sense to do this when there is a request context).

State update API may need to take into account the following:

  • read-only state (e.g., tuner status)
  • read-write state (e.g., AP settings)
  • write-only state (e.g., passwords)
  • authorization (e.g., changing user password, tuner settings, etc)

State query API may need to take into account the following:

  • write-only state cannot be read
  • authorization
  • cache control (possibly only sending the diff instead of the entire state)
  • observing state changes (both server- and client-side)

Example usage:

  • ondd periodic background task queries ondd status and updates global state
  • ondd state is synced to browsers
  • signal indicator is updated whenever client-side copy of the system state is updated