diff --git a/LXMF/LXMRouter.py b/LXMF/LXMRouter.py index 30788c9..3dea0cd 100644 --- a/LXMF/LXMRouter.py +++ b/LXMF/LXMRouter.py @@ -84,6 +84,7 @@ class LXMRouter: raise ValueError("LXMF cannot be initialised without a storage path") else: self.storagepath = storagepath+"/lxmf" + self.ratchetpath = self.storagepath+"/ratchets" self.outbound_propagation_node = None self.outbound_propagation_link = None @@ -174,7 +175,11 @@ class LXMRouter: da_thread.start() def register_delivery_identity(self, identity, display_name = None): + if not os.path.isdir(self.ratchetpath): + os.makedirs(self.ratchetpath) + delivery_destination = RNS.Destination(identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, "delivery") + delivery_destination.enable_ratchets(f"{self.ratchetpath}/{RNS.hexrep(delivery_destination.hash, delimit=False)}.ratchets") delivery_destination.set_packet_callback(self.delivery_packet) delivery_destination.set_link_established_callback(self.delivery_link_established) delivery_destination.display_name = display_name @@ -971,6 +976,7 @@ class LXMRouter: self.__delivery_callback(message) except Exception as e: RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR) + RNS.trace_exception(e) return True diff --git a/LXMF/LXMessage.py b/LXMF/LXMessage.py index 5b7721c..e8dd1db 100644 --- a/LXMF/LXMessage.py +++ b/LXMF/LXMessage.py @@ -351,6 +351,7 @@ class LXMessage: def determine_transport_encryption(self): + # TODO: Update transport encryption descriptions to account for ratchets if self.method == LXMessage.OPPORTUNISTIC: if self.__destination.type == RNS.Destination.SINGLE: self.transport_encrypted = True diff --git a/docs/example_receiver.py b/docs/example_receiver.py index a637cd4..75c628e 100644 --- a/docs/example_receiver.py +++ b/docs/example_receiver.py @@ -34,4 +34,21 @@ my_lxmf_destination = router.register_delivery_identity(identity) router.register_delivery_callback(delivery_callback) RNS.log("Ready to receive on: "+RNS.prettyhexrep(my_lxmf_destination.hash)) -input() \ No newline at end of file + + +# You can set a propagation node address to test receiving +# messages from a propagation node, instead of directly + +# router.set_outbound_propagation_node(bytes.fromhex("e75d9b6a69f82b48b6077cf2242d7499")) + + +# This loop allows you to execute various actions for testing +# and experimenting with the example scripts. +while True: + input() + RNS.log("Announcing lxmf.delivery destination...") + my_lxmf_destination.announce() + + # input() + # RNS.log("Requesting messages from propagation node...") + # router.request_messages_from_propagation_node(identity) \ No newline at end of file diff --git a/docs/example_sender.py b/docs/example_sender.py index ab15a16..3dc6494 100644 --- a/docs/example_sender.py +++ b/docs/example_sender.py @@ -4,7 +4,7 @@ import time import random random_names = ["Tom", "Delilah", "Nancey", "Williams", "Neomi", "Curtis", "Alexa", "Theodora", "Ted", "Dinorah", "Nicol", "Drusilla", "Annalisa", "Verlene", "Latesha", "Tina", "Mia", "Brock", "Timothy", "Philip", "Willian", "Reyna", "Simona", "Mimi", "Stanford", "Ferne", "Catalina", "Lucie", "Jaye", "Natasha", "Willetta", "Isabel", "Esperanza", "Ciara", "Eusebio", "William", "Elma", "Angelica", "Coreen", "Melani", "Jonathan", "Maryland", "Caroline", "Gregg", "Ora", "Jacqui", "Letty", "Roselle", "Oralee", "Angla"] -random_titles = ["Long time", "Hi again", "Re: Hi there", "Test message", "", "", "Something different"] +random_titles = ["Long time", "Hi again", "Hi there", "Test message", "", "", "Something different"] random_msgs = ["If wishes were horses then beggars might fly. Stuff like that. It's enough to drive you crazy.", "'My ident cards were stolen,' Jason said. 'That fivehundred-dollar bill is yours if you can get me to someone who can replace them. If you're going to do it, do it right now; I'm not going to wait.' Wait to be picked up by a pol or a nat, he thought. Caught here in this rundown dingy hotel.", "A six, no matter what the external circumstances, will always prevail. Because that's the way they genetically defined us.", "'Should be there in an hour,' he called back over his shoulder to Chuck. Then he added, in an afterthought, 'Wonder if the computer’s finished its run. It was due about now.'. Chuck didn’t reply, so George swung round in his saddle. He could just see Chuck’s face, a white oval turned toward the sky."] def delivery_callback(message): @@ -33,7 +33,37 @@ recipient_identity = RNS.Identity.recall(recipient_hash) dest = RNS.Destination(recipient_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, "lxmf", "delivery") +# This loop allows you to execute various actions for testing +# and experimenting with the example scripts. while True: - lxm = LXMF.LXMessage(dest, source, random_msgs[random.randint(0,len(random_msgs)-1)], random_titles[random.randint(0,len(random_titles)-1)], desired_method=LXMF.LXMessage.DIRECT) + + # Create a message that will be sent directly to the + # destination over a Reticulum link: + + lxm = LXMF.LXMessage(dest, source, random_msgs[random.randint(0,len(random_msgs)-1)], + random_titles[random.randint(0,len(random_titles)-1)], + desired_method=LXMF.LXMessage.DIRECT) + + # Or, create an oppertunistic, single-packet message + # for sending without first establishing a link: + + # lxm = LXMF.LXMessage(dest, source, "This is a test", + # random_titles[random.randint(0,len(random_titles)-1)], + # desired_method=LXMF.LXMessage.OPPORTUNISTIC) + + + # Or, try sending the message via a propagation node: + + # router.set_outbound_propagation_node(bytes.fromhex("e75d9b6a69f82b48b6077cf2242d7499")) + # lxm = LXMF.LXMessage(dest, source, random_msgs[random.randint(0,len(random_msgs)-1)], + # random_titles[random.randint(0,len(random_titles)-1)], + # desired_method=LXMF.LXMessage.PROPAGATED) + + # Finally dispatch the message to the LXMF message + # router, which will handle the delivery according + # to the specified message parameters and options: + router.handle_outbound(lxm) + + # Wait for user input before starting over input() \ No newline at end of file