Persist directory to disk for every user modification

This commit is contained in:
Mark Qvist 2022-09-13 23:13:36 +02:00
parent 6df7feffe6
commit ebfa6484a2
5 changed files with 11 additions and 4 deletions

View File

@ -142,6 +142,9 @@ class Conversation:
self.__changed_callback = None 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)) self.source_identity = RNS.Identity.recall(bytes.fromhex(self.source_hash))
if self.source_identity: if self.source_identity:

View File

@ -47,6 +47,7 @@ class Directory:
file = open(self.app.directorypath, "wb") file = open(self.app.directorypath, "wb")
file.write(msgpack.packb(directory)) file.write(msgpack.packb(directory))
file.close() file.close()
except Exception as e: except Exception as e:
RNS.log("Could not write directory to disk. Then contained exception was: "+str(e), RNS.LOG_ERROR) 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 = self.directory_entries[associated_node]
node_entry.trust_level = entry.trust_level node_entry.trust_level = entry.trust_level
self.save_to_disk()
def forget(self, source_hash): def forget(self, source_hash):
if source_hash in self.directory_entries: if source_hash in self.directory_entries:
self.directory_entries.pop(source_hash) self.directory_entries.pop(source_hash)

View File

@ -30,7 +30,6 @@ class NomadNetworkApp:
START_ANNOUNCE_DELAY = 3 START_ANNOUNCE_DELAY = 3
def exit_handler(self): def exit_handler(self):
RNS.log("Nomad Network Client exit handler executing...", RNS.LOG_VERBOSE)
self.should_run_jobs = False self.should_run_jobs = False
RNS.log("Saving directory...", RNS.LOG_VERBOSE) RNS.log("Saving directory...", RNS.LOG_VERBOSE)

View File

@ -294,9 +294,6 @@ class ConversationsDisplay():
self.app.directory.remember(entry) self.app.directory.remember(entry)
new_conversation = nomadnet.Conversation(source_hash_text, nomadnet.NomadNetworkApp.get_shared_instance(), initiator=True) 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() self.update_conversation_list()

View File

@ -127,6 +127,9 @@ class AnnounceInfo(urwid.WidgetWrap):
if is_node: if is_node:
node_ident = RNS.Identity.recall(source_hash) 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_hash = RNS.Destination.hash_from_name_and_identity("lxmf.delivery", node_ident)
op_str = self.app.directory.simplest_display_str(op_hash) 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") nomadnet.NomadNetworkApp.get_shared_instance().ui.main_display.frame.set_focus("header")
elif key == "down": elif key == "down":
nomadnet.NomadNetworkApp.get_shared_instance().ui.main_display.sub_displays.network_display.left_pile.set_focus(1) 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): class KnownNodes(urwid.WidgetWrap):