From a720dfa9d8ecffab68a76a57e62846fd386d7e09 Mon Sep 17 00:00:00 2001 From: Jeremy O'Brien <956a74d715fe9cb2e9da0a19b067b414> Date: Fri, 10 Jul 2026 16:36:55 -0400 Subject: [PATCH] fix path resolution when using a shared-instance rnsd --- nomadnet/Conversation.py | 45 +++++++++++++++++------------ nomadnet/ui/textui/Conversations.py | 21 ++++++++++++-- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/nomadnet/Conversation.py b/nomadnet/Conversation.py index c543d9c..b966093 100644 --- a/nomadnet/Conversation.py +++ b/nomadnet/Conversation.py @@ -15,8 +15,9 @@ class Conversation: created_callback = None aspect_filter = "lxmf.delivery" + receive_path_responses = True @staticmethod - def received_announce(destination_hash, announced_identity, app_data): + def received_announce(destination_hash, announced_identity, app_data, announce_packet_hash=None, is_path_response=False): app = nomadnet.NomadNetworkApp.get_shared_instance() if not display_name_from_app_data(app_data): @@ -32,15 +33,16 @@ class Conversation: if Conversation.created_callback != None: Conversation.created_callback() - # This reformats the new v0.5.0 announce data back to the expected format - # for nomadnets storage and other handling functions. - dn = LXMF.display_name_from_app_data(app_data) - app_data = b"" - if dn != None: app_data = dn.encode("utf-8") + if not is_path_response: + # This reformats the new v0.5.0 announce data back to the expected format + # for nomadnets storage and other handling functions. + dn = LXMF.display_name_from_app_data(app_data) + app_data = b"" + if dn != None: app_data = dn.encode("utf-8") - # Add the announce to the directory announce - # stream logger - app.directory.lxmf_announce_received(destination_hash, app_data) + # Add the announce to the directory announce + # stream logger + app.directory.lxmf_announce_received(destination_hash, app_data) else: RNS.log("Ignored announce from "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG) @@ -202,15 +204,9 @@ class Conversation: self.__changed_callback = None - if not RNS.Identity.recall(bytes.fromhex(self.source_hash)): + if not self.__resolve_send_destination(): RNS.Transport.request_path(bytes.fromhex(source_hash)) - self.source_identity = RNS.Identity.recall(bytes.fromhex(self.source_hash)) - - if self.source_identity: - self.source_known = True - self.send_destination = RNS.Destination(self.source_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, "lxmf", "delivery") - if initiator: if not os.path.isdir(self.messages_path): os.makedirs(self.messages_path) @@ -293,8 +289,18 @@ class Conversation: def register_changed_callback(self, callback): self.__changed_callback = callback + def __resolve_send_destination(self): + if self.send_destination == None: + self.source_identity = RNS.Identity.recall(bytes.fromhex(self.source_hash)) + + if self.source_identity: + self.source_known = True + self.send_destination = RNS.Destination(self.source_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, "lxmf", "delivery") + + return self.send_destination != None + def send(self, content="", title="", fields=None): - if self.send_destination: + if self.__resolve_send_destination(): dest = self.send_destination source = self.app.lxmf_destination desired_method = LXMF.LXMessage.DIRECT @@ -324,11 +330,12 @@ class Conversation: return True else: - RNS.log("Destination is not known, cannot create LXMF Message.", RNS.LOG_VERBOSE) + RNS.log("Destination is not known, cannot create LXMF Message. Requesting path...", RNS.LOG_VERBOSE) + RNS.Transport.request_path(bytes.fromhex(self.source_hash)) return False def paper_output(self, content="", title="", mode="print_qr"): - if self.send_destination: + if self.__resolve_send_destination(): try: dest = self.send_destination source = self.app.lxmf_destination diff --git a/nomadnet/ui/textui/Conversations.py b/nomadnet/ui/textui/Conversations.py index f022206..feaedc9 100644 --- a/nomadnet/ui/textui/Conversations.py +++ b/nomadnet/ui/textui/Conversations.py @@ -242,13 +242,24 @@ class ConversationsDisplay(): except Exception: pass - nomadnet.Conversation.created_callback = lambda: self._wake(self.update_conversation_list) + nomadnet.Conversation.created_callback = lambda: self._wake(self._conversations_changed) try: self.app.ui.loop.set_alarm_in(30.0, self._refresh_sync_status) except Exception: pass + def _conversations_changed(self): + self.update_conversation_list() + # If the identity keys for the displayed conversation just + # became known, enable its editor without requiring the user + # to close and reopen the conversation. + if self.currently_displayed_conversation != None: + widget = ConversationsDisplay.cached_conversation_widgets.get(self.currently_displayed_conversation) + if widget != None: + widget.check_editor_allowed() + widget._update_peer_info() + def _process_pending(self, data): while True: try: @@ -1890,6 +1901,7 @@ class ConversationWidget(urwid.WidgetWrap): self.sort_by_timestamp = False self.pending_attachments = [] self.dialog_active = False + self.editor_allowed = None self.update_message_widgets() @@ -2187,14 +2199,17 @@ class ConversationWidget(urwid.WidgetWrap): g = self.app.ui.glyphs if self.frame: allowed = nomadnet.NomadNetworkApp.get_shared_instance().directory.is_known(bytes.fromhex(self.source_hash)) + if allowed == self.editor_allowed: + return + self.editor_allowed = allowed if allowed: self.frame.contents["footer"] = (self._build_footer(), None) else: warning = urwid.AttrMap( urwid.Padding(urwid.Text( "\n"+g["info"]+"\n\nYou cannot currently message this peer, since its identity keys are not known. " - "The keys have been requested from the network and should arrive shortly, if available. " - "Close this conversation and reopen it to try again.\n\n" + "The keys have been requested from the network, and you will be able to send messages " + "as soon as they arrive.\n\n" "To query the network manually, select this conversation in the conversation list, " "press Ctrl-E, and use the query button.\n", align=urwid.CENTER,