allow user to configure a preferred propagation node

This commit is contained in:
liamcottle 2024-09-18 17:42:25 +12:00
commit fcbb6a8f25
2 changed files with 67 additions and 1 deletions

View file

@ -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:

View file

@ -48,6 +48,35 @@
</div>
</div>
<!-- propagation nodes -->
<div class="bg-white rounded shadow">
<div class="flex border-b border-gray-300 text-gray-700 p-2 font-semibold">Propagation Nodes</div>
<div class="divide-y text-gray-900">
<div class="p-2">
<div class="text-sm text-gray-700">
<ul class="list-disc list-inside">
<li>When you send a message, the intended recipient may be offline and your message will fail to send.</li>
<li>Instead, messages can be sent to propagation nodes, which store the messages and allow recipients to retrieve them when they're next online.</li>
<li>Propagation nodes automatically peer and sync messages with each other, creating an encrypted, distributed message store.</li>
<li>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.</li>
</ul>
</div>
</div>
<div class="p-2">
<div>
<label class="text-sm font-medium text-gray-900">Preferred Propagation Node</label>
</div>
<div class="flex">
<input v-model="config.lxmf_preferred_propagation_node_destination_hash" @input="onLxmfPreferredPropagationNodeDestinationHashChange" type="text" placeholder="Destination Hash. e.g: a39610c89d18bb48c73e429582423c24" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5">
</div>
<div class="text-sm text-gray-700">When provided, messages that fail to send will automatically send to this propagation node.</div>
</div>
</div>
</div>
</div>
</div>
</template>
@ -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,
});
},
},
}
</script>