Problem

      There are a few reasons we need a local cache of domains and their configuration.

      Desktop Offline support

        When the user is offline and they use a HTTPS url, we need to remember which site/account ID is being referenced, so we can correctly convert back to a hm URL.

      Cross-Site Linking

        When a web site links to another HM site, we want to redirect to that other domain, unless the domain is down. So we can check this local linkbase to see if the domain is working, and if so, redirect the reader to the correct domain.

      Email Notifications

        Similarly: when the notify server redirects the user to a site, we should make sure the target domain is still correctly set up. Otherwise, redirect to the gateway.

    Solution

      In the local daemon DB, save a table of domains along with some cached information about them.

      The daemon will occasionally poll the /hm/api/config endpoint of the hosts in the table, and will make additional requests to this endpoint as needed by the frontend. The results of this will be cached in the table.

      The columns of this table:

        domain (unique)

        last_check, timestamp of the last http request we sent

        last_status, the most recent status of this. Either: "success" "unreachable" or "error"

        last_success, timestamp of the most recent successful config fetch

        last_config, the results of the /hm/api/config on the last successful run. Includes the site account ID, and the peer ID

        last_error, the error details of the last error.

      The daemon will provide data from this table over gRPC endpoints, as needed.

      We will also expose this over the public HTTP API, so you can ask any SHM web server what it most recently remembers about a domain.