teos.cleaner

class Cleaner[source]

Bases: object

The Cleaner is in charge of removing expired/completed data from the tower.

Mutable objects (like dicts) are passed-by-reference in Python, so no return is needed for the Cleaner.

static delete_appointment_from_db(uuid, db_manager)[source]

Deletes an appointment from the appointments database.

Parameters
  • uuid (str) – the identifier of the appointment to be deleted.

  • db_manager (AppointmentsDBM) – an instance of the appointment database manager to interact with the database.

static delete_appointment_from_memory(uuid, appointments, locator_uuid_map)[source]

Deletes an appointment from memory (appointments and locator_uuid_map dictionaries). If the given appointment does not share locator with any other, the map will completely removed, otherwise, the uuid will be removed from the map.

Parameters
  • uuid (str) – the identifier of the appointment to be deleted.

  • appointments (dict) – the appointments dictionary from where the appointment should be removed.

  • locator_uuid_map (dict) – the locator:uuid map from where the appointment should also be removed.

static delete_completed_appointments(completed_appointments, appointments, locator_uuid_map, db_manager)[source]

Deletes a completed appointment from memory (Watcher) and disk.

Currently, an appointment is only completed if it cannot make it to the (Responder), otherwise, it will be flagged as triggered and removed once the tracker is completed.

Parameters
  • completed_appointments (list) – a list of appointments to be deleted.

  • appointments (dict) – a dictionary containing all the Watcher appointments.

  • locator_uuid_map (dict) – a locator:uuid map for the Watcher appointments.

  • db_manager (AppointmentsDBM) – an instance of the appointment database manager to interact with the database.

static delete_expired_appointments(expired_appointments, appointments, locator_uuid_map, db_manager)[source]

Deletes appointments which expiry has been reached (with no trigger) both from memory (Watcher) and disk.

Parameters
  • expired_appointments (list) – a list of appointments to be deleted.

  • appointments (dict) – a dictionary containing all the Watcher appointments.

  • locator_uuid_map (dict) – a locator:uuid map for the Watcher appointments.

  • db_manager (AppointmentsDBM) – an instance of the appointment database manager to interact with the database.

static delete_gatekeeper_appointments(gatekeeper, appointment_to_delete)[source]

Deletes a list of expired / completed appointments of a given user both from memory and the UserDB.

Parameters
  • gatekeeper (Gatekeeper) – a Gatekeeper instance in charge to control the user access and subscription expiry.

  • appointment_to_delete (dict) – uuid:user_id dict containing the appointments to delete (expired + completed)

static delete_trackers(completed_trackers, height, trackers, tx_tracker_map, db_manager, expired=False)[source]

Deletes completed/expired trackers both from memory (Responder) and disk (from the Responder’s and Watcher’s databases).

Parameters
  • trackers (dict) – a dictionary containing all the Responder trackers.

  • height (int) – the block height at which the trackers were completed.

  • tx_tracker_map (dict) – a penalty_txid:uuid map for the Responder trackers.

  • completed_trackers (dict) – a dict of completed/expired trackers to be deleted (uuid:confirmations).

  • db_manager (AppointmentsDBM) – an instance of the appointment database manager to interact with the database.

  • expired (bool) – whether the trackers have expired or not. Defaults to False.

static flag_triggered_appointments(triggered_appointments, appointments, locator_uuid_map, db_manager)[source]

Deletes a list of triggered appointment from memory (Watcher) and flags them as triggered on disk.

Parameters
  • triggered_appointments (list) – a list of appointments to be flagged as triggered on the database.

  • appointments (dict) – a dictionary containing all the Watcher appointments.

  • locator_uuid_map (dict) – a locator:uuid map for the Watcher appointments.

  • db_manager (AppointmentsDBM) – an instance of the appointment database manager to interact with the database.

static update_delete_db_locator_map(uuids, locator, db_manager)[source]

Updates the locator:uuid map of a given locator from the database by removing a given uuid. If the uuid is the only element of the map, the map is deleted, otherwise the uuid is simply removed and the database is updated.

If either the uuid of the locator are not found, the data is not modified.

Parameters
  • uuids (list) – a list of identifiers to be removed from the map.

  • locator (str) – the identifier of the map to be either updated or deleted.

  • db_manager (AppointmentsDBM) – an instance of the appointment database manager to interact with the database.