From ebfa6484a28626e0345705463a6a130d2d6f6a59 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 13 Sep 2022 23:13:36 +0200 Subject: [PATCH] Persist directory to disk for every user modification --- nomadnet/Conversation.py | 3 +++ nomadnet/Directory.py | 3 +++ nomadnet/NomadNetworkApp.py | 1 - nomadnet/ui/textui/Conversations.py | 3 --- nomadnet/ui/textui/Network.py | 5 +++++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/nomadnet/Conversation.py b/nomadnet/Conversation.py index 94f2697..d36f2eb 100644 --- a/nomadnet/Conversation.py +++ b/nomadnet/Conversation.py @@ -142,6 +142,9 @@ class Conversation: self.__changed_callback = None + if not RNS.Transport.has_path(bytes.fromhex(source_hash)): + RNS.Transport.request_path(bytes.fromhex(source_hash)) + self.source_identity = RNS.Identity.recall(bytes.fromhex(self.source_hash)) if self.source_identity: diff --git a/nomadnet/Directory.py b/nomadnet/Directory.py index a2d9e79..875f621 100644 --- a/nomadnet/Directory.py +++ b/nomadnet/Directory.py @@ -47,6 +47,7 @@ class Directory: file = open(self.app.directorypath, "wb") file.write(msgpack.packb(directory)) file.close() + except Exception as e: RNS.log("Could not write directory to disk. Then contained exception was: "+str(e), RNS.LOG_ERROR) @@ -179,6 +180,8 @@ class Directory: node_entry = self.directory_entries[associated_node] node_entry.trust_level = entry.trust_level + self.save_to_disk() + def forget(self, source_hash): if source_hash in self.directory_entries: self.directory_entries.pop(source_hash) diff --git a/nomadnet/NomadNetworkApp.py b/nomadnet/NomadNetworkApp.py index 12323d1..07919e2 100644 --- a/nomadnet/NomadNetworkApp.py +++ b/nomadnet/NomadNetworkApp.py @@ -30,7 +30,6 @@ class NomadNetworkApp: START_ANNOUNCE_DELAY = 3 def exit_handler(self): - RNS.log("Nomad Network Client exit handler executing...", RNS.LOG_VERBOSE) self.should_run_jobs = False RNS.log("Saving directory...", RNS.LOG_VERBOSE) diff --git a/nomadnet/ui/textui/Conversations.py b/nomadnet/ui/textui/Conversations.py index 951b452..12645e5 100644 --- a/nomadnet/ui/textui/Conversations.py +++ b/nomadnet/ui/textui/Conversations.py @@ -294,9 +294,6 @@ class ConversationsDisplay(): self.app.directory.remember(entry) new_conversation = nomadnet.Conversation(source_hash_text, nomadnet.NomadNetworkApp.get_shared_instance(), initiator=True) - - if not RNS.Transport.has_path(source_hash): - RNS.Transport.request_path(source_hash) self.update_conversation_list() diff --git a/nomadnet/ui/textui/Network.py b/nomadnet/ui/textui/Network.py index 6039c48..9a72d13 100644 --- a/nomadnet/ui/textui/Network.py +++ b/nomadnet/ui/textui/Network.py @@ -127,6 +127,9 @@ class AnnounceInfo(urwid.WidgetWrap): if is_node: node_ident = RNS.Identity.recall(source_hash) + if not node_ident: + raise KeyError("Could not recall identity for selected node") + op_hash = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", node_ident) op_str = self.app.directory.simplest_display_str(op_hash) @@ -607,6 +610,8 @@ class ExceptionHandlingListBox(IndicativeListBox): nomadnet.NomadNetworkApp.get_shared_instance().ui.main_display.frame.set_focus("header") elif key == "down": nomadnet.NomadNetworkApp.get_shared_instance().ui.main_display.sub_displays.network_display.left_pile.set_focus(1) + else: + RNS.log("An error occurred while processing an interface event. The contained exception was: "+str(e), RNS.LOG_ERROR) class KnownNodes(urwid.WidgetWrap):