From 31afb1373adf99f02c1b35674ffbc2f02ee88e7f Mon Sep 17 00:00:00 2001 From: Sergi Delgado Segura Date: Wed, 6 Nov 2019 17:08:42 +0000 Subject: [PATCH] Integrates the locator map dumping to the Watcher and Cleaner --- pisa/cleaner.py | 18 ++++++++++++++++++ pisa/watcher.py | 1 + 2 files changed, 19 insertions(+) diff --git a/pisa/cleaner.py b/pisa/cleaner.py index 6234643..0ed0cda 100644 --- a/pisa/cleaner.py +++ b/pisa/cleaner.py @@ -33,6 +33,7 @@ class Cleaner: # ToDo: #9-add-data-persistence justice_txid = jobs[uuid].justice_txid + locator = jobs[uuid].locator jobs.pop(uuid) if len(tx_job_map[justice_txid]) == 1: @@ -46,3 +47,20 @@ class Cleaner: # Delete appointment from the db (both watchers's and responder's) db_manager.delete_watcher_appointment(uuid) db_manager.delete_responder_job(uuid) + + # Update / delete the locator map + locator_map = db_manager.load_locator_map(locator) + if locator_map is not None: + if uuid in locator_map: + if len(locator_map) == 1: + db_manager.delete_locator_map(locator) + + else: + locator_map.remove(uuid) + db_manager.store_update_locator_map(locator, locator_map) + + else: + logger.error("UUID not found in the db.", uuid=uuid) + + else: + logger.error("Locator not found in the db.", uuid=uuid) diff --git a/pisa/watcher.py b/pisa/watcher.py index 70dc175..5d579e9 100644 --- a/pisa/watcher.py +++ b/pisa/watcher.py @@ -74,6 +74,7 @@ class Watcher: logger.info("Waking up") self.db_manager.store_watcher_appointment(uuid, appointment.to_json()) + self.db_manager.store_update_locator_map(appointment.locator, uuid) appointment_added = True