Compare commits

...
19 Commits
Author SHA1 Message Date
Mark Qvist e8ba024832 Updated versions 2026-10-05 15:15:24 +02:00
Mark Qvist 5745f85647 Added outbound queue hold mechanism and improved slow-medium processing, by Zenith 2026-10-05 15:14:49 +02:00
Mark Qvist c3ff2d6dc2 Added version signalling to propagation node announce metadata 2026-09-30 14:41:07 +02:00
Mark Qvist aa7137d840 Cleanup 2026-09-30 14:01:14 +02:00
Mark Qvist 247008105a Improved outbound processing error and callback handling 2026-09-30 13:59:40 +02:00
Mark Qvist 3fc60af1ab Fixed regression introduced in 7789e0b that caused incorrect max payload size calculation for opportunistic messages, by JRG 2026-09-30 13:14:35 +02:00
Mark Qvist 3290c4e63d Cleanup 2026-09-30 11:20:09 +02:00
Mark Qvist 599bb67080 Updated versions 2026-09-28 18:48:30 +02:00
Mark Qvist db2bd9e0e5 Added micron readme 2026-09-28 17:03:51 +02:00
Mark Qvist e52016c20f Updated readme 2026-09-26 21:09:17 +02:00
Mark Qvist 6fb5a366b1 Updated versions 2026-09-25 16:19:25 +02:00
Mark Qvist 43a077b291 Ensure sequential processing in process_outbound 2026-09-25 15:19:43 +02:00
Mark Qvist 170e71d5a9 Set awaiting_path on opportunistic path rediscovery 2026-09-25 15:17:58 +02:00
Mark Qvist beac6bcd1c Use medium aware timeouts and debouncing in outbound processing, by Zenith 2026-09-25 15:11:26 +02:00
Mark Qvist acaa9e30ed Use canonical medium-aware path request handler in LXMPeer, by Zenith 2026-09-25 12:08:27 +02:00
Mark Qvist fbc821ebb9 Prepare announce handlers for medium-aware timeout handling, by Zenith 2026-09-25 12:05:34 +02:00
Mark Qvist 0889401ca1 Prepare LXMessage for medium-aware timeout handling, by Zenith 2026-09-25 11:37:35 +02:00
Mark Qvist 1dc8097212 Adjusted loglevel 2026-09-02 14:40:12 +02:00
Mark Qvist 41cdce67c1 Adjusted loglevel 2026-08-19 14:48:40 +02:00
11 changed files with 497 additions and 131 deletions

No files matched your search

