mirror of
https://github.com/markqvist/LXMF
synced 2026-11-22 23:10:36 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0ac4660510 | ||
|
|
672054177c | ||
|
|
55cf934475 | ||
|
|
b690880332 | ||
|
|
7220a4d6f7 | ||
|
|
5abf01a88f | ||
|
|
51a4d19595 | ||
|
|
ad8fb74d9e | ||
|
|
447a8a920c | ||
|
|
0ba3ea98cb | ||
|
|
fc0b086cb1 | ||
|
|
7a40bd44e8 | ||
|
|
afe6815637 | ||
|
|
a64f3a58f7 | ||
|
|
2bb34176b7 | ||
|
|
6f80c6941d | ||
|
|
02d42747b7 | ||
|
|
5b81ecce04 | ||
|
|
8c94118e07 | ||
|
|
390cac84e3 | ||
|
|
ae6b5d9a6d | ||
|
|
ffb1bdff17 | ||
|
|
1440a0b162 | ||
|
|
b10755e34f | ||
|
|
683e9ee412 | ||
|
|
aa3886720f | ||
|
|
7ee7c60e77 | ||
|
|
0c52d3fcd4 | ||
|
|
8f425e6dde | ||
|
|
a1c897a8ca | ||
|
|
9fa6a144d0 | ||
|
|
54005c148a | ||
|
|
abe2e78283 | ||
|
|
edbb887d81 | ||
|
|
540aa1a496 | ||
|
|
3d31620160 | ||
|
|
6b983872fa | ||
|
|
bb7bbaf124 | ||
|
|
dad21bcca7 | ||
|
|
f75ea842d9 | ||
|
|
f7ee4c1d86 | ||
|
|
58c61a2557 | ||
|
|
730a611f7a | ||
|
|
ab68c15d2d | ||
|
|
564cd9b18c | ||
|
|
cacddfdf30 | ||
|
|
adbbaa532b | ||
|
|
2d81b47b6a | ||
|
|
1c4928a29b | ||
|
|
2181584f69 | ||
|
|
8bb21688e5 | ||
|
|
8cdf12e866 | ||
|
|
a1dae1fc15 | ||
|
|
2f43d660d5 | ||
|
|
920beaf6f5 | ||
|
|
6b28cd8698 | ||
|
|
323a968525 | ||
|
|
a26dfe3b7b |
No files matched your search
@@ -8,6 +8,7 @@ __pycache__/
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
LXMF/Utilities/LXMF
|
||||
RNS
|
||||
.Python
|
||||
build/
|
||||
|
||||
+76
-38
@@ -24,6 +24,17 @@ class LXMPeer:
|
||||
# be unreachable before it is removed
|
||||
MAX_UNREACHABLE = 4*24*60*60
|
||||
|
||||
# Everytime consecutive time a sync
|
||||
# link fails to establish, add this
|
||||
# amount off time to wait before the
|
||||
# next sync is attempted.
|
||||
SYNC_BACKOFF_STEP = 12*60
|
||||
|
||||
# How long to wait for an answer to
|
||||
# peer path requests before deferring
|
||||
# sync to later.
|
||||
PATH_REQUEST_GRACE = 7.5
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(peer_bytes, router):
|
||||
dictionary = msgpack.unpackb(peer_bytes)
|
||||
@@ -32,6 +43,10 @@ class LXMPeer:
|
||||
peer.peering_timebase = dictionary["peering_timebase"]
|
||||
peer.alive = dictionary["alive"]
|
||||
peer.last_heard = dictionary["last_heard"]
|
||||
if "link_establishment_rate" in dictionary:
|
||||
peer.link_establishment_rate = dictionary["link_establishment_rate"]
|
||||
else:
|
||||
peer.link_establishment_rate = 0
|
||||
|
||||
for transient_id in dictionary["handled_ids"]:
|
||||
if transient_id in router.propagation_entries:
|
||||
@@ -49,6 +64,7 @@ class LXMPeer:
|
||||
dictionary["alive"] = self.alive
|
||||
dictionary["last_heard"] = self.last_heard
|
||||
dictionary["destination_hash"] = self.destination_hash
|
||||
dictionary["link_establishment_rate"] = self.link_establishment_rate
|
||||
|
||||
handled_ids = []
|
||||
for transient_id in self.handled_messages:
|
||||
@@ -66,7 +82,11 @@ class LXMPeer:
|
||||
def __init__(self, router, destination_hash):
|
||||
self.alive = False
|
||||
self.last_heard = 0
|
||||
self.next_sync_attempt = 0
|
||||
self.last_sync_attempt = 0
|
||||
self.sync_backoff = 0
|
||||
self.peering_timebase = 0
|
||||
self.link_establishment_rate = 0
|
||||
|
||||
self.link = None
|
||||
self.state = LXMPeer.IDLE
|
||||
@@ -81,47 +101,59 @@ class LXMPeer:
|
||||
|
||||
def sync(self):
|
||||
RNS.log("Initiating LXMF Propagation Node sync with peer "+RNS.prettyhexrep(self.destination_hash), RNS.LOG_DEBUG)
|
||||
self.last_sync_attempt = time.time()
|
||||
|
||||
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.Transport.request_path(self.destination_hash)
|
||||
RNS.log("Path requested, retrying sync later", RNS.LOG_DEBUG)
|
||||
|
||||
else:
|
||||
if self.identity == None:
|
||||
self.identity = RNS.Identity.recall(destination_hash)
|
||||
self.destination = RNS.Destination(self.identity, RNS.Destination.OUT, RNS.Destination.SINGLE, APP_NAME, "propagation")
|
||||
if time.time() > self.next_sync_attempt:
|
||||
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.Transport.request_path(self.destination_hash)
|
||||
time.sleep(LXMPeer.PATH_REQUEST_GRACE)
|
||||
|
||||
if self.identity != None:
|
||||
if len(self.unhandled_messages) > 0:
|
||||
if self.state == LXMPeer.IDLE:
|
||||
RNS.log("Establishing link for sync to peer "+RNS.prettyhexrep(self.destination_hash)+"...", RNS.LOG_DEBUG)
|
||||
self.link = RNS.Link(self.destination, established_callback = self.link_established, closed_callback = self.link_closed)
|
||||
self.state = LXMPeer.LINK_ESTABLISHING
|
||||
|
||||
else:
|
||||
if self.state == LXMPeer.LINK_READY:
|
||||
self.alive = True
|
||||
self.last_heard = time.time()
|
||||
|
||||
RNS.log("Synchronisation link to peer "+RNS.prettyhexrep(self.destination_hash)+" established, preparing request...", RNS.LOG_DEBUG)
|
||||
unhandled_ids = []
|
||||
purged_ids = []
|
||||
for transient_id in self.unhandled_messages:
|
||||
if transient_id in self.router.propagation_entries:
|
||||
unhandled_ids.append(transient_id)
|
||||
else:
|
||||
purged_ids.append(transient_id)
|
||||
|
||||
for transient_id in purged_ids:
|
||||
RNS.log("Dropping unhandled message "+RNS.prettyhexrep(transient_id)+" for peer "+RNS.prettyhexrep(self.destination_hash)+" since it no longer exists in the message store.", RNS.LOG_DEBUG)
|
||||
self.unhandled_messages.pop(transient_id)
|
||||
|
||||
RNS.log("Sending sync request to peer "+str(self.destination), RNS.LOG_DEBUG)
|
||||
self.link.request(LXMPeer.OFFER_REQUEST_PATH, unhandled_ids, response_callback=self.offer_response, failed_callback=self.request_failed)
|
||||
self.state = LXMPeer.REQUEST_SENT
|
||||
if not RNS.Transport.has_path(self.destination_hash):
|
||||
RNS.log("Path request was not answered, retrying sync with peer "+RNS.prettyhexrep(self.destination_hash)+" later", RNS.LOG_DEBUG)
|
||||
|
||||
else:
|
||||
RNS.log("Could not request sync to peer "+RNS.prettyhexrep(self.destination_hash)+" since its identity could not be recalled.", RNS.LOG_ERROR)
|
||||
if self.identity == None:
|
||||
self.identity = RNS.Identity.recall(destination_hash)
|
||||
self.destination = RNS.Destination(self.identity, RNS.Destination.OUT, RNS.Destination.SINGLE, APP_NAME, "propagation")
|
||||
|
||||
if self.identity != None:
|
||||
if len(self.unhandled_messages) > 0:
|
||||
if self.state == LXMPeer.IDLE:
|
||||
RNS.log("Establishing link for sync to peer "+RNS.prettyhexrep(self.destination_hash)+"...", RNS.LOG_DEBUG)
|
||||
self.sync_backoff += LXMPeer.SYNC_BACKOFF_STEP
|
||||
self.next_sync_attempt = time.time() + self.sync_backoff
|
||||
self.link = RNS.Link(self.destination, established_callback = self.link_established, closed_callback = self.link_closed)
|
||||
self.state = LXMPeer.LINK_ESTABLISHING
|
||||
|
||||
else:
|
||||
if self.state == LXMPeer.LINK_READY:
|
||||
self.alive = True
|
||||
self.last_heard = time.time()
|
||||
self.sync_backoff = 0
|
||||
|
||||
RNS.log("Synchronisation link to peer "+RNS.prettyhexrep(self.destination_hash)+" established, preparing request...", RNS.LOG_DEBUG)
|
||||
unhandled_ids = []
|
||||
purged_ids = []
|
||||
for transient_id in self.unhandled_messages:
|
||||
if transient_id in self.router.propagation_entries:
|
||||
unhandled_ids.append(transient_id)
|
||||
else:
|
||||
purged_ids.append(transient_id)
|
||||
|
||||
for transient_id in purged_ids:
|
||||
RNS.log("Dropping unhandled message "+RNS.prettyhexrep(transient_id)+" for peer "+RNS.prettyhexrep(self.destination_hash)+" since it no longer exists in the message store.", RNS.LOG_DEBUG)
|
||||
self.unhandled_messages.pop(transient_id)
|
||||
|
||||
RNS.log("Sending sync request to peer "+str(self.destination), RNS.LOG_DEBUG)
|
||||
self.link.request(LXMPeer.OFFER_REQUEST_PATH, unhandled_ids, response_callback=self.offer_response, failed_callback=self.request_failed)
|
||||
self.state = LXMPeer.REQUEST_SENT
|
||||
else:
|
||||
RNS.log("Could not request sync to peer "+RNS.prettyhexrep(self.destination_hash)+" since its identity could not be recalled.", RNS.LOG_ERROR)
|
||||
else:
|
||||
RNS.log("Postponing sync with peer "+RNS.prettyhexrep(self.destination_hash)+" for "+RNS.prettytime(self.next_sync_attempt-time.time())+" due to previous failures", RNS.LOG_DEBUG)
|
||||
if self.last_sync_attempt > self.last_heard:
|
||||
self.alive = False
|
||||
|
||||
def request_failed(self, request_receipt):
|
||||
RNS.log("Sync request to peer "+str(self.destination)+" failed", RNS.LOG_DEBUG)
|
||||
@@ -191,6 +223,7 @@ class LXMPeer:
|
||||
resource.transferred_messages = wanted_message_ids
|
||||
self.state = LXMPeer.RESOURCE_TRANSFERRING
|
||||
else:
|
||||
RNS.log("Peer "+RNS.prettyhexrep(self.destination_hash)+" did not request any of the available messages, sync completed", RNS.LOG_DEBUG)
|
||||
self.state = LXMPeer.IDLE
|
||||
|
||||
except Exception as e:
|
||||
@@ -225,7 +258,12 @@ class LXMPeer:
|
||||
|
||||
def link_established(self, link):
|
||||
self.link.identify(self.router.identity)
|
||||
link_establishment_rate = link.get_establishment_rate()
|
||||
if link_establishment_rate != None:
|
||||
self.link_establishment_rate = link_establishment_rate
|
||||
|
||||
self.state = LXMPeer.LINK_READY
|
||||
self.next_sync_attempt = 0
|
||||
self.sync()
|
||||
|
||||
def link_closed(self, link):
|
||||
|
||||
+164
-31
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import time
|
||||
import random
|
||||
import base64
|
||||
import atexit
|
||||
import threading
|
||||
|
||||
@@ -15,9 +16,9 @@ from .Handlers import LXMFDeliveryAnnounceHandler
|
||||
from .Handlers import LXMFPropagationAnnounceHandler
|
||||
|
||||
class LXMRouter:
|
||||
MAX_DELIVERY_ATTEMPTS = 4
|
||||
PROCESSING_INTERVAL = 5
|
||||
DELIVERY_RETRY_WAIT = 12
|
||||
MAX_DELIVERY_ATTEMPTS = 5
|
||||
PROCESSING_INTERVAL = 4
|
||||
DELIVERY_RETRY_WAIT = 7
|
||||
PATH_REQUEST_WAIT = 5
|
||||
LINK_MAX_INACTIVITY = 10*60
|
||||
|
||||
@@ -27,6 +28,7 @@ class LXMRouter:
|
||||
|
||||
AUTOPEER = True
|
||||
AUTOPEER_MAXDEPTH = 4
|
||||
FASTEST_N_RANDOM_POOL = 2
|
||||
|
||||
PR_PATH_TIMEOUT = 10
|
||||
|
||||
@@ -47,7 +49,7 @@ class LXMRouter:
|
||||
### Developer-facing API ##############################
|
||||
#######################################################
|
||||
|
||||
def __init__(self, identity = None, storagepath = None, autopeer = AUTOPEER, autopeer_maxdepth = AUTOPEER_MAXDEPTH):
|
||||
def __init__(self, identity = None, storagepath = None, autopeer = AUTOPEER, autopeer_maxdepth = None):
|
||||
random.seed(os.urandom(10))
|
||||
|
||||
self.pending_inbound = []
|
||||
@@ -85,6 +87,7 @@ class LXMRouter:
|
||||
self.propagation_transfer_last_result = None
|
||||
self.propagation_transfer_max_messages = None
|
||||
self.locally_delivered_transient_ids = {}
|
||||
self.locally_processed_transient_ids = {}
|
||||
|
||||
if identity == None:
|
||||
identity = RNS.Identity()
|
||||
@@ -93,12 +96,18 @@ class LXMRouter:
|
||||
self.lxmf_query_destination = RNS.Destination(None, RNS.Destination.IN, RNS.Destination.PLAIN, APP_NAME, "query")
|
||||
self.propagation_destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, "propagation")
|
||||
|
||||
self.autopeer = autopeer
|
||||
self.autopeer_maxdepth = autopeer_maxdepth
|
||||
if autopeer != None:
|
||||
self.autopeer = autopeer
|
||||
else:
|
||||
self.autopeer = LXMRouter.AUTOPEER
|
||||
|
||||
if autopeer_maxdepth != None:
|
||||
self.autopeer_maxdepth = autopeer_maxdepth
|
||||
else:
|
||||
self.autopeer_maxdepth = LXMRouter.AUTOPEER_MAXDEPTH
|
||||
|
||||
self.peers = {}
|
||||
self.propagation_entries = {}
|
||||
self.propagated_ids = {}
|
||||
|
||||
RNS.Transport.register_announce_handler(LXMFDeliveryAnnounceHandler(self))
|
||||
RNS.Transport.register_announce_handler(LXMFPropagationAnnounceHandler(self))
|
||||
@@ -111,7 +120,14 @@ class LXMRouter:
|
||||
data = locally_delivered_file.read()
|
||||
self.locally_delivered_transient_ids = msgpack.unpackb(data)
|
||||
locally_delivered_file.close()
|
||||
self.clean_transient_id_cache()
|
||||
|
||||
if os.path.isfile(self.storagepath+"/locally_processed"):
|
||||
locally_processed_file = open(self.storagepath+"/locally_processed", "rb")
|
||||
data = locally_processed_file.read()
|
||||
self.locally_processed_transient_ids = msgpack.unpackb(data)
|
||||
locally_processed_file.close()
|
||||
|
||||
self.clean_transient_id_caches()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not load locally delivered message ID cache from storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
@@ -138,7 +154,7 @@ class LXMRouter:
|
||||
da_thread.start()
|
||||
|
||||
def register_delivery_identity(self, identity, display_name = None):
|
||||
delivery_destination = RNS.Destination(identity, RNS.Destination.IN, RNS.Destination.SINGLE, "lxmf", "delivery")
|
||||
delivery_destination = RNS.Destination(identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, "delivery")
|
||||
delivery_destination.set_packet_callback(self.delivery_packet)
|
||||
delivery_destination.set_link_established_callback(self.delivery_link_established)
|
||||
delivery_destination.display_name = display_name
|
||||
@@ -417,7 +433,7 @@ class LXMRouter:
|
||||
self.clean_links()
|
||||
|
||||
if self.processing_count % LXMRouter.JOB_TRANSIENT_INTERVAL == 0:
|
||||
self.clean_transient_id_cache()
|
||||
self.clean_transient_id_caches()
|
||||
|
||||
if self.processing_count % LXMRouter.JOB_STORE_INTERVAL == 0:
|
||||
self.clean_message_store()
|
||||
@@ -429,7 +445,12 @@ class LXMRouter:
|
||||
while (True):
|
||||
# TODO: Improve this to scheduling, so manual
|
||||
# triggers can delay next run
|
||||
self.jobs()
|
||||
|
||||
try:
|
||||
self.jobs()
|
||||
except Exception as e:
|
||||
RNS.log("An error ocurred while running LXMF Router jobs.", RNS.LOG_ERROR)
|
||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
time.sleep(LXMRouter.PROCESSING_INTERVAL)
|
||||
|
||||
def clean_links(self):
|
||||
@@ -451,18 +472,28 @@ class LXMRouter:
|
||||
self.acknowledge_sync_completion()
|
||||
RNS.log("Cleaned outbound propagation link", RNS.LOG_DEBUG)
|
||||
|
||||
def clean_transient_id_cache(self):
|
||||
def clean_transient_id_caches(self):
|
||||
now = time.time()
|
||||
removed_entries = []
|
||||
for transient_id in self.locally_delivered_transient_ids:
|
||||
timestamp = self.locally_delivered_transient_ids[transient_id]
|
||||
if now > timestamp+LXMRouter.MESSAGE_EXPIRY*1.1:
|
||||
if now > timestamp+LXMRouter.MESSAGE_EXPIRY*1.25:
|
||||
removed_entries.append(transient_id)
|
||||
|
||||
for transient_id in removed_entries:
|
||||
self.locally_delivered_transient_ids.pop(transient_id)
|
||||
RNS.log("Cleaned "+RNS.prettyhexrep(transient_id)+" from local delivery cache", RNS.LOG_DEBUG)
|
||||
|
||||
removed_entries = []
|
||||
for transient_id in self.locally_processed_transient_ids:
|
||||
timestamp = self.locally_processed_transient_ids[transient_id]
|
||||
if now > timestamp+LXMRouter.MESSAGE_EXPIRY*1.25:
|
||||
removed_entries.append(transient_id)
|
||||
|
||||
for transient_id in removed_entries:
|
||||
self.locally_processed_transient_ids.pop(transient_id)
|
||||
RNS.log("Cleaned "+RNS.prettyhexrep(transient_id)+" from locally processed cache", RNS.LOG_DEBUG)
|
||||
|
||||
def clean_message_store(self):
|
||||
# Check and remove expired messages
|
||||
now = time.time()
|
||||
@@ -552,6 +583,30 @@ class LXMRouter:
|
||||
except Exception as e:
|
||||
RNS.log("Could not clean the LXMF message store. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
def save_locally_delivered_transient_ids(self):
|
||||
try:
|
||||
if not os.path.isdir(self.storagepath):
|
||||
os.makedirs(self.storagepath)
|
||||
|
||||
locally_delivered_file = open(self.storagepath+"/local_deliveries", "wb")
|
||||
locally_delivered_file.write(msgpack.packb(self.locally_delivered_transient_ids))
|
||||
locally_delivered_file.close()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not save locally delivered message ID cache to storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
def save_locally_processed_transient_ids(self):
|
||||
try:
|
||||
if not os.path.isdir(self.storagepath):
|
||||
os.makedirs(self.storagepath)
|
||||
|
||||
locally_processed_file = open(self.storagepath+"/locally_processed", "wb")
|
||||
locally_processed_file.write(msgpack.packb(self.locally_processed_transient_ids))
|
||||
locally_processed_file.close()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not save locally processed message ID cache to storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
def exit_handler(self):
|
||||
if self.propagation_node:
|
||||
try:
|
||||
@@ -569,16 +624,8 @@ class LXMRouter:
|
||||
except Exception as e:
|
||||
RNS.log("Could not save propagation node peers to storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
try:
|
||||
if not os.path.isdir(self.storagepath):
|
||||
os.makedirs(self.storagepath)
|
||||
|
||||
locally_delivered_file = open(self.storagepath+"/local_deliveries", "wb")
|
||||
locally_delivered_file.write(msgpack.packb(self.locally_delivered_transient_ids))
|
||||
locally_delivered_file.close()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not save locally delivered message ID cache to storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
self.save_locally_delivered_transient_ids()
|
||||
self.save_locally_processed_transient_ids()
|
||||
|
||||
def __str__(self):
|
||||
return "<LXMRouter "+RNS.hexrep(self.identity.hash, delimit=False)+">"
|
||||
@@ -723,6 +770,14 @@ class LXMRouter:
|
||||
RNS.log("Propagation node indicated missing identification on get request, tearing down link.", RNS.LOG_DEBUG)
|
||||
if self.outbound_propagation_link != None:
|
||||
self.outbound_propagation_link.teardown()
|
||||
self.propagation_transfer_state = LXMRouter.PR_NO_IDENTITY_RCVD
|
||||
|
||||
elif request_receipt.response == LXMPeer.ERROR_NO_ACCESS:
|
||||
RNS.log("Propagation node did not allow get request, tearing down link.", RNS.LOG_DEBUG)
|
||||
if self.outbound_propagation_link != None:
|
||||
self.outbound_propagation_link.teardown()
|
||||
self.propagation_transfer_state = LXMRouter.PR_NO_ACCESS
|
||||
|
||||
else:
|
||||
if request_receipt.response != None and len(request_receipt.response) > 0:
|
||||
haves = []
|
||||
@@ -744,6 +799,7 @@ class LXMRouter:
|
||||
self.propagation_transfer_state = LXMRouter.PR_COMPLETE
|
||||
self.propagation_transfer_progress = 1.0
|
||||
self.propagation_transfer_last_result = len(request_receipt.response)
|
||||
self.save_locally_delivered_transient_ids()
|
||||
|
||||
def message_get_progress(self, request_receipt):
|
||||
self.propagation_transfer_state = LXMRouter.PR_RECEIVING
|
||||
@@ -860,9 +916,14 @@ class LXMRouter:
|
||||
def peer(self, destination_hash, timestamp):
|
||||
if destination_hash in self.peers:
|
||||
peer = self.peers[destination_hash]
|
||||
peer.alive = True
|
||||
if timestamp > peer.peering_timebase:
|
||||
peer.alive = True
|
||||
peer.sync_backoff = 0
|
||||
peer.next_sync_attempt = 0
|
||||
|
||||
peer.peering_timebase = timestamp
|
||||
peer.last_heard = time.time()
|
||||
|
||||
else:
|
||||
peer = LXMPeer(self, destination_hash)
|
||||
peer.alive = True
|
||||
@@ -884,18 +945,50 @@ class LXMRouter:
|
||||
def sync_peers(self):
|
||||
culled_peers = []
|
||||
waiting_peers = []
|
||||
unresponsive_peers = []
|
||||
for peer_id in self.peers:
|
||||
peer = self.peers[peer_id]
|
||||
if time.time() > peer.last_heard + LXMPeer.MAX_UNREACHABLE:
|
||||
culled_peers.append(peer_id)
|
||||
else:
|
||||
if peer.state == LXMPeer.IDLE and len(peer.unhandled_messages) > 0:
|
||||
waiting_peers.append(peer)
|
||||
if peer.alive:
|
||||
waiting_peers.append(peer)
|
||||
else:
|
||||
if hasattr(peer, "next_sync_attempt") and time.time() > peer.next_sync_attempt:
|
||||
unresponsive_peers.append(peer)
|
||||
else:
|
||||
pass
|
||||
# RNS.log("Not adding peer "+str(peer)+" since it is in sync backoff", RNS.LOG_DEBUG)
|
||||
|
||||
peer_pool = []
|
||||
if len(waiting_peers) > 0:
|
||||
RNS.log("Randomly selecting peer to sync from "+str(len(waiting_peers))+" waiting peers.", RNS.LOG_DEBUG)
|
||||
selected_index = random.randint(0,len(waiting_peers)-1)
|
||||
selected_peer = waiting_peers[selected_index]
|
||||
fastest_peers = sorted(
|
||||
waiting_peers,
|
||||
key=lambda p: p.link_establishment_rate,
|
||||
reverse=True
|
||||
)[0:min(LXMRouter.FASTEST_N_RANDOM_POOL, len(waiting_peers))]
|
||||
peer_pool.extend(fastest_peers)
|
||||
|
||||
unknown_speed_peers = [p for p in waiting_peers if p.link_establishment_rate == 0]
|
||||
if len(unknown_speed_peers) > 0:
|
||||
peer_pool.extend(
|
||||
unknown_speed_peers[
|
||||
0:min(
|
||||
len(unknown_speed_peers),
|
||||
len(fastest_peers)
|
||||
)]
|
||||
)
|
||||
|
||||
RNS.log("Selecting peer to sync from "+str(len(waiting_peers))+" waiting peers.", RNS.LOG_DEBUG)
|
||||
|
||||
elif len(unresponsive_peers) > 0:
|
||||
RNS.log("No active peers available, randomly selecting peer to sync from "+str(len(unresponsive_peers))+" unresponsive peers.", RNS.LOG_DEBUG)
|
||||
peer_pool = unresponsive_peers
|
||||
|
||||
if len(peer_pool) > 0:
|
||||
selected_index = random.randint(0,len(peer_pool)-1)
|
||||
selected_peer = peer_pool[selected_index]
|
||||
RNS.log("Selected waiting peer "+str(selected_index)+": "+RNS.prettyhexrep(selected_peer.destination.hash), RNS.LOG_DEBUG)
|
||||
selected_peer.sync()
|
||||
|
||||
@@ -976,7 +1069,8 @@ class LXMRouter:
|
||||
remote_hash = remote_destination.hash
|
||||
|
||||
if not remote_hash in self.peers:
|
||||
self.peer(remote_hash, remote_timebase)
|
||||
if self.autopeer and RNS.Transport.hops_to(remote_hash) <= self.autopeer_maxdepth:
|
||||
self.peer(remote_hash, remote_timebase)
|
||||
|
||||
messages = data[1]
|
||||
for lxmf_data in messages:
|
||||
@@ -992,15 +1086,18 @@ class LXMRouter:
|
||||
except Exception as e:
|
||||
RNS.log("Error while unpacking received propagation resource", RNS.LOG_DEBUG)
|
||||
|
||||
def lxmf_propagation(self, lxmf_data):
|
||||
def lxmf_propagation(self, lxmf_data, signal_local_delivery=None, signal_duplicate=None):
|
||||
try:
|
||||
if len(lxmf_data) >= LXMessage.LXMF_OVERHEAD:
|
||||
transient_id = RNS.Identity.full_hash(lxmf_data)
|
||||
if not transient_id in self.propagation_entries and not transient_id in self.propagated_ids:
|
||||
|
||||
if not transient_id in self.propagation_entries and not transient_id in self.locally_processed_transient_ids:
|
||||
received = time.time()
|
||||
propagation_entry = [transient_id, received, lxmf_data]
|
||||
destination_hash = lxmf_data[:LXMessage.DESTINATION_LENGTH]
|
||||
|
||||
self.locally_processed_transient_ids[transient_id] = received
|
||||
|
||||
if destination_hash in self.delivery_destinations:
|
||||
delivery_destination = self.delivery_destinations[destination_hash]
|
||||
encrypted_lxmf_data = lxmf_data[LXMessage.DESTINATION_LENGTH:]
|
||||
@@ -1009,6 +1106,9 @@ class LXMRouter:
|
||||
self.lxmf_delivery(delivery_data, delivery_destination.type)
|
||||
self.locally_delivered_transient_ids[transient_id] = time.time()
|
||||
|
||||
if signal_local_delivery != None:
|
||||
return signal_local_delivery
|
||||
|
||||
else:
|
||||
if self.propagation_node:
|
||||
file_path = self.messagepath+"/"+RNS.hexrep(transient_id, delimit=False)+"_"+str(received)
|
||||
@@ -1023,8 +1123,19 @@ class LXMRouter:
|
||||
peer = self.peers[peer_id]
|
||||
peer.handle_message(transient_id)
|
||||
|
||||
else:
|
||||
# TODO: Add message to sneakernet queues when implemented
|
||||
RNS.log("Received propagated LXMF message "+RNS.prettyhexrep(transient_id)+", but this instance is not hosting a propagation node, discarding message.", RNS.LOG_DEBUG)
|
||||
|
||||
return True
|
||||
|
||||
else:
|
||||
if signal_duplicate != None:
|
||||
return signal_duplicate
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
@@ -1032,6 +1143,28 @@ class LXMRouter:
|
||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
|
||||
return False
|
||||
|
||||
def ingest_lxm_uri(self, uri, signal_local_delivery=None, signal_duplicate=None):
|
||||
try:
|
||||
if not uri.lower().startswith(LXMessage.URI_SCHEMA+"://"):
|
||||
RNS.log("Cannot ingest LXM, invalid URI provided.", RNS.LOG_ERROR)
|
||||
return False
|
||||
|
||||
else:
|
||||
lxmf_data = base64.urlsafe_b64decode(uri.replace(LXMessage.URI_SCHEMA+"://", "").replace("/", "")+"==")
|
||||
transient_id = RNS.Identity.full_hash(lxmf_data)
|
||||
|
||||
router_propagation_result = self.lxmf_propagation(lxmf_data, signal_local_delivery=signal_local_delivery, signal_duplicate=signal_duplicate)
|
||||
if router_propagation_result != False:
|
||||
RNS.log("LXM with transient ID "+RNS.prettyhexrep(transient_id)+" was ingested.", RNS.LOG_DEBUG)
|
||||
return router_propagation_result
|
||||
else:
|
||||
RNS.log("No valid LXM could be ingested from the provided URI", RNS.LOG_DEBUG)
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while decoding URI-encoded LXMF message. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
return False
|
||||
|
||||
def fail_message(self, lxmessage):
|
||||
RNS.log(str(lxmessage)+" failed to send", RNS.LOG_DEBUG)
|
||||
|
||||
|
||||
+102
-9
@@ -2,6 +2,7 @@ import RNS
|
||||
import RNS.vendor.umsgpack as msgpack
|
||||
|
||||
import time
|
||||
import base64
|
||||
|
||||
from .LXMF import APP_NAME
|
||||
|
||||
@@ -22,7 +23,8 @@ class LXMessage:
|
||||
OPPORTUNISTIC = 0x01
|
||||
DIRECT = 0x02
|
||||
PROPAGATED = 0x03
|
||||
valid_methods = [OPPORTUNISTIC, DIRECT, PROPAGATED]
|
||||
PAPER = 0x05
|
||||
valid_methods = [OPPORTUNISTIC, DIRECT, PROPAGATED, PAPER]
|
||||
|
||||
SOURCE_UNKNOWN = 0x01
|
||||
SIGNATURE_INVALID = 0x02
|
||||
@@ -31,9 +33,9 @@ class LXMessage:
|
||||
DESTINATION_LENGTH = RNS.Identity.TRUNCATED_HASHLENGTH//8
|
||||
SIGNATURE_LENGTH = RNS.Identity.SIGLENGTH//8
|
||||
|
||||
# LXMF overhead is 99 bytes per message:
|
||||
# 10 bytes for destination hash
|
||||
# 10 bytes for source hash
|
||||
# LXMF overhead is 111 bytes per message:
|
||||
# 16 bytes for destination hash
|
||||
# 16 bytes for source hash
|
||||
# 64 bytes for Ed25519 signature
|
||||
# 8 bytes for timestamp
|
||||
# 7 bytes for msgpack structure
|
||||
@@ -51,7 +53,7 @@ class LXMessage:
|
||||
# field of the packet, therefore we also add the length
|
||||
# of a destination hash to the calculation. With default
|
||||
# RNS and LXMF parameters, the largest single-packet
|
||||
# LXMF message we can send is 294 bytes. If a message
|
||||
# LXMF message we can send is 288 bytes. If a message
|
||||
# is larger than that, a Reticulum link will be used.
|
||||
ENCRYPTED_PACKET_MAX_CONTENT = ENCRYPTED_PACKET_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH
|
||||
|
||||
@@ -61,13 +63,13 @@ class LXMessage:
|
||||
LINK_PACKET_MDU = RNS.Link.MDU
|
||||
|
||||
# Which means that we can deliver single-packet LXMF
|
||||
# messages with content of up to 332 bytes over a link.
|
||||
# messages with content of up to 320 bytes over a link.
|
||||
# If a message is larger than that, LXMF will sequence
|
||||
# and transfer it as a RNS resource over the link instead.
|
||||
LINK_PACKET_MAX_CONTENT = LINK_PACKET_MDU - LXMF_OVERHEAD
|
||||
|
||||
# For plain packets without encryption, we can
|
||||
# fit up to 388 bytes of content.
|
||||
# fit up to 369 bytes of content.
|
||||
PLAIN_PACKET_MDU = RNS.Packet.PLAIN_MDU
|
||||
PLAIN_PACKET_MAX_CONTENT = PLAIN_PACKET_MDU - LXMF_OVERHEAD + DESTINATION_LENGTH
|
||||
|
||||
@@ -76,6 +78,12 @@ class LXMessage:
|
||||
ENCRYPTION_DESCRIPTION_EC = "Curve25519"
|
||||
ENCRYPTION_DESCRIPTION_UNENCRYPTED = "Unencrypted"
|
||||
|
||||
# Constants for QR/URI encoding LXMs
|
||||
URI_SCHEMA = "lxm"
|
||||
QR_ERROR_CORRECTION = "ERROR_CORRECT_L"
|
||||
QR_MAX_STORAGE = 2953
|
||||
PAPER_MDU = ((QR_MAX_STORAGE-(len(URI_SCHEMA)+len("://")))*6)//8
|
||||
|
||||
def __str__(self):
|
||||
if self.hash != None:
|
||||
return "<LXMessage "+RNS.hexrep(self.hash, delimit=False)+">"
|
||||
@@ -115,6 +123,9 @@ class LXMessage:
|
||||
self.state = LXMessage.DRAFT
|
||||
self.method = LXMessage.UNKNOWN
|
||||
|
||||
self.propagation_packed = None
|
||||
self.paper_packed = None
|
||||
|
||||
self.incoming = False
|
||||
self.signature_validated = False
|
||||
self.unverified_reason = None
|
||||
@@ -196,6 +207,7 @@ class LXMessage:
|
||||
self.timestamp = time.time()
|
||||
|
||||
self.propagation_packed = None
|
||||
self.paper_packed = None
|
||||
|
||||
self.payload = [self.timestamp, self.title, self.content, self.fields]
|
||||
|
||||
@@ -263,6 +275,19 @@ class LXMessage:
|
||||
self.method = self.desired_method
|
||||
self.representation = LXMessage.RESOURCE
|
||||
|
||||
elif self.desired_method == LXMessage.PAPER:
|
||||
paper_content_limit = LXMessage.PAPER_MDU
|
||||
|
||||
encrypted_data = self.__destination.encrypt(self.packed[LXMessage.DESTINATION_LENGTH:])
|
||||
self.paper_packed = self.packed[:LXMessage.DESTINATION_LENGTH]+encrypted_data
|
||||
|
||||
content_size = len(self.paper_packed)
|
||||
if content_size <= paper_content_limit:
|
||||
self.method = self.desired_method
|
||||
self.representation = LXMessage.PAPER
|
||||
else:
|
||||
raise TypeError("LXMessage desired paper delivery method, but content exceeds paper message maximum size.")
|
||||
|
||||
else:
|
||||
raise ValueError("Attempt to re-pack LXMessage "+str(self)+" that was already packed")
|
||||
|
||||
@@ -327,6 +352,16 @@ class LXMessage:
|
||||
else:
|
||||
self.transport_encrypted = False
|
||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
|
||||
elif self.method == LXMessage.PAPER:
|
||||
if self.__destination.type == RNS.Destination.SINGLE:
|
||||
self.transport_encrypted = True
|
||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC
|
||||
elif self.__destination.type == RNS.Destination.GROUP:
|
||||
self.transport_encrypted = True
|
||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_AES
|
||||
else:
|
||||
self.transport_encrypted = False
|
||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
|
||||
else:
|
||||
self.transport_encrypted = False
|
||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
|
||||
@@ -351,6 +386,16 @@ class LXMessage:
|
||||
except Exception as e:
|
||||
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
|
||||
|
||||
def __mark_paper_generated(self, receipt = None):
|
||||
RNS.log("Paper message generation succeeded for "+str(self), RNS.LOG_DEBUG)
|
||||
self.state = LXMessage.PAPER
|
||||
|
||||
if self.__delivery_callback != None and callable(self.__delivery_callback):
|
||||
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):
|
||||
if resource.status == RNS.Resource.COMPLETE:
|
||||
self.__mark_delivered()
|
||||
@@ -441,9 +486,56 @@ class LXMessage:
|
||||
RNS.log("Error while writing LXMF message to file \""+str(file_path)+"\". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
return None
|
||||
|
||||
def as_uri(self, finalise=True):
|
||||
self.determine_transport_encryption()
|
||||
if not self.packed:
|
||||
self.pack()
|
||||
|
||||
if self.desired_method == LXMessage.PAPER and self.paper_packed != None:
|
||||
# Encode packed LXM with URL-safe base64 and remove padding
|
||||
encoded_bytes = base64.urlsafe_b64encode(self.paper_packed)
|
||||
|
||||
# Add protocol specifier and return
|
||||
lxm_uri = LXMessage.URI_SCHEMA+"://"+encoded_bytes.decode("utf-8").replace("=","")
|
||||
|
||||
if finalise:
|
||||
self.__mark_paper_generated()
|
||||
|
||||
return lxm_uri
|
||||
|
||||
else:
|
||||
raise TypeError("Attempt to represent LXM with non-paper delivery method as URI")
|
||||
|
||||
def as_qr(self):
|
||||
self.determine_transport_encryption()
|
||||
if not self.packed:
|
||||
self.pack()
|
||||
|
||||
if self.desired_method == LXMessage.PAPER and self.paper_packed != None:
|
||||
import importlib
|
||||
if importlib.util.find_spec('qrcode') != None:
|
||||
import qrcode
|
||||
|
||||
qr = qrcode.make(
|
||||
error_correction = qrcode.constants.__dict__[LXMessage.QR_ERROR_CORRECTION],
|
||||
border = 1,
|
||||
data = self.as_uri(finalise=False),
|
||||
)
|
||||
|
||||
self.__mark_paper_generated()
|
||||
|
||||
return qr
|
||||
|
||||
else:
|
||||
RNS.log("Generating QR-code representanions of LXMs requires the \"qrcode\" module to be installed.", RNS.LOG_CRITICAL)
|
||||
RNS.log("You can install it with the command: python3 -m pip install qrcode", RNS.LOG_CRITICAL)
|
||||
return None
|
||||
|
||||
else:
|
||||
raise TypeError("Attempt to represent LXM with non-paper delivery method as QR-code")
|
||||
|
||||
@staticmethod
|
||||
def unpack_from_bytes(lxmf_bytes):
|
||||
def unpack_from_bytes(lxmf_bytes, original_method = None):
|
||||
destination_hash = lxmf_bytes[:LXMessage.DESTINATION_LENGTH]
|
||||
source_hash = lxmf_bytes[LXMessage.DESTINATION_LENGTH:2*LXMessage.DESTINATION_LENGTH]
|
||||
signature = lxmf_bytes[2*LXMessage.DESTINATION_LENGTH:2*LXMessage.DESTINATION_LENGTH+LXMessage.SIGNATURE_LENGTH]
|
||||
@@ -476,7 +568,8 @@ class LXMessage:
|
||||
title = "",
|
||||
fields = fields,
|
||||
destination_hash = destination_hash,
|
||||
source_hash = source_hash)
|
||||
source_hash = source_hash,
|
||||
desired_method = original_method)
|
||||
|
||||
message.hash = message_hash
|
||||
message.signature = signature
|
||||
|
||||
@@ -0,0 +1,507 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2016-2022 Mark Qvist / unsigned.io
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
DEFFERED_JOBS_DELAY = 10
|
||||
JOBS_INTERVAL = 5
|
||||
|
||||
import RNS
|
||||
import LXMF
|
||||
import argparse
|
||||
import threading
|
||||
import subprocess
|
||||
import shlex
|
||||
import time
|
||||
import os
|
||||
|
||||
from LXMF._version import __version__
|
||||
|
||||
from RNS.vendor.configobj import ConfigObj
|
||||
|
||||
configpath = None
|
||||
ignoredpath = None
|
||||
identitypath = None
|
||||
storagedir = None
|
||||
lxmdir = None
|
||||
targetloglevel = None
|
||||
|
||||
identity = None
|
||||
lxmd_config = None
|
||||
message_router = None
|
||||
lxmf_destination = None
|
||||
active_configuration = {}
|
||||
|
||||
last_peer_announce = None
|
||||
last_node_announce = None
|
||||
|
||||
def create_default_config(configpath):
|
||||
lxmd_config = ConfigObj(__default_lxmd_config__.splitlines())
|
||||
lxmd_config.filename = configpath
|
||||
lxmd_config.write()
|
||||
|
||||
def apply_config():
|
||||
global active_configuration, targetloglevel
|
||||
try:
|
||||
# Load peer settings
|
||||
if "lxmf" in lxmd_config and "display_name" in lxmd_config["lxmf"]:
|
||||
active_configuration["display_name"] = lxmd_config["lxmf"]["display_name"]
|
||||
else:
|
||||
active_configuration["display_name"] = "Anonymous Peer"
|
||||
|
||||
if "lxmf" in lxmd_config and "announce_at_start" in lxmd_config["lxmf"]:
|
||||
active_configuration["peer_announce_at_start"] = lxmd_config["lxmf"].as_bool("announce_at_start")
|
||||
else:
|
||||
active_configuration["peer_announce_at_start"] = False
|
||||
|
||||
if "lxmf" in lxmd_config and "announce_interval" in lxmd_config["lxmf"]:
|
||||
active_configuration["peer_announce_interval"] = lxmd_config["lxmf"].as_int("announce_interval")*60
|
||||
else:
|
||||
active_configuration["peer_announce_interval"] = None
|
||||
|
||||
if "lxmf" in lxmd_config and "on_inbound" in lxmd_config["lxmf"]:
|
||||
active_configuration["on_inbound"] = lxmd_config["lxmf"]["on_inbound"]
|
||||
else:
|
||||
active_configuration["on_inbound"] = None
|
||||
|
||||
# Load propagation node settings
|
||||
if "propagation" in lxmd_config and "enable_node" in lxmd_config["propagation"]:
|
||||
active_configuration["enable_propagation_node"] = lxmd_config["propagation"].as_bool("enable_node")
|
||||
else:
|
||||
active_configuration["enable_propagation_node"] = False
|
||||
|
||||
if "propagation" in lxmd_config and "auth_required" in lxmd_config["propagation"]:
|
||||
active_configuration["auth_required"] = lxmd_config["propagation"].as_bool("auth_required")
|
||||
else:
|
||||
active_configuration["auth_required"] = False
|
||||
|
||||
if "propagation" in lxmd_config and "announce_at_start" in lxmd_config["propagation"]:
|
||||
active_configuration["node_announce_at_start"] = lxmd_config["propagation"].as_bool("announce_at_start")
|
||||
else:
|
||||
active_configuration["node_announce_at_start"] = False
|
||||
|
||||
if "propagation" in lxmd_config and "autopeer" in lxmd_config["propagation"]:
|
||||
active_configuration["autopeer"] = lxmd_config["propagation"].as_bool("autopeer")
|
||||
else:
|
||||
active_configuration["autopeer"] = True
|
||||
|
||||
if "propagation" in lxmd_config and "autopeer_maxdepth" in lxmd_config["propagation"]:
|
||||
active_configuration["autopeer_maxdepth"] = lxmd_config["propagation"].as_int("autopeer_maxdepth")
|
||||
else:
|
||||
active_configuration["autopeer_maxdepth"] = None
|
||||
|
||||
if "propagation" in lxmd_config and "announce_interval" in lxmd_config["propagation"]:
|
||||
active_configuration["node_announce_interval"] = lxmd_config["propagation"].as_int("announce_interval")*60
|
||||
else:
|
||||
active_configuration["node_announce_interval"] = None
|
||||
|
||||
if "propagation" in lxmd_config and "message_storage_limit" in lxmd_config["propagation"]:
|
||||
active_configuration["message_storage_limit"] = lxmd_config["propagation"].as_float("message_storage_limit")
|
||||
if active_configuration["message_storage_limit"] < 0.005:
|
||||
active_configuration["message_storage_limit"] = 0.005
|
||||
else:
|
||||
active_configuration["message_storage_limit"] = 2000
|
||||
|
||||
if "propagation" in lxmd_config and "prioritise_destinations" in lxmd_config["propagation"]:
|
||||
active_configuration["prioritised_lxmf_destinations"] = lxmd_config["propagation"].as_list("prioritise_destinations")
|
||||
else:
|
||||
active_configuration["prioritised_lxmf_destinations"] = []
|
||||
|
||||
# Load various settings
|
||||
if "logging" in lxmd_config and "loglevel" in lxmd_config["logging"]:
|
||||
targetloglevel = lxmd_config["logging"].as_int("loglevel")
|
||||
|
||||
active_configuration["ignored_lxmf_destinations"] = []
|
||||
if os.path.isfile(ignoredpath):
|
||||
try:
|
||||
fh = open(ignoredpath, "rb")
|
||||
ignored_input = fh.read()
|
||||
fh.close()
|
||||
|
||||
ignored_hash_strs = ignored_input.splitlines()
|
||||
|
||||
for hash_str in ignored_hash_strs:
|
||||
if len(hash_str) == RNS.Identity.TRUNCATED_HASHLENGTH//8*2:
|
||||
try:
|
||||
ignored_hash = bytes.fromhex(hash_str.decode("utf-8"))
|
||||
active_configuration["ignored_lxmf_destinations"].append(ignored_hash)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not decode hash from: "+str(hash_str), RNS.LOG_DEBUG)
|
||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while loading list of ignored destinations: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
active_configuration["allowed_identities"] = []
|
||||
if os.path.isfile(allowedpath):
|
||||
try:
|
||||
fh = open(allowedpath, "rb")
|
||||
allowed_input = fh.read()
|
||||
fh.close()
|
||||
|
||||
allowed_hash_strs = allowed_input.splitlines()
|
||||
|
||||
for hash_str in allowed_hash_strs:
|
||||
if len(hash_str) == RNS.Identity.TRUNCATED_HASHLENGTH//8*2:
|
||||
try:
|
||||
allowed_hash = bytes.fromhex(hash_str.decode("utf-8"))
|
||||
active_configuration["allowed_identities"].append(allowed_hash)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not decode hash from: "+str(hash_str), RNS.LOG_DEBUG)
|
||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error while loading list of allowed identities: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Could not apply LXM Daemon configuration. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
raise e
|
||||
exit(3)
|
||||
|
||||
def lxmf_delivery(lxm):
|
||||
global active_configuration, lxmdir
|
||||
|
||||
try:
|
||||
written_path = lxm.write_to_directory(lxmdir)
|
||||
RNS.log("Received "+str(lxm)+" written to "+str(written_path), RNS.LOG_DEBUG)
|
||||
|
||||
if active_configuration["on_inbound"]:
|
||||
RNS.log("Calling external program to handle message", RNS.LOG_DEBUG)
|
||||
command = active_configuration["on_inbound"]
|
||||
processing_command = command+" \""+written_path+"\""
|
||||
return_code = subprocess.call(shlex.split(processing_command), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
else:
|
||||
RNS.log("No action defined for inbound messages, ignoring", RNS.LOG_DEBUG)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Error occurred while processing received message "+str(lxm)+". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
|
||||
def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbound = None, verbosity = 0, quietness = 0, service = False):
|
||||
global configpath, ignoredpath, identitypath, allowedpath, storagedir, lxmdir
|
||||
global lxmd_config, active_configuration, targetloglevel
|
||||
global message_router, lxmf_destination
|
||||
|
||||
if service:
|
||||
targetlogdest = RNS.LOG_FILE
|
||||
targetloglevel = None
|
||||
else:
|
||||
targetlogdest = RNS.LOG_STDOUT
|
||||
|
||||
# Get configuration
|
||||
if configdir == None:
|
||||
if os.path.isdir("/etc/lxmd") and os.path.isfile("/etc/lxmd/config"):
|
||||
configdir = "/etc/lxmd"
|
||||
elif os.path.isdir(RNS.Reticulum.userdir+"/.config/lxmd") and os.path.isfile(Reticulum.userdir+"/.config/lxmd/config"):
|
||||
configdir = RNS.Reticulum.userdir+"/.config/lxmd"
|
||||
else:
|
||||
configdir = RNS.Reticulum.userdir+"/.lxmd"
|
||||
|
||||
configpath = configdir+"/config"
|
||||
ignoredpath = configdir+"/ignored"
|
||||
allowedpath = configdir+"/allowed"
|
||||
identitypath = configdir+"/identity"
|
||||
storagedir = configdir+"/storage"
|
||||
lxmdir = storagedir+"/messages"
|
||||
|
||||
if not os.path.isdir(storagedir):
|
||||
os.makedirs(storagedir)
|
||||
|
||||
if not os.path.isdir(lxmdir):
|
||||
os.makedirs(lxmdir)
|
||||
|
||||
if not os.path.isfile(configpath):
|
||||
RNS.log("Could not load config file, creating default configuration file...")
|
||||
create_default_config(configpath)
|
||||
RNS.log("Default config file created. Make any necessary changes in "+configpath+" and restart lxmd if needed.")
|
||||
time.sleep(1.5)
|
||||
|
||||
if os.path.isfile(configpath):
|
||||
try:
|
||||
lxmd_config = ConfigObj(configpath)
|
||||
except Exception as e:
|
||||
RNS.log("Could not parse the configuration at "+configpath, RNS.LOG_ERROR)
|
||||
RNS.log("Check your configuration file for errors!", RNS.LOG_ERROR)
|
||||
RNS.panic()
|
||||
|
||||
apply_config()
|
||||
RNS.log("Configuration loaded from "+configpath, RNS.LOG_VERBOSE)
|
||||
|
||||
if targetloglevel == None:
|
||||
targetloglevel = 3
|
||||
|
||||
if verbosity != 0 or quietness != 0:
|
||||
targetloglevel = targetloglevel+verbosity-quietness
|
||||
|
||||
# Start Reticulum
|
||||
RNS.log("Substantiating Reticulum...")
|
||||
reticulum = RNS.Reticulum(configdir=rnsconfigdir, loglevel=targetloglevel, logdest=targetlogdest)
|
||||
|
||||
# Generate or load primary identity
|
||||
if os.path.isfile(identitypath):
|
||||
try:
|
||||
identity = RNS.Identity.from_file(identitypath)
|
||||
if identity != None:
|
||||
RNS.log("Loaded Primary Identity %s" % (str(identity)))
|
||||
else:
|
||||
RNS.log("Could not load the Primary Identity from "+identitypath, RNS.LOG_ERROR)
|
||||
exit(4)
|
||||
except Exception as e:
|
||||
RNS.log("Could not load the Primary Identity from "+identitypath, RNS.LOG_ERROR)
|
||||
RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR)
|
||||
exit(1)
|
||||
else:
|
||||
try:
|
||||
RNS.log("No Primary Identity file found, creating new...")
|
||||
identity = RNS.Identity()
|
||||
identity.to_file(identitypath)
|
||||
RNS.log("Created new Primary Identity %s" % (str(identity)))
|
||||
except Exception as e:
|
||||
RNS.log("Could not create and save a new Primary Identity", RNS.LOG_ERROR)
|
||||
RNS.log("The contained exception was: %s" % (str(e)), RNS.LOG_ERROR)
|
||||
exit(2)
|
||||
|
||||
# Start LXMF
|
||||
message_router = LXMF.LXMRouter(
|
||||
identity = identity,
|
||||
storagepath = storagedir,
|
||||
autopeer = active_configuration["autopeer"],
|
||||
autopeer_maxdepth = active_configuration["autopeer_maxdepth"],
|
||||
)
|
||||
message_router.register_delivery_callback(lxmf_delivery)
|
||||
|
||||
for destination_hash in active_configuration["ignored_lxmf_destinations"]:
|
||||
message_router.ignore_destination(destination_hash)
|
||||
|
||||
lxmf_destination = message_router.register_delivery_identity(identity, display_name=active_configuration["display_name"])
|
||||
|
||||
RNS.Identity.remember(
|
||||
packet_hash=None,
|
||||
destination_hash=lxmf_destination.hash,
|
||||
public_key=identity.get_public_key(),
|
||||
app_data=None
|
||||
)
|
||||
|
||||
# Set up authentication
|
||||
if active_configuration["auth_required"]:
|
||||
message_router.set_authentication(required=True)
|
||||
|
||||
if len(active_configuration["allowed_identities"]) == 0:
|
||||
RNS.log("Clint authentication was enabled, but no identity hashes could be loaded from "+str(allowedpath)+". Nobody will be able to sync messages from this propagation node.", RNS.LOG_WARNING)
|
||||
|
||||
for identity_hash in active_configuration["allowed_identities"]:
|
||||
message_router.allow(identity_hash)
|
||||
|
||||
RNS.log("LXMF Router ready to receive on "+RNS.prettyhexrep(lxmf_destination.hash))
|
||||
|
||||
if run_pn or active_configuration["enable_propagation_node"]:
|
||||
message_router.set_message_storage_limit(megabytes=active_configuration["message_storage_limit"])
|
||||
for dest_str in active_configuration["prioritised_lxmf_destinations"]:
|
||||
try:
|
||||
dest_hash = bytes.fromhex(dest_str)
|
||||
if len(dest_hash) == RNS.Reticulum.TRUNCATED_HASHLENGTH//8:
|
||||
message_router.prioritise(dest_hash)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("Cannot prioritise "+str(dest_str)+", it is not a valid destination hash", RNS.LOG_ERROR)
|
||||
|
||||
message_router.enable_propagation()
|
||||
|
||||
RNS.log("LXMF Propagation Node started on "+RNS.prettyhexrep(message_router.propagation_destination.hash))
|
||||
|
||||
RNS.log("Started lxmd version {version}".format(version=__version__), RNS.LOG_NOTICE)
|
||||
|
||||
threading.Thread(target=deferred_start_jobs, daemon=True).start()
|
||||
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
||||
def jobs():
|
||||
global active_configuration, last_peer_announce, last_node_announce
|
||||
global message_router, lxmf_destination
|
||||
|
||||
while True:
|
||||
try:
|
||||
if "peer_announce_interval" in active_configuration and active_configuration["peer_announce_interval"] != None:
|
||||
if time.time() > last_peer_announce + active_configuration["peer_announce_interval"]:
|
||||
RNS.log("Sending announce for LXMF delivery destination", RNS.LOG_EXTREME)
|
||||
message_router.announce(lxmf_destination.hash)
|
||||
last_peer_announce = time.time()
|
||||
|
||||
if "node_announce_interval" in active_configuration and active_configuration["node_announce_interval"] != None:
|
||||
if time.time() > last_node_announce + active_configuration["node_announce_interval"]:
|
||||
RNS.log("Sending announce for LXMF Propagation Node", RNS.LOG_EXTREME)
|
||||
message_router.announce_propagation_node()
|
||||
last_node_announce = time.time()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log("An error occurred while running periodic jobs. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
time.sleep(JOBS_INTERVAL)
|
||||
|
||||
def deferred_start_jobs():
|
||||
global active_configuration, last_peer_announce, last_node_announce
|
||||
global message_router, lxmf_destination
|
||||
time.sleep(DEFFERED_JOBS_DELAY)
|
||||
RNS.log("Running deferred start jobs")
|
||||
if active_configuration["peer_announce_at_start"]:
|
||||
RNS.log("Sending announce for LXMF delivery destination", RNS.LOG_EXTREME)
|
||||
message_router.announce(lxmf_destination.hash)
|
||||
|
||||
if active_configuration["node_announce_at_start"]:
|
||||
RNS.log("Sending announce for LXMF Propagation Node", RNS.LOG_EXTREME)
|
||||
message_router.announce_propagation_node()
|
||||
|
||||
last_peer_announce = time.time()
|
||||
last_node_announce = time.time()
|
||||
threading.Thread(target=jobs, daemon=True).start()
|
||||
|
||||
def main():
|
||||
try:
|
||||
parser = argparse.ArgumentParser(description="Lightweight Extensible Messaging Daemon")
|
||||
parser.add_argument("--config", action="store", default=None, help="path to alternative lxmd config directory", type=str)
|
||||
parser.add_argument("--rnsconfig", action="store", default=None, help="path to alternative Reticulum config directory", type=str)
|
||||
parser.add_argument("-p", "--propagation-node", action="store_true", default=False, help="run an LXMF Propagation Node")
|
||||
parser.add_argument("-i", "--on-inbound", action="store", metavar="PATH", default=None, help="executable to run when a message is received", type=str)
|
||||
parser.add_argument("-v", "--verbose", action="count", default=0)
|
||||
parser.add_argument("-q", "--quiet", action="count", default=0)
|
||||
parser.add_argument("-s", "--service", action="store_true", default=False, help="lxmd is running as a service and should log to file")
|
||||
parser.add_argument("--exampleconfig", action="store_true", default=False, help="print verbose configuration example to stdout and exit")
|
||||
parser.add_argument("--version", action="version", version="lxmd {version}".format(version=__version__))
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.exampleconfig:
|
||||
print(__default_lxmd_config__)
|
||||
exit()
|
||||
|
||||
program_setup(
|
||||
configdir = args.config,
|
||||
rnsconfigdir=args.rnsconfig,
|
||||
run_pn=args.propagation_node,
|
||||
on_inbound=args.on_inbound,
|
||||
verbosity=args.verbose,
|
||||
quietness=args.quiet,
|
||||
service=args.service
|
||||
)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("")
|
||||
exit()
|
||||
|
||||
__default_lxmd_config__ = """# This is an example LXM Daemon config file.
|
||||
# You should probably edit it to suit your
|
||||
# intended usage.
|
||||
|
||||
[propagation]
|
||||
|
||||
# Whether to enable propagation node
|
||||
enable_node = no
|
||||
|
||||
# Automatic announce interval in minutes.
|
||||
# 6 hours by default.
|
||||
announce_interval = 360
|
||||
|
||||
# Whether to announce when the node starts.
|
||||
announce_at_start = yes
|
||||
|
||||
# Wheter to automatically peer with other
|
||||
# propagation nodes on the network.
|
||||
autopeer = yes
|
||||
|
||||
# The maximum peering depth (in hops) for
|
||||
# automatically peered nodes.
|
||||
autopeer_maxdepth = 4
|
||||
|
||||
# The maximum amount of storage to use for
|
||||
# the LXMF Propagation Node message store,
|
||||
# specified in megabytes. When this limit
|
||||
# is reached, LXMF will periodically remove
|
||||
# messages in its message store. By default,
|
||||
# LXMF prioritises keeping messages that are
|
||||
# new and small. Large and old messages will
|
||||
# be removed first. This setting is optional
|
||||
# and defaults to 2 gigabytes.
|
||||
# message_storage_limit = 2000
|
||||
|
||||
# You can tell the LXMF message router to
|
||||
# prioritise storage for one or more
|
||||
# destinations. If the message store reaches
|
||||
# the specified limit, LXMF will prioritise
|
||||
# keeping messages for destinations specified
|
||||
# with this option. This setting is optional,
|
||||
# and generally you do not need to use it.
|
||||
# prioritise_destinations = 41d20c727598a3fbbdf9106133a3a0ed, d924b81822ca24e68e2effea99bcb8cf
|
||||
|
||||
# By default, any destination is allowed to
|
||||
# connect and download messages, but you can
|
||||
# optionally restrict this. If you enable
|
||||
# authentication, you must provide a list of
|
||||
# allowed identity hashes in the a file named
|
||||
# "allowed" in the lxmd config directory.
|
||||
auth_required = no
|
||||
|
||||
|
||||
[lxmf]
|
||||
|
||||
# The LXM Daemon will create an LXMF destination
|
||||
# that it can receive messages on. This option sets
|
||||
# the announced display name for this destination.
|
||||
display_name = Anonymous Peer
|
||||
|
||||
# It is possible to announce the internal LXMF
|
||||
# destination when the LXM Daemon starts up.
|
||||
announce_at_start = no
|
||||
|
||||
# You can also announce the delivery destination
|
||||
# at a specified interval. This is not enabled by
|
||||
# default.
|
||||
# announce_interval = 360
|
||||
|
||||
# You can configure an external program to be run
|
||||
# every time a message is received. The program
|
||||
# will receive as an argument the full path to the
|
||||
# message saved as a file. The example below will
|
||||
# simply result in the message getting deleted as
|
||||
# soon as it has been received.
|
||||
# on_inbound = rm
|
||||
|
||||
|
||||
[logging]
|
||||
# Valid log levels are 0 through 7:
|
||||
# 0: Log only critical information
|
||||
# 1: Log errors and lower log levels
|
||||
# 2: Log warnings and lower log levels
|
||||
# 3: Log notices and lower log levels
|
||||
# 4: Log info and lower (this is the default)
|
||||
# 5: Verbose logging
|
||||
# 6: Debug logging
|
||||
# 7: Extreme logging
|
||||
loglevel = 4
|
||||
|
||||
"""
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__ = "0.1.8"
|
||||
__version__ = "0.3.4"
|
||||
@@ -8,10 +8,12 @@ clean:
|
||||
remove_symlinks:
|
||||
@echo Removing symlinks for build...
|
||||
-rm ./RNS
|
||||
-rm ./LXMF/Utilities/LXMF
|
||||
|
||||
create_symlinks:
|
||||
@echo Creating symlinks...
|
||||
-ln -s ../Reticulum/RNS ./
|
||||
-ln -s ../../LXMF ./LXMF/Utilities/LXMF
|
||||
|
||||
build_wheel:
|
||||
python3 setup.py sdist bdist_wheel
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
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](https://github.com/markqvist/reticulum) and offers zero-conf message routing, end-to-end encryption and Forward Secrecy by default.
|
||||
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)
|
||||
- [Nomad Network](https://unsigned.io/nomadnet)
|
||||
- [Nexus Messenger](https://github.com/HarlekinSimplex/nexus_messenger)
|
||||
|
||||
## Structure
|
||||
|
||||
LXMF messages are stored in a simple and efficient format, that's easy to parse and write.
|
||||
|
||||
##### The format follows this general structure:
|
||||
### The format follows this general structure:
|
||||
|
||||
- Destination
|
||||
- Source
|
||||
@@ -18,14 +25,14 @@ LXMF messages are stored in a simple and efficient format, that's easy to parse
|
||||
- Title
|
||||
- Fields
|
||||
|
||||
##### And these rules:
|
||||
### 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 theses cases a _transient-id_ is used to identify the message while in storage or transit.
|
||||
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 10-byte Reticulum destination hashes
|
||||
- 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.
|
||||
@@ -39,7 +46,7 @@ LXMF messages are stored in a simple and efficient format, that's easy to parse
|
||||
|
||||
## Usage Examples
|
||||
|
||||
LXMF offers flexibility to implement many different messaging schemes, ranging from human communication to machine control and sensor monitoring. Here's a few 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.
|
||||
|
||||
@@ -76,7 +83,7 @@ The LXM Router then handles the heavy lifting, such as message packing, encrypti
|
||||
|
||||
## Transport Encryption
|
||||
|
||||
LXMF uses encryption provided by [Reticulum](https://github.com/markqvist/reticulum), and thus uses end-to-end encryption by default. The delivery method of a message will influence which transport encryption scheme is used.
|
||||
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.
|
||||
|
||||
- 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 _ephemeral_ keys derived with _ECDH_ on _Curve25519_. This mode offers Perfect Forward Secrecy.
|
||||
|
||||
@@ -88,21 +95,64 @@ LXMF uses encryption provided by [Reticulum](https://github.com/markqvist/reticu
|
||||
|
||||
Assuming the default Reticulum configuration, the binary wire-format is as follows:
|
||||
|
||||
- 10 bytes destination hash
|
||||
- 10 bytes source hash
|
||||
- 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 99 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.
|
||||
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.
|
||||
|
||||
## 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 `6b3362bd2c1dbf87b66a85f79a8d8c75`. To be able to decrypt and read the message, you will need to import the following Reticulum Identity to an LXMF messaging app:
|
||||
|
||||
`3BPTDTQCRZPKJT3TXAJCMQFMOYWIM3OCLKPWMG4HCF2T4CH3YZHVNHNRDU6QAZWV2KBHMWBNT2C62TQEVC5GLFM4MN25VLZFSK3ADRQ=`
|
||||
|
||||
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.
|
||||
|
||||
<p align="center"><img width="50%" src="./docs/paper_msg_test.png"/></p>
|
||||
|
||||
You can also find the entire message in <a href="lxm://azNivSwdv4e2aoX3mo2MdTAozuI7BlzrLlHULmnVgpz3dNT9CMPVwgywzCJP8FVogj5j_kU7j7ywuvBNcr45kRTrd19c3iHenmnSDe4VEd6FuGsAiT0Khzl7T81YZHPTDhRNp0FdhDE9AJ7uphw7zKMyqhHHxOxqrYeBeKF66gpPxDceqjsOApvsSwggjcuHBx9OxOBy05XmnJxA1unCKgvNfOFYc1T47luxoY3c0dLOJnJPwZuFRytx2TXlQNZzOJ28yTEygIfkDqEO9mZi5lgev7XZJ0DvgioQxMIyoCm7lBUzfq66zW3SQj6vHHph7bhr36dLOCFgk4fZA6yia2MlTT9KV66Tn2l8mPNDlvuSAJhwDA_xx2PN9zKadCjo9sItkAp8r-Ss1CzoUWZUAyT1oDw7ly6RrzGBG-e3eM3CL6u1juIeFiHby7_3cON-6VTUuk4xR5nwKlFTu5vsYMVXe5H3VahiDSS4Q1aqX7I">this link</a>:
|
||||
|
||||
`lxm://azNivSwdv4e2aoX3mo2MdTAozuI7BlzrLlHULmnVgpz3dNT9CMPVwgywzCJP8FVogj5j_kU7j7ywuvBNcr45kRTrd19c3iHenmnSDe4VEd6FuGsAiT0Khzl7T81YZHPTDhRNp0FdhDE9AJ7uphw7zKMyqhHHxOxqrYeBeKF66gpPxDceqjsOApvsSwggjcuHBx9OxOBy05XmnJxA1unCKgvNfOFYc1T47luxoY3c0dLOJnJPwZuFRytx2TXlQNZzOJ28yTEygIfkDqEO9mZi5lgev7XZJ0DvgioQxMIyoCm7lBUzfq66zW3SQj6vHHph7bhr36dLOCFgk4fZA6yia2MlTT9KV66Tn2l8mPNDlvuSAJhwDA_xx2PN9zKadCjo9sItkAp8r-Ss1CzoUWZUAyT1oDw7ly6RrzGBG-e3eM3CL6u1juIeFiHby7_3cON-6VTUuk4xR5nwKlFTu5vsYMVXe5H3VahiDSS4Q1aqX7I`
|
||||
|
||||
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.
|
||||
|
||||
## 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.
|
||||
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.
|
||||
|
||||
## Installation
|
||||
|
||||
If you want to try out LXMF, you can install it with pip:
|
||||
|
||||
```bash
|
||||
pip3 install lxmf
|
||||
pip install lxmf
|
||||
```
|
||||
|
||||
If you are using an operating system that blocks normal user package installation via `pip`,
|
||||
you can return `pip` to normal behaviour by editing the `~/.config/pip/pip.conf` file,
|
||||
and adding the following directive in the `[global]` section:
|
||||
|
||||
```text
|
||||
[global]
|
||||
break-system-packages = true
|
||||
```
|
||||
|
||||
Alternatively, you can use the `pipx` tool to install Reticulum in an isolated environment:
|
||||
|
||||
```bash
|
||||
pipx install lxmf
|
||||
```
|
||||
|
||||
## Development Roadmap
|
||||
|
||||
LXMF is actively being developed, and the following improvements and features are currently planned for implementation:
|
||||
|
||||
- Write and release full API and protocol documentation
|
||||
- Update examples in readme to actually work
|
||||
- Content Destinations, and easy to use API for group messaging and discussion threads
|
||||
- Sneakernet and physical transport functionality
|
||||
- Documenting and possibly expanding LXMF limits and priorities
|
||||
- Sync affinity based on link speeds and distances, for more intelligently choosing peer sync order
|
||||
- Markets on LXMF
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
@@ -14,12 +14,17 @@ setuptools.setup(
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/markqvist/lxmf",
|
||||
packages=setuptools.find_packages(),
|
||||
packages=["LXMF", "LXMF.Utilities"],
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
install_requires=['rns>=0.3.12'],
|
||||
python_requires='>=3.6',
|
||||
entry_points= {
|
||||
'console_scripts': [
|
||||
'lxmd=LXMF.Utilities.lxmd:main',
|
||||
]
|
||||
},
|
||||
install_requires=['rns>=0.6.2'],
|
||||
python_requires='>=3.7',
|
||||
)
|
||||
Reference in new issue
Block a user