From fcbb6a8f25ae0c781ab9a495582b0f6e06b8ca46 Mon Sep 17 00:00:00 2001 From: liamcottle Date: Wed, 18 Sep 2024 17:42:25 +1200 Subject: [PATCH] allow user to configure a preferred propagation node --- meshchat.py | 33 ++++++++++++++++- .../components/settings/SettingsPage.vue | 35 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/meshchat.py b/meshchat.py index 807a43a..ea0a3bf 100644 --- a/meshchat.py +++ b/meshchat.py @@ -118,6 +118,9 @@ class ReticulumMeshChat: # set a callback for when an lxmf message is received self.message_router.register_delivery_callback(self.on_lxmf_delivery) + # update active propagation node + self.set_active_propagation_node(self.config.lxmf_preferred_propagation_node_destination_hash.get()) + # handle received announces based on aspect RNS.Transport.register_announce_handler(AnnounceHandler("call.audio", self.on_audio_call_announce_received)) RNS.Transport.register_announce_handler(AnnounceHandler("lxmf.delivery", self.on_lxmf_announce_received)) @@ -174,6 +177,22 @@ class ReticulumMeshChat: # wait 1 second before next loop await asyncio.sleep(1) + # uses the provided destination hash as the active propagation node + def set_active_propagation_node(self, destination_hash: str | None): + + # set outbound propagation node + if destination_hash is not None and destination_hash != "": + try: + self.message_router.set_outbound_propagation_node(bytes.fromhex(destination_hash)) + except: + # failed to set propagation node, clear it to ensure we don't use an old one by mistake + self.message_router.outbound_propagation_node = None + pass + + # stop using propagation node + else: + self.message_router.outbound_propagation_node = None + # handle receiving a new audio call def on_incoming_audio_call(self, audio_call: AudioCall): print("on_incoming_audio_call: {}".format(audio_call.link.hash.hex())) @@ -1197,6 +1216,16 @@ class ReticulumMeshChat: value = bool(data["show_suggested_community_interfaces"]) self.config.show_suggested_community_interfaces.set(value) + if "lxmf_preferred_propagation_node_destination_hash" in data: + + # update config value + value = data["lxmf_preferred_propagation_node_destination_hash"] + self.config.lxmf_preferred_propagation_node_destination_hash.set(value) + + # update active propagation node + self.set_active_propagation_node(value) + + # send config to websocket clients await self.send_config_to_websocket_clients() @@ -1359,6 +1388,7 @@ class ReticulumMeshChat: "auto_resend_failed_messages_when_announce_received": self.config.auto_resend_failed_messages_when_announce_received.get(), "allow_auto_resending_failed_messages_with_attachments": self.config.allow_auto_resending_failed_messages_with_attachments.get(), "show_suggested_community_interfaces": self.config.show_suggested_community_interfaces.get(), + "lxmf_preferred_propagation_node_destination_hash": self.config.lxmf_preferred_propagation_node_destination_hash.get(), } # convert audio call to dict @@ -2037,7 +2067,7 @@ class Config: # handle config values that should be strings class StringConfig: - def __init__(self, key: str, default_value: str = None): + def __init__(self, key: str, default_value: str | None = None): self.key = key self.default_value = default_value @@ -2103,6 +2133,7 @@ class Config: allow_auto_resending_failed_messages_with_attachments = BoolConfig("allow_auto_resending_failed_messages_with_attachments", False) show_suggested_community_interfaces = BoolConfig("show_suggested_community_interfaces", True) lxmf_delivery_transfer_limit_in_bytes = IntConfig("lxmf_delivery_transfer_limit_in_bytes", 1000 * 1000 * 10) # 10MB + lxmf_preferred_propagation_node_destination_hash = StringConfig("lxmf_preferred_propagation_node_destination_hash", None) class NomadnetDownloader: diff --git a/src/frontend/components/settings/SettingsPage.vue b/src/frontend/components/settings/SettingsPage.vue index dcb5897..ea44bb9 100644 --- a/src/frontend/components/settings/SettingsPage.vue +++ b/src/frontend/components/settings/SettingsPage.vue @@ -48,6 +48,35 @@ + +
+
Propagation Nodes
+
+ +
+
+
    +
  • When you send a message, the intended recipient may be offline and your message will fail to send.
  • +
  • Instead, messages can be sent to propagation nodes, which store the messages and allow recipients to retrieve them when they're next online.
  • +
  • Propagation nodes automatically peer and sync messages with each other, creating an encrypted, distributed message store.
  • +
  • By default, propagation nodes store messages for up to 30 days. If the recipient hasn't retrieved it by then, the message will be lost.
  • +
+
+
+ +
+
+ +
+
+ +
+
When provided, messages that fail to send will automatically send to this propagation node.
+
+ +
+
+ @@ -61,6 +90,7 @@ export default { auto_resend_failed_messages_when_announce_received: null, allow_auto_resending_failed_messages_with_attachments: null, show_suggested_community_interfaces: null, + lxmf_preferred_propagation_node_destination_hash: null, }, }; }, @@ -101,6 +131,11 @@ export default { "show_suggested_community_interfaces": this.config.show_suggested_community_interfaces, }); }, + async onLxmfPreferredPropagationNodeDestinationHashChange() { + await this.updateConfig({ + "lxmf_preferred_propagation_node_destination_hash": this.config.lxmf_preferred_propagation_node_destination_hash, + }); + }, }, }