Class: ThaliNotificationServer

thaliNotificationServer~ThaliNotificationServer

new ThaliNotificationServer(router, ecdhForLocalDevice, secondsUntilExpiration)

This class will register the path to retrieve beacons on the submitted router object.

The constructor MUST NOT take any action. It can only record values.

Parameters:
Name Type Description
router Object

An express router object that the class will use to register its path.

ecdhForLocalDevice ECDH

A Crypto.ECDH object initialized with the local device's public and private keys

secondsUntilExpiration number

The number of seconds into the future after which the beacons should expire.}

Source:

Methods

setBeacons(publicKeysToNotify) → {Promise.<?error>}

When called for the first time on an instance of ThaliNotificationServer the route "/NotificationBeacons" MUST be registered on the submitted router object with a GET handler. Registration of the path on the router MUST occur at most once.

If publicKeysToNotify is null then any GET requests on the endpoint MUST be responded to with 204 No Content per the spec .

Otherwise the endpoint MUST respond with an application/octet-stream content-type with cache-control: no-cache and a response body containing the properly generated beacon contents from module:thaliNotificationBeacons.generatePreambleAndBeacons.

There MUST be logic in the endpoint to make sure that if requests/second for this endpoint exceed a set threshold then we MUST respond with a 503 server overloaded. We MUST be careful when logging information about overloads to make sure we don't overload the log. Once the request rate for this endpoint has fallen below the threshold then we MUST start serving beacons (or 204s) again.

Every time this method is called the beacons MUST be updated with the submitted value, including NULL to start returning 204s.

The following error values MUST be used as appropriate:

'bad public keys' - This indicates that one or more of the public keys is of the wrong type or otherwise malformed and so it is not possible to use these keys to create beacons.

Parameters:
Name Type Description
publicKeysToNotify Array.<string>

An array of strings holding base64 url safe encoded ECDH public keys

Source:
Returns:

Returns null if everything went fine otherwise returns an error object.

Type
Promise.<?error>