-11
View File
@@ -1,11 +0,0 @@
blank_issues_enabled: false
contact_links:
- name: ✨ Feature Request or Idea
url: https://github.com/markqvist/Reticulum/discussions/new?category=ideas
about: Propose and discuss features and ideas
- name: 💬 Questions, Help & Discussion
about: Ask anything, or get help
url: https://github.com/markqvist/Reticulum/discussions/new/choose
- name: 📖 Read the Reticulum Manual
url: https://markqvist.github.io/Reticulum/manual/
about: The complete documentation for Reticulum
-35
View File
@@ -1,35 +0,0 @@
---
name: "\U0001F41B Bug Report"
about: Report a reproducible bug
title: ''
labels: ''
assignees: ''
---
**Read the Contribution Guidelines**
Before creating a bug report on this issue tracker, you **must** read the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md). Issues that do not follow the contribution guidelines **will be deleted without comment**.
- The issue tracker is used by developers of this project. **Do not use it to ask general questions, or for support requests**.
- Ideas and feature requests can be made on the [Discussions](https://github.com/markqvist/Reticulum/discussions). **Only** feature requests accepted by maintainers and developers are tracked and included on the issue tracker. **Do not post feature requests here**.
- After reading the [Contribution Guidelines](https://github.com/markqvist/Reticulum/blob/master/Contributing.md), **delete this section only** (*"Read the Contribution Guidelines"*) from your bug report, **and fill in all the other sections**.
**Describe the Bug**
A clear and concise description of what the bug is.
**To Reproduce**
Describe in detail how to reproduce the bug.
**Expected Behavior**
A clear and concise description of what you expected to happen.
**Logs & Screenshots**
Please include any relevant log output. If applicable, also add screenshots to help explain your problem.
**System Information**
- OS and version
- Python version
- Program version
**Additional context**
Add any other context about the problem here.
+2 -2
View File
@@ -22,7 +22,7 @@ class LXMFDeliveryAnnounceHandler:
for lxmessage in self.lxmrouter.pending_outbound: for lxmessage in self.lxmrouter.pending_outbound:
if destination_hash == lxmessage.destination_hash: if destination_hash == lxmessage.destination_hash:
if lxmessage.method == LXMessage.DIRECT or lxmessage.method == LXMessage.OPPORTUNISTIC: if (lxmessage.method == LXMessage.DIRECT or lxmessage.method == LXMessage.OPPORTUNISTIC) and lxmessage.awaiting_path:
lxmessage.next_delivery_attempt = time.time() lxmessage.next_delivery_attempt = time.time()
def outbound_trigger(): def outbound_trigger():
@@ -44,7 +44,7 @@ class LXMFPropagationAnnounceHandler:
if destination_hash == self.lxmrouter.get_outbound_propagation_node(): if destination_hash == self.lxmrouter.get_outbound_propagation_node():
if pn_announce_data_is_valid(app_data): if pn_announce_data_is_valid(app_data):
for lxmessage in self.lxmrouter.pending_outbound: for lxmessage in self.lxmrouter.pending_outbound:
if lxmessage.method == LXMessage.PROPAGATED: if lxmessage.method == LXMessage.PROPAGATED and lxmessage.awaiting_path:
lxmessage.next_delivery_attempt = time.time() lxmessage.next_delivery_attempt = time.time()
def outbound_trigger(): def outbound_trigger():
+2 -1
View File
@@ -135,6 +135,7 @@ PN_META_SYNC_STRATUM = 0x02
PN_META_SYNC_THROTTLE = 0x03 PN_META_SYNC_THROTTLE = 0x03
PN_META_AUTH_BAND = 0x04 PN_META_AUTH_BAND = 0x04
PN_META_UTIL_PRESSURE = 0x05 PN_META_UTIL_PRESSURE = 0x05
PN_META_IMPL_NAME = 0xFE
PN_META_CUSTOM = 0xFF PN_META_CUSTOM = 0xFF
# Supported functionality codes for signalling # Supported functionality codes for signalling
@@ -165,7 +166,7 @@ def display_name_from_app_data(app_data=None):
decoded = dn.decode("utf-8").replace("\x00", "").strip() decoded = dn.decode("utf-8").replace("\x00", "").strip()
return decoded return decoded
except Exception as e: except Exception as e:
RNS.log(f"Could not decode display name in included announce data. The contained exception was: {e}", RNS.LOG_ERROR) RNS.log(f"Could not decode display name in included announce data. The contained exception was: {e}", RNS.LOG_EXTREME)
return None return None
# Original announce format # Original announce format
+1 -1
View File
@@ -294,7 +294,7 @@ class LXMPeer:
else: else:
if not RNS.Transport.has_path(self.destination_hash): if not RNS.Transport.has_path(self.destination_hash):
RNS.log("No path to peer "+RNS.prettyhexrep(self.destination_hash)+" exists, requesting...", RNS.LOG_DEBUG) RNS.log("No path to peer "+RNS.prettyhexrep(self.destination_hash)+" exists, requesting...", RNS.LOG_DEBUG)
RNS.Transport.request_path(self.destination_hash) self.router.request_path(self.destination_hash)
time.sleep(LXMPeer.PATH_REQUEST_GRACE) time.sleep(LXMPeer.PATH_REQUEST_GRACE)
if not RNS.Transport.has_path(self.destination_hash): if not RNS.Transport.has_path(self.destination_hash):
+222 -70
View File
@@ -13,9 +13,11 @@ from collections import deque
import RNS import RNS
import RNS.vendor.umsgpack as msgpack import RNS.vendor.umsgpack as msgpack
from ._version import __version__
from .LXMF import APP_NAME from .LXMF import APP_NAME
from .LXMF import FIELD_TICKET from .LXMF import FIELD_TICKET
from .LXMF import PN_META_NAME from .LXMF import PN_META_NAME, PN_META_IMPL_NAME, PN_META_VERSION
from .LXMF import SF_COMPRESSION from .LXMF import SF_COMPRESSION
from .LXMF import pn_announce_data_is_valid from .LXMF import pn_announce_data_is_valid
@@ -31,6 +33,9 @@ class LXMRouter:
PROCESSING_INTERVAL = 4 PROCESSING_INTERVAL = 4
DELIVERY_RETRY_WAIT = 10 DELIVERY_RETRY_WAIT = 10
PATH_REQUEST_WAIT = 7 PATH_REQUEST_WAIT = 7
PATH_REQUEST_DEBOUNCE = 60
SLOW_INTERFACE_BITRATE = 2000
AIRTIME_AWARE_MTU_TIME = 0.5
MAX_PATHLESS_TRIES = 1 MAX_PATHLESS_TRIES = 1
LINK_MAX_INACTIVITY = 10*60 LINK_MAX_INACTIVITY = 10*60
P_LINK_MAX_INACTIVITY = 3*60 P_LINK_MAX_INACTIVITY = 3*60
@@ -108,6 +113,9 @@ class LXMRouter:
self.pending_outbound = [] self.pending_outbound = []
self.direct_links = {} self.direct_links = {}
self.backchannel_links = {} self.backchannel_links = {}
self.path_request_times = {}
self.slow_path_cache = {}
self.path_request_lock = threading.Lock()
self.delivery_destinations = {} self.delivery_destinations = {}
self.prioritised_list = [] self.prioritised_list = []
@@ -318,6 +326,8 @@ class LXMRouter:
def get_propagation_node_announce_metadata(self): def get_propagation_node_announce_metadata(self):
metadata = {} metadata = {}
metadata[PN_META_IMPL_NAME] = "lxmd"
metadata[PN_META_VERSION] = str(__version__)
if self.name: metadata[PN_META_NAME] = str(self.name).encode("utf-8") if self.name: metadata[PN_META_NAME] = str(self.name).encode("utf-8")
return metadata return metadata
@@ -428,8 +438,8 @@ class LXMRouter:
if not target_propagation_cost: if not target_propagation_cost:
RNS.log(f"Could not retrieve cached propagation node config. Requesting path to propagation node to get target propagation cost...", RNS.LOG_DEBUG) RNS.log(f"Could not retrieve cached propagation node config. Requesting path to propagation node to get target propagation cost...", RNS.LOG_DEBUG)
RNS.Transport.request_path(pn_destination_hash) self.request_path(pn_destination_hash)
timeout = time.time() + LXMRouter.PATH_REQUEST_WAIT timeout = time.time() + self.path_request_wait()
while not RNS.Identity.recall_app_data(pn_destination_hash) and time.time() < timeout: while not RNS.Identity.recall_app_data(pn_destination_hash) and time.time() < timeout:
time.sleep(0.5) time.sleep(0.5)
@@ -532,10 +542,10 @@ class LXMRouter:
self.outbound_propagation_link = RNS.Link(propagation_node_destination, established_callback=msg_request_established_callback) self.outbound_propagation_link = RNS.Link(propagation_node_destination, established_callback=msg_request_established_callback)
else: else:
RNS.log("No path known for message download from propagation node "+RNS.prettyhexrep(self.outbound_propagation_node)+". Requesting path...", RNS.LOG_DEBUG) RNS.log("No path known for message download from propagation node "+RNS.prettyhexrep(self.outbound_propagation_node)+". Requesting path...", RNS.LOG_DEBUG)
RNS.Transport.request_path(self.outbound_propagation_node) self.request_path(self.outbound_propagation_node)
self.wants_download_on_path_available_from = self.outbound_propagation_node self.wants_download_on_path_available_from = self.outbound_propagation_node
self.wants_download_on_path_available_to = identity self.wants_download_on_path_available_to = identity
self.wants_download_on_path_available_timeout = time.time() + LXMRouter.PR_PATH_TIMEOUT self.wants_download_on_path_available_timeout = time.time() + max(LXMRouter.PR_PATH_TIMEOUT, self.path_request_wait())
self.propagation_transfer_state = LXMRouter.PR_PATH_REQUESTED self.propagation_transfer_state = LXMRouter.PR_PATH_REQUESTED
self.request_messages_path_job() self.request_messages_path_job()
else: else:
@@ -617,7 +627,7 @@ class LXMRouter:
peer = LXMPeer.from_bytes(serialised_peer, self) peer = LXMPeer.from_bytes(serialised_peer, self)
del serialised_peer del serialised_peer
if peer.destination_hash in self.static_peers and peer.last_heard == 0: if peer.destination_hash in self.static_peers and peer.last_heard == 0:
RNS.Transport.request_path(peer.destination_hash) self.request_path(peer.destination_hash)
if peer.identity != None: if peer.identity != None:
self.peers[peer.destination_hash] = peer self.peers[peer.destination_hash] = peer
lim_str = ", no transfer limit" lim_str = ", no transfer limit"
@@ -639,7 +649,7 @@ class LXMRouter:
# TODO: Allow path request responses through announce handler # TODO: Allow path request responses through announce handler
# momentarily here, so peering config can be updated even if # momentarily here, so peering config can be updated even if
# the static peer is not available to directly send an announce. # the static peer is not available to directly send an announce.
RNS.Transport.request_path(static_peer) self.request_path(static_peer)
RNS.log(f"Rebuilt synchronisation state for {len(self.peers)} peers in {RNS.prettytime(time.time()-st)}", RNS.LOG_NOTICE) RNS.log(f"Rebuilt synchronisation state for {len(self.peers)} peers in {RNS.prettytime(time.time()-st)}", RNS.LOG_NOTICE)
@@ -1743,6 +1753,112 @@ class LXMRouter:
RNS.log(f"An error occurred while cancelling {lxmessage}: {e}", RNS.LOG_ERROR) RNS.log(f"An error occurred while cancelling {lxmessage}: {e}", RNS.LOG_ERROR)
RNS.trace_exception(e) RNS.trace_exception(e)
def medium_path_timeout(self):
try: return RNS.Reticulum.get_instance().get_medium_path_timeout()
except Exception: return 0
def destination_round_trip(self, destination_hash):
if not RNS.Transport.has_path(destination_hash): return self.medium_path_timeout()
try:
mtu_time = RNS.Reticulum.get_instance().get_first_hop_timeout(destination_hash) - RNS.Reticulum.DEFAULT_PER_HOP_TIMEOUT
return 2 * max(mtu_time, 0) + RNS.Reticulum.DEFAULT_PER_HOP_TIMEOUT
except Exception: return 0
def path_request_wait(self):
return max(LXMRouter.PATH_REQUEST_WAIT, self.medium_path_timeout())
def slow_interface_online(self):
try: bitrate = RNS.Reticulum.get_instance().get_lowest_interface_bitrate()
except Exception: return False
return bitrate != None and bitrate < LXMRouter.SLOW_INTERFACE_BITRATE
def request_path(self, destination_hash):
if self.slow_interface_online(): window = LXMRouter.PATH_REQUEST_DEBOUNCE
else: window = self.path_request_wait()
with self.path_request_lock:
now = time.time()
if destination_hash in self.path_request_times and now - self.path_request_times[destination_hash] < window:
RNS.log(f"Path request for {RNS.prettyhexrep(destination_hash)} still pending, not repeating within {RNS.prettytime(window)}", RNS.LOG_DEBUG)
return False
self.path_request_times = {d: t for d, t in self.path_request_times.items() if now - t < window}
self.path_request_times[destination_hash] = now
RNS.Transport.request_path(destination_hash)
return True
def path_request_pending(self, destination_hash):
window = self.path_request_wait()
with self.path_request_lock:
if not destination_hash in self.path_request_times: return False
return time.time() - self.path_request_times[destination_hash] < window
def attempt_limit(self, lxmessage):
if lxmessage.max_delivery_attempts == None: return LXMRouter.MAX_DELIVERY_ATTEMPTS
else: return lxmessage.max_delivery_attempts
def attempt_due(self, lxmessage, destination_hash):
if not hasattr(lxmessage, "next_delivery_attempt"): return True
if time.time() > lxmessage.next_delivery_attempt: return True
return lxmessage.awaiting_path and RNS.Transport.has_path(destination_hash)
def schedule_attempt(self, lxmessage, destination_hash, path_request = False):
if path_request:
round_trip = self.medium_path_timeout()
lxmessage.next_delivery_attempt = time.time() + max(LXMRouter.PATH_REQUEST_WAIT, round_trip)
lxmessage.awaiting_path = True
else:
round_trip = self.destination_round_trip(destination_hash)
lxmessage.next_delivery_attempt = time.time() + max(LXMRouter.DELIVERY_RETRY_WAIT, round_trip)
if round_trip > LXMRouter.DELIVERY_RETRY_WAIT: lxmessage.max_delivery_attempts = max(3, round(LXMRouter.MAX_DELIVERY_ATTEMPTS * LXMRouter.DELIVERY_RETRY_WAIT / round_trip))
else: lxmessage.max_delivery_attempts = LXMRouter.MAX_DELIVERY_ATTEMPTS
mtu_time = max(round_trip - RNS.Reticulum.DEFAULT_PER_HOP_TIMEOUT, 0) / 2
if mtu_time > LXMRouter.AIRTIME_AWARE_MTU_TIME:
lxmessage.next_delivery_attempt += random.uniform(0, mtu_time)
retry_wait = max(LXMRouter.DELIVERY_RETRY_WAIT, round_trip) + mtu_time
remaining_attempts = max(1, lxmessage.max_delivery_attempts - lxmessage.delivery_attempts + 1)
lxmessage.receipt_timeout = retry_wait * remaining_attempts + LXMRouter.PROCESSING_INTERVAL
else: lxmessage.receipt_timeout = None
def slow_path(self, destination_hash):
now = time.time()
cached = self.slow_path_cache.get(destination_hash)
if cached and now - cached[1] < LXMRouter.PROCESSING_INTERVAL: return cached[0]
if len(self.slow_path_cache) > 256: self.slow_path_cache = {}
slow = self.destination_round_trip(destination_hash) > LXMRouter.DELIVERY_RETRY_WAIT
self.slow_path_cache[destination_hash] = (slow, now)
return slow
def outbound_target(self, lxmessage):
if lxmessage.method == LXMessage.PROPAGATED: return self.outbound_propagation_node
else: return lxmessage.destination_hash
def slow_path_in_flight(self, lxmessage):
if not getattr(lxmessage, "sent_on_slow_path", False): return False
if lxmessage.method == LXMessage.OPPORTUNISTIC: return lxmessage.state == LXMessage.SENT
else: return lxmessage.state == LXMessage.SENDING
def slow_path_held(self, lxmessage, target_hash):
if lxmessage.state != LXMessage.OUTBOUND: return False
if not self.slow_path(target_hash): return False
ahead = True
for other in self.pending_outbound:
if other == lxmessage: ahead = False
elif other.state in [LXMessage.DELIVERED, LXMessage.FAILED, LXMessage.CANCELLED, LXMessage.REJECTED]: continue
elif other.method == LXMessage.PROPAGATED and other.state == LXMessage.SENT: continue
elif ahead and self.outbound_target(other) == target_hash: return True
elif self.slow_path_in_flight(other): return True
return False
def outbound_concluded(self, lxmessage):
if not getattr(lxmessage, "sent_on_slow_path", False): return
def job():
while self.outbound_processing_lock.locked(): time.sleep(0.1)
self.process_outbound()
threading.Thread(target=job, daemon=True).start()
def handle_outbound(self, lxmessage): def handle_outbound(self, lxmessage):
destination_hash = lxmessage.get_destination().hash destination_hash = lxmessage.get_destination().hash
@@ -1757,6 +1873,7 @@ class LXMRouter:
RNS.log(f"No stamp cost set on LXM to {RNS.prettyhexrep(destination_hash)}, autoconfigured to {stamp_cost}, as required by latest announce", RNS.LOG_DEBUG) RNS.log(f"No stamp cost set on LXM to {RNS.prettyhexrep(destination_hash)}, autoconfigured to {stamp_cost}, as required by latest announce", RNS.LOG_DEBUG)
lxmessage.state = LXMessage.OUTBOUND lxmessage.state = LXMessage.OUTBOUND
lxmessage.concluded_callback = self.outbound_concluded
# If an outbound ticket is available for this # If an outbound ticket is available for this
# destination, attach it to the message. # destination, attach it to the message.
@@ -1776,8 +1893,8 @@ class LXMRouter:
unknown_path_requested = False unknown_path_requested = False
if not RNS.Transport.has_path(destination_hash) and lxmessage.method == LXMessage.OPPORTUNISTIC: if not RNS.Transport.has_path(destination_hash) and lxmessage.method == LXMessage.OPPORTUNISTIC:
RNS.log(f"Pre-emptively requesting unknown path for opportunistic {lxmessage}", RNS.LOG_DEBUG) RNS.log(f"Pre-emptively requesting unknown path for opportunistic {lxmessage}", RNS.LOG_DEBUG)
RNS.Transport.request_path(destination_hash) self.request_path(destination_hash)
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT self.schedule_attempt(lxmessage, destination_hash, path_request=True)
unknown_path_requested = True unknown_path_requested = True
lxmessage.determine_transport_encryption() lxmessage.determine_transport_encryption()
@@ -2561,14 +2678,20 @@ class LXMRouter:
RNS.log("Error while decoding URI-encoded LXMF message. The contained exception was: "+str(e), RNS.LOG_ERROR) RNS.log("Error while decoding URI-encoded LXMF message. The contained exception was: "+str(e), RNS.LOG_ERROR)
return False return False
def __execute_failed_callback(self, lxmessage):
if lxmessage.failed_callback != None and callable(lxmessage.failed_callback):
try: lxmessage.failed_callback(lxmessage)
except Exception as e:
RNS.log(f"An error occurred while handling external message failed callback: {e}", RNS.LOG_ERROR)
RNS.trace_exception(e)
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)
lxmessage.progress = 0.0 lxmessage.progress = 0.0
if lxmessage in self.pending_outbound: self.pending_outbound.remove(lxmessage) if lxmessage in self.pending_outbound: self.pending_outbound.remove(lxmessage)
if lxmessage.state != LXMessage.REJECTED: lxmessage.state = LXMessage.FAILED if lxmessage.state != LXMessage.REJECTED: lxmessage.state = LXMessage.FAILED
if lxmessage.failed_callback != None and callable(lxmessage.failed_callback): self.__execute_failed_callback(lxmessage)
lxmessage.failed_callback(lxmessage)
def process_deferred_stamps(self): def process_deferred_stamps(self):
if len(self.pending_deferred_stamps) > 0: if len(self.pending_deferred_stamps) > 0:
@@ -2591,8 +2714,7 @@ class LXMRouter:
RNS.log(f"Message cancelled during deferred stamp generation for {selected_lxm}.", RNS.LOG_DEBUG) RNS.log(f"Message cancelled during deferred stamp generation for {selected_lxm}.", RNS.LOG_DEBUG)
selected_lxm.stamp_generation_failed = True selected_lxm.stamp_generation_failed = True
self.pending_deferred_stamps.pop(selected_message_id) self.pending_deferred_stamps.pop(selected_message_id)
if selected_lxm.failed_callback != None and callable(selected_lxm.failed_callback): self.__execute_failed_callback(lxmessage)
selected_lxm.failed_callback(lxmessage)
return return
@@ -2621,8 +2743,7 @@ class LXMRouter:
RNS.log(f"Message cancelled during deferred stamp generation for {selected_lxm}.", RNS.LOG_DEBUG) RNS.log(f"Message cancelled during deferred stamp generation for {selected_lxm}.", RNS.LOG_DEBUG)
selected_lxm.stamp_generation_failed = True selected_lxm.stamp_generation_failed = True
self.pending_deferred_stamps.pop(selected_message_id) self.pending_deferred_stamps.pop(selected_message_id)
if selected_lxm.failed_callback != None and callable(selected_lxm.failed_callback): self.__execute_failed_callback(lxmessage)
selected_lxm.failed_callback(lxmessage)
else: else:
RNS.log(f"Deferred stamp generation did not succeed. Failing {selected_lxm}.", RNS.LOG_ERROR) RNS.log(f"Deferred stamp generation did not succeed. Failing {selected_lxm}.", RNS.LOG_ERROR)
selected_lxm.stamp_generation_failed = True selected_lxm.stamp_generation_failed = True
@@ -2652,8 +2773,7 @@ class LXMRouter:
RNS.log(f"Message cancelled during deferred propagation stamp generation for {selected_lxm}.", RNS.LOG_DEBUG) RNS.log(f"Message cancelled during deferred propagation stamp generation for {selected_lxm}.", RNS.LOG_DEBUG)
selected_lxm.stamp_generation_failed = True selected_lxm.stamp_generation_failed = True
self.pending_deferred_stamps.pop(selected_message_id) self.pending_deferred_stamps.pop(selected_message_id)
if selected_lxm.failed_callback != None and callable(selected_lxm.failed_callback): self.__execute_failed_callback(lxmessage)
selected_lxm.failed_callback(lxmessage)
else: else:
RNS.log(f"Deferred propagation stamp generation did not succeed. Failing {selected_lxm}.", RNS.LOG_ERROR) RNS.log(f"Deferred propagation stamp generation did not succeed. Failing {selected_lxm}.", RNS.LOG_ERROR)
selected_lxm.stamp_generation_failed = True selected_lxm.stamp_generation_failed = True
@@ -2682,7 +2802,7 @@ class LXMRouter:
def process_outbound(self, sender = None): def process_outbound(self, sender = None):
if self.outbound_processing_lock.locked(): return if self.outbound_processing_lock.locked(): return
with self.outbound_processing_lock: with self.outbound_processing_lock:
for lxmessage in self.pending_outbound: for lxmessage in self.pending_outbound.copy():
if lxmessage.state == LXMessage.DELIVERED: if lxmessage.state == LXMessage.DELIVERED:
RNS.log("Delivery has occurred for "+str(lxmessage)+", removing from outbound queue", RNS.LOG_DEBUG) RNS.log("Delivery has occurred for "+str(lxmessage)+", removing from outbound queue", RNS.LOG_DEBUG)
self.pending_outbound.remove(lxmessage) self.pending_outbound.remove(lxmessage)
@@ -2717,14 +2837,12 @@ class LXMRouter:
elif lxmessage.state == LXMessage.CANCELLED: elif lxmessage.state == LXMessage.CANCELLED:
RNS.log("Cancellation requested for "+str(lxmessage)+", removing from outbound queue", RNS.LOG_DEBUG) RNS.log("Cancellation requested for "+str(lxmessage)+", removing from outbound queue", RNS.LOG_DEBUG)
self.pending_outbound.remove(lxmessage) self.pending_outbound.remove(lxmessage)
if lxmessage.failed_callback != None and callable(lxmessage.failed_callback): self.__execute_failed_callback(lxmessage)
lxmessage.failed_callback(lxmessage)
elif lxmessage.state == LXMessage.REJECTED: elif lxmessage.state == LXMessage.REJECTED:
RNS.log("Receiver rejected "+str(lxmessage)+", removing from outbound queue", RNS.LOG_DEBUG) RNS.log("Receiver rejected "+str(lxmessage)+", removing from outbound queue", RNS.LOG_DEBUG)
if lxmessage in self.pending_outbound: self.pending_outbound.remove(lxmessage) if lxmessage in self.pending_outbound: self.pending_outbound.remove(lxmessage)
if lxmessage.failed_callback != None and callable(lxmessage.failed_callback): self.__execute_failed_callback(lxmessage)
lxmessage.failed_callback(lxmessage)
else: else:
RNS.log("Outbound processing for "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) RNS.log("Outbound processing for "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
@@ -2733,38 +2851,56 @@ class LXMRouter:
# Outbound handling for opportunistic messages # Outbound handling for opportunistic messages
if lxmessage.method == LXMessage.OPPORTUNISTIC: if lxmessage.method == LXMessage.OPPORTUNISTIC:
if lxmessage.delivery_attempts <= LXMRouter.MAX_DELIVERY_ATTEMPTS: held = self.slow_path_held(lxmessage, lxmessage.get_destination().hash)
if lxmessage.delivery_attempts >= LXMRouter.MAX_PATHLESS_TRIES and not RNS.Transport.has_path(lxmessage.get_destination().hash): if not held and lxmessage.delivery_attempts <= self.attempt_limit(lxmessage):
RNS.log(f"Requesting path to {RNS.prettyhexrep(lxmessage.get_destination().hash)} after {lxmessage.delivery_attempts} pathless tries for {lxmessage}", RNS.LOG_DEBUG) destination_hash = lxmessage.get_destination().hash
lxmessage.delivery_attempts += 1 if self.attempt_due(lxmessage, destination_hash):
RNS.Transport.request_path(lxmessage.get_destination().hash) path_known = RNS.Transport.has_path(destination_hash)
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT lxmessage.awaiting_path = False
lxmessage.progress = 0.01 if lxmessage.delivery_attempts >= LXMRouter.MAX_PATHLESS_TRIES and not path_known:
elif lxmessage.delivery_attempts == LXMRouter.MAX_PATHLESS_TRIES+1 and RNS.Transport.has_path(lxmessage.get_destination().hash): RNS.log(f"Requesting path to {RNS.prettyhexrep(destination_hash)} after {lxmessage.delivery_attempts} pathless tries for {lxmessage}", RNS.LOG_DEBUG)
RNS.log(f"Opportunistic delivery for {lxmessage} still unsuccessful after {lxmessage.delivery_attempts} attempts, trying to rediscover path to {RNS.prettyhexrep(lxmessage.get_destination().hash)}", RNS.LOG_DEBUG)
lxmessage.delivery_attempts += 1
RNS.Reticulum.get_instance().drop_path(lxmessage.get_destination().hash)
def rediscover_job():
time.sleep(0.5)
RNS.Transport.request_path(lxmessage.get_destination().hash)
threading.Thread(target=rediscover_job, daemon=True).start()
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT
lxmessage.progress = 0.01
else:
if not hasattr(lxmessage, "next_delivery_attempt") or time.time() > lxmessage.next_delivery_attempt:
lxmessage.delivery_attempts += 1 lxmessage.delivery_attempts += 1
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT lxmessage.sent_on_path = False
RNS.log("Opportunistic delivery attempt "+str(lxmessage.delivery_attempts)+" for "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) self.request_path(destination_hash)
lxmessage.send() self.schedule_attempt(lxmessage, destination_hash, path_request=True)
else: lxmessage.progress = 0.01
elif lxmessage.delivery_attempts == LXMRouter.MAX_PATHLESS_TRIES+1 and path_known and lxmessage.sent_on_path:
# Only rediscover if the previous attempt was actually sent from same path
lxmessage.delivery_attempts += 1
lxmessage.sent_on_path = False
lxmessage.awaiting_path = True
if self.path_request_pending(destination_hash):
RNS.log(f"Opportunistic delivery for {lxmessage} still unsuccessful after {lxmessage.delivery_attempts} attempts, path to {RNS.prettyhexrep(destination_hash)} is already being rediscovered, waiting for reply", RNS.LOG_DEBUG)
else:
RNS.log(f"Opportunistic delivery for {lxmessage} still unsuccessful after {lxmessage.delivery_attempts} attempts, trying to rediscover path to {RNS.prettyhexrep(destination_hash)}", RNS.LOG_DEBUG)
with self.path_request_lock: self.path_request_times[destination_hash] = time.time()
RNS.Reticulum.get_instance().drop_path(destination_hash)
def rediscover_job():
time.sleep(0.5)
RNS.Transport.request_path(destination_hash)
threading.Thread(target=rediscover_job, daemon=True).start()
lxmessage.next_delivery_attempt = time.time() + self.path_request_wait()
lxmessage.progress = 0.01
else:
lxmessage.delivery_attempts += 1
lxmessage.sent_on_path = path_known
lxmessage.sent_on_slow_path = self.slow_path(destination_hash)
self.schedule_attempt(lxmessage, destination_hash)
RNS.log("Opportunistic delivery attempt "+str(lxmessage.delivery_attempts) +" for "+str(lxmessage)+" to "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
try: lxmessage.send()
except Exception as e:
RNS.log(f"Error while sending {lxmessage}: {e}", RNS.LOG_ERROR)
self.fail_message(lxmessage)
elif not held and self.attempt_due(lxmessage, lxmessage.get_destination().hash):
RNS.log("Max delivery attempts reached for oppertunistic "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) RNS.log("Max delivery attempts reached for oppertunistic "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
self.fail_message(lxmessage) self.fail_message(lxmessage)
# Outbound handling for messages transferred # Outbound handling for messages transferred
# over a direct link to the final recipient # over a direct link to the final recipient
elif lxmessage.method == LXMessage.DIRECT: elif lxmessage.method == LXMessage.DIRECT:
if lxmessage.delivery_attempts <= LXMRouter.MAX_DELIVERY_ATTEMPTS: delivery_destination_hash = lxmessage.get_destination().hash
delivery_destination_hash = lxmessage.get_destination().hash held = self.slow_path_held(lxmessage, delivery_destination_hash)
if not held and lxmessage.delivery_attempts <= self.attempt_limit(lxmessage):
direct_link = None direct_link = None
if delivery_destination_hash in self.direct_links: if delivery_destination_hash in self.direct_links:
@@ -2785,10 +2921,14 @@ class LXMRouter:
if direct_link.status == RNS.Link.ACTIVE: if direct_link.status == RNS.Link.ACTIVE:
if lxmessage.progress == None or lxmessage.progress < 0.05: if lxmessage.progress == None or lxmessage.progress < 0.05:
lxmessage.progress = 0.05 lxmessage.progress = 0.05
if lxmessage.state != LXMessage.SENDING: if lxmessage.state == LXMessage.OUTBOUND:
RNS.log("Starting transfer of "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" on link "+str(direct_link), RNS.LOG_DEBUG) RNS.log("Starting transfer of "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" on link "+str(direct_link), RNS.LOG_DEBUG)
lxmessage.sent_on_slow_path = self.slow_path(delivery_destination_hash)
lxmessage.set_delivery_destination(direct_link) lxmessage.set_delivery_destination(direct_link)
lxmessage.send() try: lxmessage.send()
except Exception as e:
RNS.log(f"Error while sending {lxmessage}: {e}", RNS.LOG_ERROR)
self.fail_message(lxmessage)
else: else:
if lxmessage.representation == LXMessage.RESOURCE: if lxmessage.representation == LXMessage.RESOURCE:
RNS.log("The transfer of "+str(lxmessage)+" is in progress ("+str(round(lxmessage.progress*100, 1))+"%)", RNS.LOG_DEBUG) RNS.log("The transfer of "+str(lxmessage)+" is in progress ("+str(round(lxmessage.progress*100, 1))+"%)", RNS.LOG_DEBUG)
@@ -2797,23 +2937,21 @@ class LXMRouter:
elif direct_link.status == RNS.Link.CLOSED: elif direct_link.status == RNS.Link.CLOSED:
if direct_link.activated_at != None: if direct_link.activated_at != None:
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was closed unexpectedly, retrying path request...", RNS.LOG_DEBUG) RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was closed unexpectedly, retrying path request...", RNS.LOG_DEBUG)
RNS.Transport.request_path(lxmessage.get_destination().hash) self.request_path(lxmessage.get_destination().hash)
else: else:
if not hasattr(lxmessage, "path_request_retried"): if not hasattr(lxmessage, "path_request_retried"):
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was never activated, retrying path request...", RNS.LOG_DEBUG) RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was never activated, retrying path request...", RNS.LOG_DEBUG)
RNS.Transport.request_path(lxmessage.get_destination().hash) self.request_path(lxmessage.get_destination().hash)
lxmessage.path_request_retried = True lxmessage.path_request_retried = True
else: else:
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was never activated", RNS.LOG_DEBUG) RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" was never activated", RNS.LOG_DEBUG)
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT
lxmessage.set_delivery_destination(None) lxmessage.set_delivery_destination(None)
if delivery_destination_hash in self.direct_links: if delivery_destination_hash in self.direct_links:
self.direct_links.pop(delivery_destination_hash) self.direct_links.pop(delivery_destination_hash)
if delivery_destination_hash in self.backchannel_links: if delivery_destination_hash in self.backchannel_links:
self.backchannel_links.pop(delivery_destination_hash) self.backchannel_links.pop(delivery_destination_hash)
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT if lxmessage.delivery_attempts+1 < self.attempt_limit(lxmessage): self.schedule_attempt(lxmessage, delivery_destination_hash)
else: else:
# Simply wait for the link to become active or close # Simply wait for the link to become active or close
RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" is pending, waiting for link to become active", RNS.LOG_DEBUG) RNS.log("The link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" is pending, waiting for link to become active", RNS.LOG_DEBUG)
@@ -2821,11 +2959,12 @@ class LXMRouter:
# No link exists, so we'll try to establish one, but # No link exists, so we'll try to establish one, but
# only if we've never tried before, or the retry wait # only if we've never tried before, or the retry wait
# period has elapsed. # period has elapsed.
if not hasattr(lxmessage, "next_delivery_attempt") or time.time() > lxmessage.next_delivery_attempt: if self.attempt_due(lxmessage, delivery_destination_hash):
lxmessage.delivery_attempts += 1 lxmessage.delivery_attempts += 1
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT lxmessage.awaiting_path = False
self.schedule_attempt(lxmessage, delivery_destination_hash)
if lxmessage.delivery_attempts < LXMRouter.MAX_DELIVERY_ATTEMPTS: if lxmessage.delivery_attempts < self.attempt_limit(lxmessage):
if RNS.Transport.has_path(lxmessage.get_destination().hash): if RNS.Transport.has_path(lxmessage.get_destination().hash):
RNS.log("Establishing link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) RNS.log("Establishing link to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
delivery_link = RNS.Link(lxmessage.get_destination()) delivery_link = RNS.Link(lxmessage.get_destination())
@@ -2834,10 +2973,14 @@ class LXMRouter:
lxmessage.progress = 0.03 lxmessage.progress = 0.03
else: else:
RNS.log("No path known for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+". Requesting path...", RNS.LOG_DEBUG) RNS.log("No path known for delivery attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+". Requesting path...", RNS.LOG_DEBUG)
RNS.Transport.request_path(lxmessage.get_destination().hash) self.request_path(lxmessage.get_destination().hash)
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT self.schedule_attempt(lxmessage, delivery_destination_hash, path_request=True)
lxmessage.progress = 0.01 lxmessage.progress = 0.01
else: else:
RNS.log("Max delivery attempts reached for direct "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
self.fail_message(lxmessage)
elif not held and self.attempt_due(lxmessage, delivery_destination_hash):
RNS.log("Max delivery attempts reached for direct "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) RNS.log("Max delivery attempts reached for direct "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
self.fail_message(lxmessage) self.fail_message(lxmessage)
@@ -2850,16 +2993,21 @@ class LXMRouter:
RNS.log("No outbound propagation node specified for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_ERROR) RNS.log("No outbound propagation node specified for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_ERROR)
self.fail_message(lxmessage) self.fail_message(lxmessage)
else: else:
if lxmessage.delivery_attempts <= LXMRouter.MAX_DELIVERY_ATTEMPTS: held = self.slow_path_held(lxmessage, self.outbound_propagation_node)
if not held and lxmessage.delivery_attempts <= self.attempt_limit(lxmessage):
if self.outbound_propagation_link != None: if self.outbound_propagation_link != None:
# A link already exists, so we'll try to use it # A link already exists, so we'll try to use it
# to deliver the message # to deliver the message
if self.outbound_propagation_link.status == RNS.Link.ACTIVE: if self.outbound_propagation_link.status == RNS.Link.ACTIVE:
if lxmessage.state != LXMessage.SENDING: if lxmessage.state == LXMessage.OUTBOUND:
RNS.log("Starting propagation transfer of "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" via "+RNS.prettyhexrep(self.outbound_propagation_node), RNS.LOG_DEBUG) RNS.log("Starting propagation transfer of "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash)+" via "+RNS.prettyhexrep(self.outbound_propagation_node), RNS.LOG_DEBUG)
lxmessage.sent_on_slow_path = self.slow_path(self.outbound_propagation_node)
lxmessage.set_delivery_destination(self.outbound_propagation_link) lxmessage.set_delivery_destination(self.outbound_propagation_link)
lxmessage.send() try: lxmessage.send()
except Exception as e:
RNS.log(f"Error while sending {lxmessage}: {e}", RNS.LOG_ERROR)
self.fail_message(lxmessage)
else: else:
if lxmessage.representation == LXMessage.RESOURCE: if lxmessage.representation == LXMessage.RESOURCE:
RNS.log("The transfer of "+str(lxmessage)+" is in progress ("+str(round(lxmessage.progress*100, 1))+"%)", RNS.LOG_DEBUG) RNS.log("The transfer of "+str(lxmessage)+" is in progress ("+str(round(lxmessage.progress*100, 1))+"%)", RNS.LOG_DEBUG)
@@ -2868,7 +3016,7 @@ class LXMRouter:
elif self.outbound_propagation_link.status == RNS.Link.CLOSED: elif self.outbound_propagation_link.status == RNS.Link.CLOSED:
RNS.log("The link to "+RNS.prettyhexrep(self.outbound_propagation_node)+" was closed", RNS.LOG_DEBUG) RNS.log("The link to "+RNS.prettyhexrep(self.outbound_propagation_node)+" was closed", RNS.LOG_DEBUG)
self.outbound_propagation_link = None self.outbound_propagation_link = None
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT if lxmessage.delivery_attempts+1 < self.attempt_limit(lxmessage): self.schedule_attempt(lxmessage, self.outbound_propagation_node)
else: else:
# Simply wait for the link to become # Simply wait for the link to become
# active or close # active or close
@@ -2877,11 +3025,12 @@ class LXMRouter:
# No link exists, so we'll try to establish one, but # No link exists, so we'll try to establish one, but
# only if we've never tried before, or the retry wait # only if we've never tried before, or the retry wait
# period has elapsed. # period has elapsed.
if not hasattr(lxmessage, "next_delivery_attempt") or time.time() > lxmessage.next_delivery_attempt: if self.attempt_due(lxmessage, self.outbound_propagation_node):
lxmessage.delivery_attempts += 1 lxmessage.delivery_attempts += 1
lxmessage.next_delivery_attempt = time.time() + LXMRouter.DELIVERY_RETRY_WAIT lxmessage.awaiting_path = False
self.schedule_attempt(lxmessage, self.outbound_propagation_node)
if lxmessage.delivery_attempts < LXMRouter.MAX_DELIVERY_ATTEMPTS: if lxmessage.delivery_attempts < self.attempt_limit(lxmessage):
if RNS.Transport.has_path(self.outbound_propagation_node): if RNS.Transport.has_path(self.outbound_propagation_node):
RNS.log("Establishing link to "+RNS.prettyhexrep(self.outbound_propagation_node)+" for propagation attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) RNS.log("Establishing link to "+RNS.prettyhexrep(self.outbound_propagation_node)+" for propagation attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
propagation_node_identity = RNS.Identity.recall(self.outbound_propagation_node) propagation_node_identity = RNS.Identity.recall(self.outbound_propagation_node)
@@ -2891,9 +3040,12 @@ class LXMRouter:
self.outbound_propagation_link.for_lxmessage = lxmessage self.outbound_propagation_link.for_lxmessage = lxmessage
else: else:
RNS.log("No path known for propagation attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(self.outbound_propagation_node)+". Requesting path...", RNS.LOG_DEBUG) RNS.log("No path known for propagation attempt "+str(lxmessage.delivery_attempts)+" to "+RNS.prettyhexrep(self.outbound_propagation_node)+". Requesting path...", RNS.LOG_DEBUG)
RNS.Transport.request_path(self.outbound_propagation_node) self.request_path(self.outbound_propagation_node)
lxmessage.next_delivery_attempt = time.time() + LXMRouter.PATH_REQUEST_WAIT self.schedule_attempt(lxmessage, self.outbound_propagation_node, path_request=True)
else:
RNS.log("Max delivery attempts reached for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
self.fail_message(lxmessage)
else: elif not held and self.attempt_due(lxmessage, self.outbound_propagation_node):
RNS.log("Max delivery attempts reached for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG) RNS.log("Max delivery attempts reached for propagated "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
self.fail_message(lxmessage) self.fail_message(lxmessage)
+29 -7
View File
@@ -64,8 +64,8 @@ class LXMessage:
# With an MTU of 500, the maximum amount of data # With an MTU of 500, the maximum amount of data
# we can send in a single encrypted packet is # we can send in a single encrypted packet is
# 391 bytes. # 383 bytes.
ENCRYPTED_PACKET_MDU = RNS.Packet.ENCRYPTED_MDU + TIMESTAMP_SIZE ENCRYPTED_PACKET_MDU = RNS.Packet.ENCRYPTED_MDU
# The max content length we can fit in LXMF message # The max content length we can fit in LXMF message
# inside a single RNS packet is the encrypted MDU, minus # inside a single RNS packet is the encrypted MDU, minus
@@ -74,7 +74,7 @@ class LXMessage:
# field of the packet, therefore we also add the length # field of the packet, therefore we also add the length
# of a destination hash to the calculation. With default # of a destination hash to the calculation. With default
# RNS and LXMF parameters, the largest single-packet # RNS and LXMF parameters, the largest single-packet
# LXMF message we can send is 295 bytes. If a message # LXMF message we can send is 287 bytes. If a message
# is larger than that, a Reticulum link will be used. # is larger than that, a Reticulum link will be used.
ENCRYPTED_PACKET_MAX_CONTENT = ENCRYPTED_PACKET_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH ENCRYPTED_PACKET_MAX_CONTENT = ENCRYPTED_PACKET_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH
@@ -95,7 +95,7 @@ class LXMessage:
PLAIN_PACKET_MAX_CONTENT = PLAIN_PACKET_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH PLAIN_PACKET_MAX_CONTENT = PLAIN_PACKET_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH
# Descriptive strings regarding transport encryption # Descriptive strings regarding transport encryption
ENCRYPTION_DESCRIPTION_AES = "AES-128" ENCRYPTION_DESCRIPTION_AES = "AES-256"
ENCRYPTION_DESCRIPTION_EC = "Curve25519" ENCRYPTION_DESCRIPTION_EC = "Curve25519"
ENCRYPTION_DESCRIPTION_UNENCRYPTED = "Unencrypted" ENCRYPTION_DESCRIPTION_UNENCRYPTED = "Unencrypted"
@@ -177,6 +177,11 @@ class LXMessage:
self.representation = LXMessage.UNKNOWN self.representation = LXMessage.UNKNOWN
self.desired_method = desired_method self.desired_method = desired_method
self.delivery_attempts = 0 self.delivery_attempts = 0
self.sent_on_path = False
self.awaiting_path = False
self.max_delivery_attempts = None
self.transport_encrypted = False self.transport_encrypted = False
self.transport_encryption = None self.transport_encryption = None
self.ratchet_id = None self.ratchet_id = None
@@ -187,6 +192,8 @@ class LXMessage:
self.__pn_encrypted_data = None self.__pn_encrypted_data = None
self.__persist_lock = Lock() self.__persist_lock = Lock()
self.failed_callback = None self.failed_callback = None
self.receipt_timeout = None
self.concluded_callback = None
self.deferred_stamp_generating = False self.deferred_stamp_generating = False
@@ -466,10 +473,15 @@ class LXMessage:
if self.method == LXMessage.OPPORTUNISTIC: if self.method == LXMessage.OPPORTUNISTIC:
lxm_packet = self.__as_packet() lxm_packet = self.__as_packet()
lxm_packet.send().set_delivery_callback(self.__mark_delivered) receipt = lxm_packet.send()
self.progress = 0.50 self.progress = 0.50
self.ratchet_id = lxm_packet.ratchet_id self.ratchet_id = lxm_packet.ratchet_id
self.state = LXMessage.SENT self.state = LXMessage.SENT
if receipt:
receipt.set_delivery_callback(self.__mark_delivered)
if self.receipt_timeout: receipt.set_timeout(max(receipt.timeout, self.receipt_timeout))
if receipt.status == RNS.PacketReceipt.DELIVERED: self.__mark_delivered(receipt)
else: RNS.log(f"No receipt generated on sent opportunistic {self}", RNS.LOG_WARNING)
elif self.method == LXMessage.DIRECT: elif self.method == LXMessage.DIRECT:
self.state = LXMessage.SENDING self.state = LXMessage.SENDING
@@ -479,12 +491,14 @@ class LXMessage:
receipt = lxm_packet.send() receipt = lxm_packet.send()
self.ratchet_id = self.__delivery_destination.link_id self.ratchet_id = self.__delivery_destination.link_id
if receipt: if receipt:
self.progress = 0.50
receipt.set_delivery_callback(self.__mark_delivered) receipt.set_delivery_callback(self.__mark_delivered)
receipt.set_timeout_callback(self.__link_packet_timed_out) receipt.set_timeout_callback(self.__link_packet_timed_out)
self.progress = 0.50 if receipt.status == RNS.PacketReceipt.DELIVERED: self.__mark_delivered(receipt)
else: else:
if self.__delivery_destination: if self.__delivery_destination:
self.__delivery_destination.teardown() self.__delivery_destination.teardown()
self.state = LXMessage.OUTBOUND
elif self.representation == LXMessage.RESOURCE: elif self.representation == LXMessage.RESOURCE:
self.resource_representation = self.__as_resource() self.resource_representation = self.__as_resource()
@@ -497,11 +511,13 @@ class LXMessage:
if self.representation == LXMessage.PACKET: if self.representation == LXMessage.PACKET:
receipt = self.__as_packet().send() receipt = self.__as_packet().send()
if receipt: if receipt:
self.progress = 0.50
receipt.set_delivery_callback(self.__mark_propagated) receipt.set_delivery_callback(self.__mark_propagated)
receipt.set_timeout_callback(self.__link_packet_timed_out) receipt.set_timeout_callback(self.__link_packet_timed_out)
self.progress = 0.50 if receipt.status == RNS.PacketReceipt.DELIVERED: self.__mark_propagated(receipt)
else: else:
self.__delivery_destination.teardown() self.__delivery_destination.teardown()
self.state = LXMessage.OUTBOUND
elif self.representation == LXMessage.RESOURCE: elif self.representation == LXMessage.RESOURCE:
self.resource_representation = self.__as_resource() self.resource_representation = self.__as_resource()
@@ -559,10 +575,13 @@ class LXMessage:
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
def __mark_delivered(self, receipt = None): def __mark_delivered(self, receipt = None):
if self.state == LXMessage.DELIVERED: return
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
self.progress = 1.0 self.progress = 1.0
if self.concluded_callback != None and callable(self.concluded_callback): self.concluded_callback(self)
if self.__delivery_callback != None and callable(self.__delivery_callback): if self.__delivery_callback != None and callable(self.__delivery_callback):
try: try:
self.__delivery_callback(self) self.__delivery_callback(self)
@@ -571,10 +590,13 @@ class LXMessage:
RNS.trace_exception(e) RNS.trace_exception(e)
def __mark_propagated(self, receipt = None): def __mark_propagated(self, receipt = None):
if self.state == LXMessage.SENT: return
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
self.progress = 1.0 self.progress = 1.0
if self.concluded_callback != None and callable(self.concluded_callback): self.concluded_callback(self)
if self.__delivery_callback != None and callable(self.__delivery_callback): if self.__delivery_callback != None and callable(self.__delivery_callback):
try: try:
self.__delivery_callback(self) self.__delivery_callback(self)
+1 -1
View File
@@ -1 +1 @@
__version__ = "1.1.1" __version__ = "1.2.1"
+12 -2
View File
@@ -1,14 +1,24 @@
# Lightweight Extensible Message Format # Lightweight Extensible Message Format
LXMF is a simple and flexible messaging format and delivery protocol that allows a wide variety of implementations, while using as little bandwidth as possible. It is built on top of [Reticulum](a8d24177d946de4f1f0a0fe1af9a1338:/page/repo.mu`g=reticulum|r=reticulum) and offers zero-conf message routing, end-to-end encryption and Forward Secrecy, and can be transported over any kind of medium that Reticulum supports. > [!WARNING]
> Several hastily launched, incorrect, and in most cases entirely LLM-generated fakes of LXMF and associated tools are currently being circulated and marketed. Most of these "projects" violate the open source license that LXMF was published under, but claim independent ownership and license grants. Such claims or grants are **not** legally valid, and **not** recognized by the LXMF authors and copyright holders.
>
> Any claimed assertion of copyright or grant of license that such projects are making are [void grants](https://reticulum.network/manual/brandolinis.html#void-grants-legal-foundations-of-machine-generated-code). Both the violators themselves, and **all** downstream projects using the infringing derivatives, are **directly** and **personally** liable for the legal consequences.
>
> For more detailed information, see the relevant sections of the [Brandolini's Reference](https://reticulum.network/manual/brandolinis.html) chapter of the Reticulum Manual. For software and projects recognized by the Reticulum community, see the [Programs Using Reticulum](https://reticulum.network/manual/software.html) chapter.
>
> Do **not** use these "projects", they are a hazard to the entire ecosystem we have been carefully building over the last ten years.
LXMF is a simple and flexible messaging format and delivery protocol that allows a wide variety of implementations, while using as little bandwidth as possible. It is built on top of [Reticulum](https://reticulum.network) and offers zero-conf message routing, end-to-end encryption and Forward Secrecy, and can be transported over any kind of medium that Reticulum supports.
LXMF is efficient enough that it can deliver messages over extremely low-bandwidth systems such as packet radio or LoRa. Encrypted LXMF messages can also be encoded as QR-codes or text-based URIs, allowing completely analog *paper message* transport. LXMF is efficient enough that it can deliver messages over extremely low-bandwidth systems such as packet radio or LoRa. Encrypted LXMF messages can also be encoded as QR-codes or text-based URIs, allowing completely analog *paper message* transport.
User-facing clients built on LXMF include: User-facing clients built on LXMF include:
- [Sideband](https://unsigned.io/sideband) - [Sideband](https://unsigned.io/sideband)
- [MeshChat](https://github.com/liamcottle/reticulum-meshchat) - [MeshChatX](https://meshchatx.com/)
- [Nomad Network](https://unsigned.io/nomadnet) - [Nomad Network](https://unsigned.io/nomadnet)
- [Columba](https://github.com/torlando-tech/columba)
Community-provided tools and utilities for LXMF include: Community-provided tools and utilities for LXMF include:
+227
View File
@@ -0,0 +1,227 @@
>Lightweight Extensible Message Format
LXMF is a simple and flexible messaging format and delivery protocol that allows a wide variety of implementations, while using as little bandwidth as possible. It is built on top of `_`!`[Reticulum`https://reticulum.network]`!`_ and offers zero-conf message routing, end-to-end encryption and Forward Secrecy, and can be transported over any kind of medium that Reticulum supports.
LXMF is efficient enough that it can deliver messages over extremely low-bandwidth systems such as packet radio or LoRa. Encrypted LXMF messages can also be encoded as QR-codes or text-based URIs, allowing completely analog `*paper message`* transport.
User-facing clients built on LXMF include:
• `_`!`[Sideband`https://unsigned.io/sideband]`!`_
• `_`!`[MeshChatX`https://meshchatx.com/]`!`_
• `_`!`[Nomad Network`https://unsigned.io/nomadnet]`!`_
• `_`!`[Columba`https://github.com/torlando-tech/columba]`!`_
Community-provided tools and utilities for LXMF include:
• `_`!`[LXMFy`https://lxmfy.quad4.io/]`!`_
• `_`!`[LXMF-Bot`https://github.com/randogoth/lxmf-bot]`!`_
• `_`!`[LXMF Messageboard`https://github.com/chengtripp/lxmf_messageboard]`!`_
• `_`!`[LXMEvent`https://github.com/faragher/LXMEvent]`!`_
• `_`!`[RangeMap`https://github.com/faragher/RangeMap]`!`_
• `_`!`[LXMF Tools`https://github.com/SebastianObi/LXMF-Tools]`!`_
>>Structure
LXMF messages are stored in a simple and efficient format, that's easy to parse and write.
>>>The format follows this general structure:
• Destination
• Source
• Ed25519 Signature
• Payload
• Timestamp
• Content
• Title
• Fields
>>>And these rules:
1. A LXMF message is identified by its `!message-id`!, which is a SHA-256 hash of the `!Destination`!, `!Source`! and `!Payload`!. The message-id is never included directly in the message, since it can always be inferred from the message itself.
In some cases the actual message-id cannot be inferred, for example when a Propagation Node is storing an encrypted message for an offline user. In these cases a `*transient-id`* is used to identify the message while in storage or transit.
2. `!Destination`!, `!Source`!, `!Signature`! and `!Payload`! parts are mandatory, as is the `!Timestamp`! part of the payload.
• The `!Destination`! and `!Source`! fields are 16-byte Reticulum destination hashes
• The `!Signature`! field is a 64-byte Ed25519 signature of the `!Destination`!, `!Source`!, `!Payload`! and `!message-id`!
• The `!Payload`! part is a `_`!`[msgpacked`https://msgpack.org]`!`_ list containing four items:
1. The `!Timestamp`! is a double-precision floating point number representing the number of seconds since the UNIX epoch.
2. The `!Content`! is the optional content or body of the message
3. The `!Title`! is an optional title for the message
4. The `!Fields`! is an optional dictionary
3. The `!Content`!, `!Title`! and `!Fields`! parts must be included in the message structure, but can be left empty.
4. The `!Fields`! part can be left empty, or contain a dictionary of any structure or depth.
>>Usage Examples
LXMF offers flexibility to implement many different messaging schemes, ranging from human communication to machine control and sensor monitoring. Here are a few examples:
• A messaging system for passing short, simple messages between human users, akin to SMS can be implemented using only the `!Content`! field, and leaving all other optional fields empty.
• For sending full-size mail, an email-like system can be implemented using the `!Title`! and `!Content`! fields to store "subject" and "body" parts of the message, and optionally the `!Fields`! part can be used to store attachments or other metadata.
• Machine-control messages or sensor readings can be implemented using command structures embedded in the `!Fields`! dictionary.
• Distributed discussion or news-groups, akin to USENET or similar systems, can be implemented using the relevant fields and LXMF Propagation Nodes. Broadcast bulletins can be implemented in a similar fashion.
>>Propagation Nodes
LXM Propagation Nodes offer a way to store and forward messages to users or endpoints that are not directly reachable at the time of message emission. Propagation Nodes can also provide infrastructure for distributed bulletin, news or discussion boards.
When Propagation Nodes exist on a Reticulum network, they will by default peer with each other and synchronise messages, automatically creating an encrypted, distributed message store. Users and other endpoints can retrieve messages destined for them from any available Propagation Nodes on the network.
>>The LXM Router
The LXM Router handles transporting messages over a Reticulum network, managing delivery receipts, outbound and inbound queues, and is the point of API interaction for client programs. The LXM Router also implements functionality for acting as an LXMF Propagation Node.
Programatically, using the LXM Router to send a message is as simple as:
`BT282828`Fddd
`FTff7b72import`f `FT7ee787LXMF`f
`FTe6edf3lxm_router`f `FTff7b72=`f `FTe6edf3LXMF`f`FTff7b72.`f`FTd2a8ffLXMRouter`f`FTb4b4b4(`f`FTb4b4b4)`f
`FTe6edf3message`f `FTff7b72=`f `FTe6edf3LXMF`f`FTff7b72.`f`FTd2a8ffLXMessage`f`FTb4b4b4(`f`FTe6edf3destination`f`FTb4b4b4,`f `FTe6edf3source`f`FTb4b4b4,`f `FTa5d6ff"`f`FTa5d6ffThis is a short, simple message.`f`FTa5d6ff"`f`FTb4b4b4)`f
`FTe6edf3lxm_router`f`FTff7b72.`f`FTd2a8ffhandle_outbound`f`FTb4b4b4(`f`FTe6edf3message`f`FTb4b4b4)`f
`f`b
The LXM Router then handles the heavy lifting, such as message packing, encryption, delivery confirmation, path lookup, routing, retries and failure notifications.
>>Transport Encryption
LXMF uses encryption provided by `_`!`[Reticulum`https://reticulum.network]`!`_, and thus uses end-to-end encryption by default. The delivery method of a message will influence which transport encryption scheme is used.
• If a message is delivered over a Reticulum link (which is the default method), the message will be encrypted with ephemeral AES-128 keys derived with ECDH on Curve25519. This mode offers forward secrecy.
• A message can be delivered opportunistically, embedded in a single Reticulum packet. In this cases the message will be opportunistically routed through the network, and will be encrypted with per-packet AES-128 keys derived with ECDH on Curve25519.
• If a message is delivered to the Reticulum GROUP destination type, the message will be encrypted using the symmetric AES-128 key of the GROUP destination.
>>Wire Format & Overhead
Assuming the default Reticulum configuration, the binary wire-format is as follows:
• 16 bytes destination hash
• 16 bytes source hash
• 64 bytes Ed25519 signature
• Remaining bytes of `_`!`[msgpack`https://msgpack.org]`!`_ payload data, in accordance with the structure defined above
The complete message overhead for LXMF is only 111 bytes, which in return gives you timestamped, digitally signed, infinitely extensible, end-to-end encrypted, zero-conf routed, minimal-infrastructure messaging that's easy to use and build applications with.
>>Code Examples
Before writing your own programs using LXMF, you need to have a basic understanding of how the `_`!`[Reticulum`https://reticulum.network]`!`_ protocol and API works. Please see the `_`!`[Reticulum Manual`https://reticulum.network/manual/]`!`_. For a few simple examples of how to send and receive messages with LXMF, please see the `_`!`[receiver example`:/page/blob.mu`g=reticulum|r=lxmf|ref=HEAD|path=./docs/example_receiver.py]`!`_ and the `_`!`[sender example`:/page/blob.mu`g=reticulum|r=lxmf|ref=HEAD|path=./docs/example_sender.py]`!`_ included in this repository.
>>Example Paper Message
You can try out the paper messaging functionality by using the following QR code. It is a paper message sent to the LXMF address `BT383838`Fddd6b3362bd2c1dbf87b66a85f79a8d8c75`f`b. To be able to decrypt and read the message, you will need to import the following Reticulum Identity to an LXMF messaging app:
`BT383838`Fddd3BPTDTQCRZPKJT3TXAJCMQFMOYWIM3OCLKPWMG4HCF2T4CH3YZHVNHNRDU6QAZWV2KBHMWBNT2C62TQEVC5GLFM4MN25VLZFSK3ADRQ=`f`b
The `_`!`[Sideband`https://unsigned.io/sideband]`!`_ application allows you to do this easily. After you have imported the identity into an app of your choice, you can scan the following QR code and open it in the app, where it will be decrypted and added as a message.
`_`!`[Paper message QR code`a8d24177d946de4f1f0a0fe1af9a1338:/page/blob.mu`g=reticulum|r=lxmf|ref=HEAD|path=docs/paper_msg_test.png]`!`_
You can also find the entire message in this link:
`BT282828`Fddd
`=
lxm://azNivSwdv4e2aoX3mo2MdTAozuI7BlzrLlHULmnVgpz3dNT9CMPVwgywzCJP8FVogj5j_kU7j7ywuvBNcr45kRTrd19c3iHenmnSDe4VEd6FuGsAiT0Khzl7T81YZHPTDhRNp0FdhDE9AJ7uphw7zKMyqhHHxOxqrYeBeKF66gpPxDceqjsOApvsSwggjcuHBx9OxOBy05XmnJxA1unCKgvNfOFYc1T47luxoY3c0dLOJnJPwZuFRytx2TXlQNZzOJ28yTEygIfkDqEO9mZi5lgev7XZJ0DvgioQxMIyoCm7lBUzfq66zW3SQj6vHHph7bhr36dLOCFgk4fZA6yia2MlTT9KV66Tn2l8mPNDlvuSAJhwDA_xx2PN9zKadCjo9sItkAp8r-Ss1CzoUWZUAyT1oDw7ly6RrzGBG-e3eM3CL6u1juIeFiHby7_3cON-6VTUuk4xR5nwKlFTu5vsYMVXe5H3VahiDSS4Q1aqX7I
`=
`f`b
On operating systems that allow for registering custom URI-handlers, you can click the link, and it will be decoded directly in your LXMF client. This works with Sideband on Android.
>>Installation
If you want to try out LXMF, you can install it with pip:
`BT282828`Fddd
pip install lxmf
`f`b
If you are using an operating system that blocks normal user package installation via `BT383838`Fdddpip`f`b,
you can return `BT383838`Fdddpip`f`b to normal behaviour by editing the `BT383838`Fddd~/.config/pip/pip.conf`f`b file,
and adding the following directive in the `BT383838`Fddd[global]`f`b section:
`BT282828`Fddd
[global]
break-system-packages = true
`f`b
Alternatively, you can use the `BT383838`Fdddpipx`f`b tool to install Reticulum in an isolated environment:
`BT282828`Fddd
pipx install lxmf
`f`b
>>Daemon Included
The `BT383838`Fdddlxmf`f`b package comes with the `BT383838`Fdddlxmd`f`b program, a fully functional (but lightweight) LXMF message router and propagation node daemon. After installing the `BT383838`Fdddlxmf`f`b package, you can run `BT383838`Fdddlxmd --help`f`b to learn more about the command-line options:
`BT282828`Fddd
$ lxmd --help
usage: lxmd [-h] [--config CONFIG] [--rnsconfig RNSCONFIG] [-p] [-i PATH] [-v] [-q] [-s] [--exampleconfig] [--version]
Lightweight Extensible Messaging Daemon
options:
-h, --help show this help message and exit
--config CONFIG path to alternative lxmd config directory
--rnsconfig RNSCONFIG
path to alternative Reticulum config directory
-p, --propagation-node
run an LXMF Propagation Node
-i PATH, --on-inbound PATH
executable to run when a message is received
-v, --verbose
-q, --quiet
-s, --service lxmd is running as a service and should log to file
--exampleconfig print verbose configuration example to stdout and exit
--version show program's version number and exit
`f`b
Or run `BT383838`Fdddlxmd --exampleconfig`f`b to generate a commented example configuration documenting all the available configuration directives.
>>Support LXMF Development
You can help support the continued development of open, free and private communications systems by donating via one of the following channels:
• Monero:
`BT282828`Fddd
`=
84FpY1QbxHcgdseePYNmhTHcrgMX4nFfBYtz2GKYToqHVVhJp8Eaw1Z1EedRnKD19b3B8NiLCGVxzKV17UMmmeEsCrPyA5w
`=
`f`b
• Bitcoin
`BT282828`Fddd
`=
bc1pgqgu8h8xvj4jtafslq396v7ju7hkgymyrzyqft4llfslz5vp99psqfk3a6
`=
`f`b
• Ethereum
`BT282828`Fddd
`=
0x91C421DdfB8a30a49A71d63447ddb54cEBe3465E
`=
`f`b
• Liberapay: https://liberapay.com/Reticulum/
• Ko-Fi: https://ko-fi.com/markqvist
>>Caveat Emptor
LXMF is beta software, and should be considered experimental. While it has been built with cryptography best practices very foremost in mind, it `*has not`* been externally security audited, and there could very well be privacy-breaking bugs. If you want to help out, or help sponsor an audit, please do get in touch.
>>Development Roadmap
LXMF is actively being developed, and the following improvements and features are currently planned for implementation:
• Sneakernet and physical transport functionality
• Content Destinations, and easy to use API for group messaging and discussion threads
• Write and release full API and protocol documentation
• Documenting and possibly expanding LXMF limits and priorities
+1 -1
View File
@@ -31,6 +31,6 @@ setuptools.setup(
'lxmd=LXMF.Utilities.lxmd:main', 'lxmd=LXMF.Utilities.lxmd:main',
] ]
}, },
install_requires=["rns>=1.4.2"], install_requires=["rns>=1.5.7"],
python_requires=">=3.7", python_requires=">=3.7",
) )