Create multiple LXM Routers with different identities #547
-
QuestionHow do I create multiple LXM Routers with different identities in a single application. My goal is to provide multiple LXMF destinations, created from different identities, for interaction with an application. My naive approachMy naive approach looks like this (simplified): message_router1 = LXMF.LXMRouter(identity1, storagepath1)
message_router2 = LXMF.LXMRouter(identity2, storagepath2) Which produces the following error: Attempt to register an already registered destination.
DisclaimerI do not know anything about LXMF besides the examples Mark provided. My naive "solution" at the end is most likely not a good solution since I clearly wander in forbidden land here. I do not even know what a There probably is a much more adequate way to go about this problem without the "need" to change RNS source code. ProblemIt appears that every LXM Router creates three destinations:
The LXMF.LXMRouter.py (line: 120): self.lxmf_query_destination = RNS.Destination(None, RNS.Destination.IN, RNS.Destination.PLAIN, APP_NAME, "query") My naive "Solution"The original code prevents the registration of existing destinations by raising an error. This prevents the creation of multiple LXM Routers, at least in the way I go about it as explained above. RNS.Transport.py (line 1948): def register_destination(destination):
destination.MTU = RNS.Reticulum.MTU
if destination.direction == RNS.Destination.IN:
for registered_destination in Transport.destinations:
if destination.hash == registered_destination.hash:
raise KeyError("Attempt to register an already registered destination.")
Transport.destinations.append(destination)
if Transport.owner.is_connected_to_shared_instance:
if destination.type == RNS.Destination.SINGLE:
destination.announce(path_response=True) My naive "solution" prevents the registration of existing destinations by skipping. By doing so I can create multiple LXM Routers, but only ONE def register_destination(destination):
destination.MTU = RNS.Reticulum.MTU
if destination.direction == RNS.Destination.IN:
destination_exists = False
for registered_destination in Transport.destinations:
if destination.hash == registered_destination.hash:
# raise KeyError(f"RNS.Transport() Attempt to register an already registered destination. {destination}") # r8io
destination_exists = True
RNS.log(f"RNS.Transport() Attempt to register an already registered destination. {destination}", level=2)
continue
if not destination_exists:
Transport.destinations.append(destination)
RNS.log(f"RNS.Transport() Registered destination. {destination}")
if Transport.owner.is_connected_to_shared_instance:
if destination.type == RNS.Destination.SINGLE:
destination.announce(path_response=True) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks for your detailed post about this! Fortunately, the real fix is very easy. The Thanks for spotting and investigating it! You should be able to pull the latest source from the repo and do as you want now :) |
Beta Was this translation helpful? Give feedback.
-
Thank you for for your quick reply and the easy fix! I feel like the blind hen that found a kernel of grain ... relay happy :-) It works nicely now. |
Beta Was this translation helpful? Give feedback.
Thanks for your detailed post about this! Fortunately, the real fix is very easy. The
query_destination
is a very old artifact on a very old version of LXMF, and it has not been used for anything for about three years. The fix is to remove it, as I have just done in commit this commit.Thanks for spotting and investigating it!
You should be able to pull the latest source from the repo and do as you want now :)