diff --git a/LXMF/LXMRouter.py b/LXMF/LXMRouter.py index 0a603ed..aa0578a 100644 --- a/LXMF/LXMRouter.py +++ b/LXMF/LXMRouter.py @@ -536,6 +536,12 @@ class LXMRouter: def information_storage_size(self): pass + def delivery_link_available(self, destination_hash): + if destination_hash in self.direct_links or destination_hash in self.backchannel_links: + return True + else: + return False + ### Utility & Maintenance ############################# ####################################################### @@ -1746,7 +1752,7 @@ class LXMRouter: # Prepare link for backchannel communications delivery_destination_hash = lxmessage.get_destination().hash - if delivery_destination_hash in self.direct_links: + if lxmessage.method == LXMessage.DIRECT and delivery_destination_hash in self.direct_links: direct_link = self.direct_links[delivery_destination_hash] if not hasattr(direct_link, "backchannel_identified") or direct_link.backchannel_identified == False: if direct_link.initiator == True: diff --git a/LXMF/LXMessage.py b/LXMF/LXMessage.py index 21334a8..253085b 100644 --- a/LXMF/LXMessage.py +++ b/LXMF/LXMessage.py @@ -372,8 +372,16 @@ class LXMessage: # one will be chosen according to these rules: if self.desired_method == None: self.desired_method = LXMessage.DIRECT - # TODO: Expand rules to something more intelligent + + # If opportunistic delivery was requested, check + # that message will fit within packet size limits + if self.desired_method == LXMessage.OPPORTUNISTIC: + if self.__destination.type == RNS.Destination.SINGLE: + if content_size > LXMessage.ENCRYPTED_PACKET_MAX_CONTENT: + RNS.log(f"Opportunistic delivery was requested for {self}, but content exceeds packet size limit. Falling back to link-based delivery.", RNS.LOG_DEBUG) + self.desired_method = LXMessage.DIRECT + # Set delivery parameters according to delivery method if self.desired_method == LXMessage.OPPORTUNISTIC: if self.__destination.type == RNS.Destination.SINGLE: single_packet_content_limit = LXMessage.ENCRYPTED_PACKET_MAX_CONTENT @@ -434,6 +442,7 @@ class LXMessage: if self.method == LXMessage.OPPORTUNISTIC: lxm_packet = self.__as_packet() lxm_packet.send().set_delivery_callback(self.__mark_delivered) + self.progress = 0.50 self.ratchet_id = lxm_packet.ratchet_id self.state = LXMessage.SENT