mirror of
https://github.com/markqvist/LXMF
synced 2026-11-27 13:52:19 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b10755e34f | ||
|
|
683e9ee412 | ||
|
|
aa3886720f | ||
|
|
7ee7c60e77 | ||
|
|
0c52d3fcd4 | ||
|
|
8f425e6dde | ||
|
|
a1c897a8ca | ||
|
|
9fa6a144d0 | ||
|
|
54005c148a | ||
|
|
abe2e78283 | ||
|
|
edbb887d81 | ||
|
|
540aa1a496 | ||
|
|
3d31620160 | ||
|
|
6b983872fa | ||
|
|
bb7bbaf124 | ||
|
|
dad21bcca7 | ||
|
|
f75ea842d9 | ||
|
|
f7ee4c1d86 | ||
|
|
58c61a2557 | ||
|
|
730a611f7a | ||
|
|
ab68c15d2d |
No files matched your search
+76
-6
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
|
import base64
|
||||||
import atexit
|
import atexit
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ class LXMRouter:
|
|||||||
self.propagation_transfer_last_result = None
|
self.propagation_transfer_last_result = None
|
||||||
self.propagation_transfer_max_messages = None
|
self.propagation_transfer_max_messages = None
|
||||||
self.locally_delivered_transient_ids = {}
|
self.locally_delivered_transient_ids = {}
|
||||||
|
self.locally_processed_transient_ids = {}
|
||||||
|
|
||||||
if identity == None:
|
if identity == None:
|
||||||
identity = RNS.Identity()
|
identity = RNS.Identity()
|
||||||
@@ -105,7 +107,6 @@ class LXMRouter:
|
|||||||
|
|
||||||
self.peers = {}
|
self.peers = {}
|
||||||
self.propagation_entries = {}
|
self.propagation_entries = {}
|
||||||
self.propagated_ids = {}
|
|
||||||
|
|
||||||
RNS.Transport.register_announce_handler(LXMFDeliveryAnnounceHandler(self))
|
RNS.Transport.register_announce_handler(LXMFDeliveryAnnounceHandler(self))
|
||||||
RNS.Transport.register_announce_handler(LXMFPropagationAnnounceHandler(self))
|
RNS.Transport.register_announce_handler(LXMFPropagationAnnounceHandler(self))
|
||||||
@@ -118,7 +119,14 @@ class LXMRouter:
|
|||||||
data = locally_delivered_file.read()
|
data = locally_delivered_file.read()
|
||||||
self.locally_delivered_transient_ids = msgpack.unpackb(data)
|
self.locally_delivered_transient_ids = msgpack.unpackb(data)
|
||||||
locally_delivered_file.close()
|
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:
|
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)
|
RNS.log("Could not load locally delivered message ID cache from storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
@@ -424,7 +432,7 @@ class LXMRouter:
|
|||||||
self.clean_links()
|
self.clean_links()
|
||||||
|
|
||||||
if self.processing_count % LXMRouter.JOB_TRANSIENT_INTERVAL == 0:
|
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:
|
if self.processing_count % LXMRouter.JOB_STORE_INTERVAL == 0:
|
||||||
self.clean_message_store()
|
self.clean_message_store()
|
||||||
@@ -458,7 +466,7 @@ class LXMRouter:
|
|||||||
self.acknowledge_sync_completion()
|
self.acknowledge_sync_completion()
|
||||||
RNS.log("Cleaned outbound propagation link", RNS.LOG_DEBUG)
|
RNS.log("Cleaned outbound propagation link", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
def clean_transient_id_cache(self):
|
def clean_transient_id_caches(self):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
removed_entries = []
|
removed_entries = []
|
||||||
for transient_id in self.locally_delivered_transient_ids:
|
for transient_id in self.locally_delivered_transient_ids:
|
||||||
@@ -470,6 +478,16 @@ class LXMRouter:
|
|||||||
self.locally_delivered_transient_ids.pop(transient_id)
|
self.locally_delivered_transient_ids.pop(transient_id)
|
||||||
RNS.log("Cleaned "+RNS.prettyhexrep(transient_id)+" from local delivery cache", RNS.LOG_DEBUG)
|
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):
|
def clean_message_store(self):
|
||||||
# Check and remove expired messages
|
# Check and remove expired messages
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@@ -571,6 +589,18 @@ class LXMRouter:
|
|||||||
except Exception as e:
|
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)
|
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):
|
def exit_handler(self):
|
||||||
if self.propagation_node:
|
if self.propagation_node:
|
||||||
try:
|
try:
|
||||||
@@ -589,6 +619,7 @@ class LXMRouter:
|
|||||||
RNS.log("Could not save propagation node peers to storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Could not save propagation node peers to storage. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
|
|
||||||
self.save_locally_delivered_transient_ids()
|
self.save_locally_delivered_transient_ids()
|
||||||
|
self.save_locally_processed_transient_ids()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "<LXMRouter "+RNS.hexrep(self.identity.hash, delimit=False)+">"
|
return "<LXMRouter "+RNS.hexrep(self.identity.hash, delimit=False)+">"
|
||||||
@@ -1012,15 +1043,18 @@ class LXMRouter:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("Error while unpacking received propagation resource", RNS.LOG_DEBUG)
|
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:
|
try:
|
||||||
if len(lxmf_data) >= LXMessage.LXMF_OVERHEAD:
|
if len(lxmf_data) >= LXMessage.LXMF_OVERHEAD:
|
||||||
transient_id = RNS.Identity.full_hash(lxmf_data)
|
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()
|
received = time.time()
|
||||||
propagation_entry = [transient_id, received, lxmf_data]
|
propagation_entry = [transient_id, received, lxmf_data]
|
||||||
destination_hash = lxmf_data[:LXMessage.DESTINATION_LENGTH]
|
destination_hash = lxmf_data[:LXMessage.DESTINATION_LENGTH]
|
||||||
|
|
||||||
|
self.locally_processed_transient_ids[transient_id] = received
|
||||||
|
|
||||||
if destination_hash in self.delivery_destinations:
|
if destination_hash in self.delivery_destinations:
|
||||||
delivery_destination = self.delivery_destinations[destination_hash]
|
delivery_destination = self.delivery_destinations[destination_hash]
|
||||||
encrypted_lxmf_data = lxmf_data[LXMessage.DESTINATION_LENGTH:]
|
encrypted_lxmf_data = lxmf_data[LXMessage.DESTINATION_LENGTH:]
|
||||||
@@ -1029,6 +1063,9 @@ class LXMRouter:
|
|||||||
self.lxmf_delivery(delivery_data, delivery_destination.type)
|
self.lxmf_delivery(delivery_data, delivery_destination.type)
|
||||||
self.locally_delivered_transient_ids[transient_id] = time.time()
|
self.locally_delivered_transient_ids[transient_id] = time.time()
|
||||||
|
|
||||||
|
if signal_local_delivery != None:
|
||||||
|
return signal_local_delivery
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if self.propagation_node:
|
if self.propagation_node:
|
||||||
file_path = self.messagepath+"/"+RNS.hexrep(transient_id, delimit=False)+"_"+str(received)
|
file_path = self.messagepath+"/"+RNS.hexrep(transient_id, delimit=False)+"_"+str(received)
|
||||||
@@ -1043,8 +1080,19 @@ class LXMRouter:
|
|||||||
peer = self.peers[peer_id]
|
peer = self.peers[peer_id]
|
||||||
peer.handle_message(transient_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
|
return True
|
||||||
|
|
||||||
|
else:
|
||||||
|
if signal_duplicate != None:
|
||||||
|
return signal_duplicate
|
||||||
|
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -1052,6 +1100,28 @@ class LXMRouter:
|
|||||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
|
RNS.log("The contained exception was: "+str(e), RNS.LOG_DEBUG)
|
||||||
return False
|
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):
|
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)
|
||||||
|
|
||||||
|
|||||||
+96
-3
@@ -2,6 +2,7 @@ import RNS
|
|||||||
import RNS.vendor.umsgpack as msgpack
|
import RNS.vendor.umsgpack as msgpack
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import base64
|
||||||
|
|
||||||
from .LXMF import APP_NAME
|
from .LXMF import APP_NAME
|
||||||
|
|
||||||
@@ -22,7 +23,8 @@ class LXMessage:
|
|||||||
OPPORTUNISTIC = 0x01
|
OPPORTUNISTIC = 0x01
|
||||||
DIRECT = 0x02
|
DIRECT = 0x02
|
||||||
PROPAGATED = 0x03
|
PROPAGATED = 0x03
|
||||||
valid_methods = [OPPORTUNISTIC, DIRECT, PROPAGATED]
|
PAPER = 0x05
|
||||||
|
valid_methods = [OPPORTUNISTIC, DIRECT, PROPAGATED, PAPER]
|
||||||
|
|
||||||
SOURCE_UNKNOWN = 0x01
|
SOURCE_UNKNOWN = 0x01
|
||||||
SIGNATURE_INVALID = 0x02
|
SIGNATURE_INVALID = 0x02
|
||||||
@@ -76,6 +78,12 @@ class LXMessage:
|
|||||||
ENCRYPTION_DESCRIPTION_EC = "Curve25519"
|
ENCRYPTION_DESCRIPTION_EC = "Curve25519"
|
||||||
ENCRYPTION_DESCRIPTION_UNENCRYPTED = "Unencrypted"
|
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):
|
def __str__(self):
|
||||||
if self.hash != None:
|
if self.hash != None:
|
||||||
return "<LXMessage "+RNS.hexrep(self.hash, delimit=False)+">"
|
return "<LXMessage "+RNS.hexrep(self.hash, delimit=False)+">"
|
||||||
@@ -115,6 +123,9 @@ class LXMessage:
|
|||||||
self.state = LXMessage.DRAFT
|
self.state = LXMessage.DRAFT
|
||||||
self.method = LXMessage.UNKNOWN
|
self.method = LXMessage.UNKNOWN
|
||||||
|
|
||||||
|
self.propagation_packed = None
|
||||||
|
self.paper_packed = None
|
||||||
|
|
||||||
self.incoming = False
|
self.incoming = False
|
||||||
self.signature_validated = False
|
self.signature_validated = False
|
||||||
self.unverified_reason = None
|
self.unverified_reason = None
|
||||||
@@ -196,6 +207,7 @@ class LXMessage:
|
|||||||
self.timestamp = time.time()
|
self.timestamp = time.time()
|
||||||
|
|
||||||
self.propagation_packed = None
|
self.propagation_packed = None
|
||||||
|
self.paper_packed = None
|
||||||
|
|
||||||
self.payload = [self.timestamp, self.title, self.content, self.fields]
|
self.payload = [self.timestamp, self.title, self.content, self.fields]
|
||||||
|
|
||||||
@@ -263,6 +275,19 @@ class LXMessage:
|
|||||||
self.method = self.desired_method
|
self.method = self.desired_method
|
||||||
self.representation = LXMessage.RESOURCE
|
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:
|
else:
|
||||||
raise ValueError("Attempt to re-pack LXMessage "+str(self)+" that was already packed")
|
raise ValueError("Attempt to re-pack LXMessage "+str(self)+" that was already packed")
|
||||||
|
|
||||||
@@ -327,6 +352,16 @@ class LXMessage:
|
|||||||
else:
|
else:
|
||||||
self.transport_encrypted = False
|
self.transport_encrypted = False
|
||||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
|
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:
|
else:
|
||||||
self.transport_encrypted = False
|
self.transport_encrypted = False
|
||||||
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
|
self.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_UNENCRYPTED
|
||||||
@@ -351,6 +386,16 @@ class LXMessage:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
RNS.log("An error occurred in the external delivery callback for "+str(message), RNS.LOG_ERROR)
|
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):
|
def __resource_concluded(self, resource):
|
||||||
if resource.status == RNS.Resource.COMPLETE:
|
if resource.status == RNS.Resource.COMPLETE:
|
||||||
self.__mark_delivered()
|
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)
|
RNS.log("Error while writing LXMF message to file \""+str(file_path)+"\". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
return None
|
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
|
@staticmethod
|
||||||
def unpack_from_bytes(lxmf_bytes):
|
def unpack_from_bytes(lxmf_bytes, original_method = None):
|
||||||
destination_hash = lxmf_bytes[:LXMessage.DESTINATION_LENGTH]
|
destination_hash = lxmf_bytes[:LXMessage.DESTINATION_LENGTH]
|
||||||
source_hash = lxmf_bytes[LXMessage.DESTINATION_LENGTH:2*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]
|
signature = lxmf_bytes[2*LXMessage.DESTINATION_LENGTH:2*LXMessage.DESTINATION_LENGTH+LXMessage.SIGNATURE_LENGTH]
|
||||||
@@ -476,7 +568,8 @@ class LXMessage:
|
|||||||
title = "",
|
title = "",
|
||||||
fields = fields,
|
fields = fields,
|
||||||
destination_hash = destination_hash,
|
destination_hash = destination_hash,
|
||||||
source_hash = source_hash)
|
source_hash = source_hash,
|
||||||
|
desired_method = original_method)
|
||||||
|
|
||||||
message.hash = message_hash
|
message.hash = message_hash
|
||||||
message.signature = signature
|
message.signature = signature
|
||||||
|
|||||||
+1
-1
@@ -1 +1 @@
|
|||||||
__version__ = "0.2.2"
|
__version__ = "0.2.6"
|
||||||
@@ -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
|
## Structure
|
||||||
|
|
||||||
LXMF messages are stored in a simple and efficient format, that's easy to parse and write.
|
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
|
- Destination
|
||||||
- Source
|
- Source
|
||||||
@@ -18,7 +25,7 @@ LXMF messages are stored in a simple and efficient format, that's easy to parse
|
|||||||
- Title
|
- Title
|
||||||
- Fields
|
- 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.
|
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.
|
||||||
|
|
||||||
@@ -76,7 +83,7 @@ The LXM Router then handles the heavy lifting, such as message packing, encrypti
|
|||||||
|
|
||||||
## Transport Encryption
|
## 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.
|
- 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,13 +95,29 @@ LXMF uses encryption provided by [Reticulum](https://github.com/markqvist/reticu
|
|||||||
|
|
||||||
Assuming the default Reticulum configuration, the binary wire-format is as follows:
|
Assuming the default Reticulum configuration, the binary wire-format is as follows:
|
||||||
|
|
||||||
- 10 bytes destination hash
|
- 16 bytes destination hash
|
||||||
- 10 bytes source hash
|
- 16 bytes source hash
|
||||||
- 64 bytes Ed25519 signature
|
- 64 bytes Ed25519 signature
|
||||||
- Remaining bytes of [msgpack](https://msgpack.org) payload data, in accordance with the structure defined above
|
- 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 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.
|
||||||
|
|
||||||
|
## 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 the 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
|
## 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.
|
||||||
@@ -106,3 +129,15 @@ If you want to try out LXMF, you can install it with pip:
|
|||||||
```bash
|
```bash
|
||||||
pip3 install lxmf
|
pip3 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 |
Reference in new issue
Block a user