Compare commits

..
7 Commits
2 changed files with 45 additions and 16 deletions

No files matched your search

+43 -14
View File
@@ -228,7 +228,7 @@ class LXMessage:
# If no desired delivery method has been defined, # If no desired delivery method has been defined,
# one will be chosen according to these rules: # one will be chosen according to these rules:
if self.desired_method == None: if self.desired_method == None:
self.desired_method == LXMessage.DIRECT self.desired_method = LXMessage.DIRECT
# TODO: Expand rules to something more intelligent # TODO: Expand rules to something more intelligent
if self.desired_method == LXMessage.OPPORTUNISTIC: if self.desired_method == LXMessage.OPPORTUNISTIC:
@@ -282,8 +282,12 @@ class LXMessage:
if self.representation == LXMessage.PACKET: if self.representation == LXMessage.PACKET:
receipt = self.__as_packet().send() receipt = self.__as_packet().send()
receipt.set_delivery_callback(self.__mark_delivered) if receipt:
receipt.set_timeout_callback(self.__link_packet_timed_out) receipt.set_delivery_callback(self.__mark_delivered)
receipt.set_timeout_callback(self.__link_packet_timed_out)
else:
if self.__delivery_destination:
self.__delivery_destination.teardown()
elif self.representation == LXMessage.RESOURCE: elif self.representation == LXMessage.RESOURCE:
self.resource_representation = self.__as_resource() self.resource_representation = self.__as_resource()
@@ -308,7 +312,7 @@ class LXMessage:
if self.__destination.type == RNS.Destination.SINGLE: if self.__destination.type == RNS.Destination.SINGLE:
self.transport_encrypted = True self.transport_encrypted = True
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC
elif destination_type == RNS.Destination.GROUP: elif self.__destination.type == RNS.Destination.GROUP:
self.transport_encrypted = True self.transport_encrypted = True
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_AES self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_AES
else: else:
@@ -335,15 +339,21 @@ class LXMessage:
RNS.log("Received delivery notification for "+str(self), RNS.LOG_DEBUG) RNS.log("Received delivery notification for "+str(self), RNS.LOG_DEBUG)
self.state = LXMessage.DELIVERED self.state = LXMessage.DELIVERED
if self.__delivery_callback != None: if self.__delivery_callback != None and callable(self.__delivery_callback):
self.__delivery_callback(self) try:
self.__delivery_callback(self)
except Exception as e:
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
def __mark_propagated(self, receipt = None): def __mark_propagated(self, receipt = None):
RNS.log("Received propagation success notification for "+str(self), RNS.LOG_DEBUG) RNS.log("Received propagation success notification for "+str(self), RNS.LOG_DEBUG)
self.state = LXMessage.SENT self.state = LXMessage.SENT
if self.__delivery_callback != None: if self.__delivery_callback != None and callable(self.__delivery_callback):
self.__delivery_callback(self) try:
self.__delivery_callback(self)
except Exception as e:
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
def __resource_concluded(self, resource): def __resource_concluded(self, resource):
if resource.status == RNS.Resource.COMPLETE: if resource.status == RNS.Resource.COMPLETE:
@@ -833,6 +843,8 @@ class LXMRouter:
self.direct_links = {} self.direct_links = {}
self.delivery_destinations = {} self.delivery_destinations = {}
self.ignored_list = []
self.processing_outbound = False self.processing_outbound = False
self.processing_inbound = False self.processing_inbound = False
self.processing_count = 0 self.processing_count = 0
@@ -1126,8 +1138,15 @@ class LXMRouter:
message.transport_encrypted = False message.transport_encrypted = False
message.transport_encryption = None message.transport_encryption = None
if self.__delivery_callback != None: if message.source_hash in self.ignored_list:
self.__delivery_callback(message) RNS.log(str(self)+" ignored message from "+RNS.prettyhexrep(message.source_hash), RNS.LOG_DEBUG)
return False
if self.__delivery_callback != None and callable(self.__delivery_callback):
try:
self.__delivery_callback(message)
except Exception as e:
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
return True return True
@@ -1573,16 +1592,23 @@ class LXMRouter:
RNS.log("Selected waiting peer "+str(selected_index)+": "+RNS.prettyhexrep(selected_peer.destination.hash), RNS.LOG_DEBUG) RNS.log("Selected waiting peer "+str(selected_index)+": "+RNS.prettyhexrep(selected_peer.destination.hash), RNS.LOG_DEBUG)
selected_peer.sync() selected_peer.sync()
for peer in culled_peers: for peer_id in culled_peers:
RNS.log("Removing peer "+RNS.prettyhexrep(peer)+" due to excessive unreachability", RNS.LOG_WARNING) RNS.log("Removing peer "+RNS.prettyhexrep(peer_id)+" due to excessive unreachability", RNS.LOG_WARNING)
try: try:
# TODO: Check this
if peer_id in self.peers: if peer_id in self.peers:
self.peers.pop(peer_id) self.peers.pop(peer_id)
except Exception as e: except Exception as e:
RNS.log("Error while removing peer "+RNS.prettyhexrep(peer_id)+". The contained exception was: "+str(e), RNS.LOG_ERROR) RNS.log("Error while removing peer "+RNS.prettyhexrep(peer_id)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
def ignore_destination(self, destination_hash):
if not destination_hash in self.ignored_list:
self.ignored_list.append(destination_hash)
def unignore_destination(self, destination_hash):
if destination_hash in self.ignored_list:
self.ignored_list.remove(destination_hash)
def fail_message(self, lxmessage): def fail_message(self, lxmessage):
RNS.log(str(lxmessage)+" failed to send", RNS.LOG_DEBUG) RNS.log(str(lxmessage)+" failed to send", RNS.LOG_DEBUG)
@@ -1590,9 +1616,12 @@ class LXMRouter:
self.failed_outbound.append(lxmessage) self.failed_outbound.append(lxmessage)
lxmessage.state = LXMessage.FAILED lxmessage.state = LXMessage.FAILED
if lxmessage.failed_callback != None: if lxmessage.failed_callback != None and callable(lxmessage.failed_callback):
lxmessage.failed_callback(lxmessage) lxmessage.failed_callback(lxmessage)
def __str__(self):
return "<LXMRouter "+RNS.hexrep(self.identity.hash, delimit=False)+">"
def process_outbound(self, sender = None): def process_outbound(self, sender = None):
if self.processing_outbound: if self.processing_outbound:
return return
+2 -2
View File
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
setuptools.setup( setuptools.setup(
name="lxmf", name="lxmf",
version="0.1.4", version="0.1.6",
author="Mark Qvist", author="Mark Qvist",
author_email="mark@unsigned.io", author_email="mark@unsigned.io",
description="Lightweight Extensible Message Format for Reticulum", description="Lightweight Extensible Message Format for Reticulum",
@@ -18,6 +18,6 @@ setuptools.setup(
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Operating System :: OS Independent", "Operating System :: OS Independent",
], ],
install_requires=['rns>=0.3.4'], install_requires=['rns>=0.3.6'],
python_requires='>=3.6', python_requires='>=3.6',
) )