mirror of
https://github.com/markqvist/LXMF
synced 2026-11-22 23:10:36 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0e9fa6659 | ||
|
|
7a1bcc134b | ||
|
|
87413b9355 | ||
|
|
6ed16916d6 | ||
|
|
754ae969e1 | ||
|
|
1ee0c83168 | ||
|
|
2812a07165 | ||
|
|
10be1383e5 | ||
|
|
4d356bcda8 | ||
|
|
da6fb3d0f3 | ||
|
|
56cb637bfa | ||
|
|
2872c94394 | ||
|
|
f307f33bf8 | ||
|
|
a095ba7e40 | ||
|
|
0dc1e13f9d | ||
|
|
f83600430a | ||
|
|
537123896b | ||
|
|
bc8863c3b1 | ||
|
|
b894c5a2a6 | ||
|
|
0ac4660510 | ||
|
|
672054177c | ||
|
|
55cf934475 | ||
|
|
b690880332 | ||
|
|
7220a4d6f7 | ||
|
|
5abf01a88f | ||
|
|
51a4d19595 | ||
|
|
ad8fb74d9e | ||
|
|
447a8a920c | ||
|
|
0ba3ea98cb | ||
|
|
fc0b086cb1 | ||
|
|
7a40bd44e8 | ||
|
|
afe6815637 | ||
|
|
a64f3a58f7 | ||
|
|
2bb34176b7 | ||
|
|
6f80c6941d | ||
|
|
02d42747b7 | ||
|
|
5b81ecce04 |
No files matched your search
+16
-1
@@ -1 +1,16 @@
|
||||
APP_NAME = "lxmf"
|
||||
APP_NAME = "lxmf"
|
||||
|
||||
# WARNING! These field specifiers are floating and not
|
||||
# yet final! Consider highly experiemental, and expect
|
||||
# them to change in the future! You have been warned :)
|
||||
|
||||
FIELD_EMBEDDED_LXMS = 0x01
|
||||
FIELD_TELEMETRY = 0x02
|
||||
FIELD_TELEMETRY_STREAM = 0x03
|
||||
FIELD_ICON_APPEARANCE = 0x04
|
||||
FIELD_FILE_ATTACHMENTS = 0x05
|
||||
FIELD_IMAGE = 0x06
|
||||
FIELD_AUDIO = 0x07
|
||||
FIELD_THREAD = 0x08
|
||||
FIELD_COMMANDS = 0x09
|
||||
FIELD_RESULTS = 0x0A
|
||||
+11
-2
@@ -22,7 +22,7 @@ class LXMPeer:
|
||||
|
||||
# Maximum amount of time a peer can
|
||||
# be unreachable before it is removed
|
||||
MAX_UNREACHABLE = 4*24*60*60
|
||||
MAX_UNREACHABLE = 14*24*60*60
|
||||
|
||||
# Everytime consecutive time a sync
|
||||
# link fails to establish, add this
|
||||
@@ -43,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:
|
||||
@@ -60,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:
|
||||
@@ -81,6 +86,7 @@ class LXMPeer:
|
||||
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
|
||||
@@ -94,7 +100,6 @@ class LXMPeer:
|
||||
self.destination = RNS.Destination(self.identity, RNS.Destination.OUT, RNS.Destination.SINGLE, APP_NAME, "propagation")
|
||||
|
||||
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()
|
||||
|
||||
@@ -253,6 +258,10 @@ 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()
|
||||
|
||||
+73
-17
@@ -19,7 +19,7 @@ class LXMRouter:
|
||||
MAX_DELIVERY_ATTEMPTS = 5
|
||||
PROCESSING_INTERVAL = 4
|
||||
DELIVERY_RETRY_WAIT = 7
|
||||
PATH_REQUEST_WAIT = 5
|
||||
PATH_REQUEST_WAIT = 7
|
||||
LINK_MAX_INACTIVITY = 10*60
|
||||
|
||||
MESSAGE_EXPIRY = 30*24*60*60
|
||||
@@ -28,6 +28,7 @@ class LXMRouter:
|
||||
|
||||
AUTOPEER = True
|
||||
AUTOPEER_MAXDEPTH = 4
|
||||
FASTEST_N_RANDOM_POOL = 2
|
||||
|
||||
PR_PATH_TIMEOUT = 10
|
||||
|
||||
@@ -39,8 +40,12 @@ class LXMRouter:
|
||||
PR_RECEIVING = 0x05
|
||||
PR_RESPONSE_RECEIVED = 0x06
|
||||
PR_COMPLETE = 0x07
|
||||
PR_NO_IDENTITY_RCVD = 0xf0
|
||||
PR_NO_ACCESS = 0xf1
|
||||
PR_NO_PATH = 0xf0
|
||||
PR_LINK_FAILED = 0xf1
|
||||
PR_TRANSFER_FAILED = 0xf2
|
||||
PR_NO_IDENTITY_RCVD = 0xf3
|
||||
PR_NO_ACCESS = 0xf4
|
||||
PR_FAILED = 0xfe
|
||||
|
||||
PR_ALL_MESSAGES = 0x00
|
||||
|
||||
@@ -153,7 +158,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
|
||||
@@ -219,9 +224,9 @@ class LXMRouter:
|
||||
if max_messages == None:
|
||||
max_messages = LXMRouter.PR_ALL_MESSAGES
|
||||
|
||||
self.propagation_transfer_progress = 0.0
|
||||
self.propagation_transfer_max_messages = max_messages
|
||||
if self.outbound_propagation_node != None:
|
||||
self.propagation_transfer_progress = 0.0
|
||||
if self.outbound_propagation_link != None and self.outbound_propagation_link.status == RNS.Link.ACTIVE:
|
||||
self.propagation_transfer_state = LXMRouter.PR_LINK_ESTABLISHED
|
||||
self.outbound_propagation_link.identify(identity)
|
||||
@@ -444,7 +449,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):
|
||||
@@ -463,7 +473,16 @@ class LXMRouter:
|
||||
|
||||
if self.outbound_propagation_link != None and self.outbound_propagation_link.status == RNS.Link.CLOSED:
|
||||
self.outbound_propagation_link = None
|
||||
self.acknowledge_sync_completion()
|
||||
if self.propagation_transfer_state == LXMRouter.PR_COMPLETE:
|
||||
self.acknowledge_sync_completion()
|
||||
elif self.propagation_transfer_state < LXMRouter.PR_LINK_ESTABLISHED:
|
||||
self.acknowledge_sync_completion(failure_state=LXMRouter.PR_LINK_FAILED)
|
||||
elif self.propagation_transfer_state >= LXMRouter.PR_LINK_ESTABLISHED and self.propagation_transfer_state < LXMRouter.PR_COMPLETE:
|
||||
self.acknowledge_sync_completion(failure_state=LXMRouter.PR_TRANSFER_FAILED)
|
||||
else:
|
||||
RNS.log(f"Unknown propagation transfer state on link cleaning: {self.propagation_transfer_state}", RNS.LOG_DEBUG)
|
||||
self.acknowledge_sync_completion()
|
||||
|
||||
RNS.log("Cleaned outbound propagation link", RNS.LOG_DEBUG)
|
||||
|
||||
def clean_transient_id_caches(self):
|
||||
@@ -641,7 +660,7 @@ class LXMRouter:
|
||||
self.request_messages_from_propagation_node(self.wants_download_on_path_available_to, self.propagation_transfer_max_messages)
|
||||
else:
|
||||
RNS.log("Propagation node path request timed out", RNS.LOG_DEBUG)
|
||||
self.acknowledge_sync_completion()
|
||||
self.acknowledge_sync_completion(failure_state=LXMRouter.PR_NO_PATH)
|
||||
|
||||
def identity_allowed(self, identity):
|
||||
if self.auth_required:
|
||||
@@ -804,12 +823,15 @@ class LXMRouter:
|
||||
if self.outbound_propagation_link != None:
|
||||
self.outbound_propagation_link.teardown()
|
||||
|
||||
def acknowledge_sync_completion(self, reset_state=False):
|
||||
def acknowledge_sync_completion(self, reset_state=False, failure_state=None):
|
||||
self.propagation_transfer_last_result = None
|
||||
if reset_state or self.propagation_transfer_state <= LXMRouter.PR_COMPLETE:
|
||||
self.propagation_transfer_state = LXMRouter.PR_IDLE
|
||||
if failure_state == None:
|
||||
self.propagation_transfer_state = LXMRouter.PR_IDLE
|
||||
else:
|
||||
self.propagation_transfer_state = failure_state
|
||||
|
||||
self.propagation_transfer_progress = 0.0
|
||||
self.propagation_transfer_last_result = None
|
||||
self.wants_download_on_path_available_from = None
|
||||
self.wants_download_on_path_available_to = None
|
||||
|
||||
@@ -836,10 +858,15 @@ class LXMRouter:
|
||||
self.pending_outbound.append(lxmessage)
|
||||
self.process_outbound()
|
||||
|
||||
def lxmf_delivery(self, lxmf_data, destination_type = None):
|
||||
def lxmf_delivery(self, lxmf_data, destination_type = None, phy_stats = None):
|
||||
try:
|
||||
message = LXMessage.unpack_from_bytes(lxmf_data)
|
||||
|
||||
if phy_stats != None:
|
||||
if "rssi" in phy_stats: message.rssi = phy_stats["rssi"]
|
||||
if "snr" in phy_stats: message.snr = phy_stats["snr"]
|
||||
if "q" in phy_stats: message.q = phy_stats["q"]
|
||||
|
||||
if destination_type == RNS.Destination.SINGLE:
|
||||
message.transport_encrypted = True
|
||||
message.transport_encryption = LXMessage.ENCRYPTION_DESCRIPTION_EC
|
||||
@@ -879,7 +906,16 @@ class LXMRouter:
|
||||
else:
|
||||
lxmf_data = data
|
||||
|
||||
if self.lxmf_delivery(lxmf_data, packet.destination_type):
|
||||
try:
|
||||
reticulum = RNS.Reticulum.get_instance()
|
||||
if packet.rssi == None: packet.rssi = reticulum.get_packet_rssi(packet.packet_hash)
|
||||
if packet.snr == None: packet.snr = reticulum.get_packet_snr(packet.packet_hash)
|
||||
if packet.q == None: packet.q = reticulum.get_packet_q(packet.packet_hash)
|
||||
except Exception as e:
|
||||
RNS.log("Error while retrieving physical link stats for LXMF delivery packet: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
phy_stats = {"rssi": packet.rssi, "snr": packet.snr, "q": packet.q}
|
||||
if self.lxmf_delivery(lxmf_data, packet.destination_type, phy_stats=phy_stats):
|
||||
packet.prove()
|
||||
|
||||
except Exception as e:
|
||||
@@ -887,6 +923,7 @@ class LXMRouter:
|
||||
RNS.log("The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
|
||||
def delivery_link_established(self, link):
|
||||
link.track_phy_stats(True)
|
||||
link.set_packet_callback(self.delivery_packet)
|
||||
link.set_resource_strategy(RNS.Link.ACCEPT_ALL)
|
||||
link.set_resource_started_callback(self.resource_transfer_began)
|
||||
@@ -901,7 +938,8 @@ class LXMRouter:
|
||||
def delivery_resource_concluded(self, resource):
|
||||
RNS.log("Transfer concluded for LXMF delivery resource "+str(resource), RNS.LOG_DEBUG)
|
||||
if resource.status == RNS.Resource.COMPLETE:
|
||||
self.lxmf_delivery(resource.data.read(), resource.link.type)
|
||||
phy_stats = {"rssi": resource.link.rssi, "snr": resource.link.snr, "q": resource.link.q}
|
||||
self.lxmf_delivery(resource.data.read(), resource.link.type, phy_stats=phy_stats)
|
||||
|
||||
|
||||
### Peer Sync & Propagation ###########################
|
||||
@@ -917,6 +955,7 @@ class LXMRouter:
|
||||
|
||||
peer.peering_timebase = timestamp
|
||||
peer.last_heard = time.time()
|
||||
|
||||
else:
|
||||
peer = LXMPeer(self, destination_hash)
|
||||
peer.alive = True
|
||||
@@ -956,8 +995,25 @@ class LXMRouter:
|
||||
|
||||
peer_pool = []
|
||||
if len(waiting_peers) > 0:
|
||||
RNS.log("Randomly selecting peer to sync from "+str(len(waiting_peers))+" waiting peers.", RNS.LOG_DEBUG)
|
||||
peer_pool = waiting_peers
|
||||
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
|
||||
@@ -1165,7 +1221,7 @@ class LXMRouter:
|
||||
else:
|
||||
RNS.log("Starting outbound processing for "+str(lxmessage)+" to "+RNS.prettyhexrep(lxmessage.get_destination().hash), RNS.LOG_DEBUG)
|
||||
# Outbound handling for opportunistic messages
|
||||
if lxmessage.method == LXMessage.OPPORTUNISTIC:
|
||||
if lxmessage.method == LXMessage.OPPORTUNISTIC:
|
||||
if lxmessage.delivery_attempts <= LXMRouter.MAX_DELIVERY_ATTEMPTS:
|
||||
if not hasattr(lxmessage, "next_delivery_attempt") or time.time() > lxmessage.next_delivery_attempt:
|
||||
lxmessage.delivery_attempts += 1
|
||||
|
||||
+34
-16
@@ -33,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
|
||||
@@ -53,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
|
||||
|
||||
@@ -63,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
|
||||
|
||||
@@ -111,7 +111,6 @@ class LXMessage:
|
||||
|
||||
self.set_title_from_string(title)
|
||||
self.set_content_from_string(content)
|
||||
|
||||
self.set_fields(fields)
|
||||
|
||||
self.payload = None
|
||||
@@ -122,6 +121,9 @@ class LXMessage:
|
||||
self.progress = None
|
||||
self.state = LXMessage.DRAFT
|
||||
self.method = LXMessage.UNKNOWN
|
||||
self.rssi = None
|
||||
self.snr = None
|
||||
self.q = None
|
||||
|
||||
self.propagation_packed = None
|
||||
self.paper_packed = None
|
||||
@@ -161,12 +163,23 @@ class LXMessage:
|
||||
|
||||
def set_fields(self, fields):
|
||||
if isinstance(fields, dict) or fields == None:
|
||||
self.fields = fields
|
||||
self.fields = fields or {}
|
||||
else:
|
||||
raise ValueError("LXMessage property \"fields\" can only be dict or None")
|
||||
|
||||
def get_fields(self):
|
||||
return self.__fields
|
||||
return self.fields
|
||||
|
||||
@property
|
||||
def destination(self):
|
||||
return self.__destination
|
||||
|
||||
@destination.setter
|
||||
def destination(self, destination):
|
||||
self.set_destination(destination)
|
||||
|
||||
def get_destination(self):
|
||||
return self.destination
|
||||
|
||||
def set_destination(self, destination):
|
||||
if self.destination == None:
|
||||
@@ -177,8 +190,16 @@ class LXMessage:
|
||||
else:
|
||||
raise ValueError("Cannot reassign destination on LXMessage")
|
||||
|
||||
def get_destination(self):
|
||||
return self.__destination
|
||||
@property
|
||||
def source(self):
|
||||
return self.__source
|
||||
|
||||
@source.setter
|
||||
def source(self, source):
|
||||
self.set_source(source)
|
||||
|
||||
def get_source(self):
|
||||
return self.source
|
||||
|
||||
def set_source(self, source):
|
||||
if self.source == None:
|
||||
@@ -189,9 +210,6 @@ class LXMessage:
|
||||
else:
|
||||
raise ValueError("Cannot reassign source on LXMessage")
|
||||
|
||||
def get_source(self):
|
||||
return self.__source
|
||||
|
||||
def set_delivery_destination(self, delivery_destination):
|
||||
self.__delivery_destination = delivery_destination
|
||||
|
||||
@@ -487,7 +505,6 @@ class LXMessage:
|
||||
return None
|
||||
|
||||
def as_uri(self, finalise=True):
|
||||
self.determine_transport_encryption()
|
||||
if not self.packed:
|
||||
self.pack()
|
||||
|
||||
@@ -499,6 +516,7 @@ class LXMessage:
|
||||
lxm_uri = LXMessage.URI_SCHEMA+"://"+encoded_bytes.decode("utf-8").replace("=","")
|
||||
|
||||
if finalise:
|
||||
self.determine_transport_encryption()
|
||||
self.__mark_paper_generated()
|
||||
|
||||
return lxm_uri
|
||||
@@ -507,7 +525,6 @@ class LXMessage:
|
||||
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()
|
||||
|
||||
@@ -522,6 +539,7 @@ class LXMessage:
|
||||
data = self.as_uri(finalise=False),
|
||||
)
|
||||
|
||||
self.determine_transport_encryption()
|
||||
self.__mark_paper_generated()
|
||||
|
||||
return qr
|
||||
|
||||
+27
-19
@@ -204,8 +204,6 @@ def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbo
|
||||
global lxmd_config, active_configuration, targetloglevel
|
||||
global message_router, lxmf_destination
|
||||
|
||||
targetloglevel = 3+verbosity-quietness
|
||||
|
||||
if service:
|
||||
targetlogdest = RNS.LOG_FILE
|
||||
targetloglevel = None
|
||||
@@ -234,6 +232,12 @@ def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbo
|
||||
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)
|
||||
@@ -241,15 +245,16 @@ def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbo
|
||||
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()
|
||||
else:
|
||||
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 Reticulum if needed.")
|
||||
time.sleep(1.5)
|
||||
|
||||
|
||||
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)
|
||||
@@ -302,6 +307,10 @@ def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbo
|
||||
# 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)
|
||||
|
||||
@@ -322,9 +331,6 @@ def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbo
|
||||
|
||||
RNS.log("LXMF Propagation Node started on "+RNS.prettyhexrep(message_router.propagation_destination.hash))
|
||||
|
||||
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)
|
||||
|
||||
RNS.log("Started lxmd version {version}".format(version=__version__), RNS.LOG_NOTICE)
|
||||
|
||||
threading.Thread(target=deferred_start_jobs, daemon=True).start()
|
||||
@@ -338,15 +344,17 @@ def jobs():
|
||||
|
||||
while True:
|
||||
try:
|
||||
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 "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 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()
|
||||
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)
|
||||
|
||||
@@ -2,6 +2,7 @@ import os
|
||||
import glob
|
||||
from .LXMessage import LXMessage
|
||||
from .LXMRouter import LXMRouter
|
||||
from .LXMF import *
|
||||
|
||||
from ._version import __version__
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__ = "0.2.9"
|
||||
__version__ = "0.3.9"
|
||||
@@ -8,7 +8,14 @@ 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)
|
||||
|
||||
Community-provided tools and utilities for LXMF include:
|
||||
|
||||
- [LXMF-Bot](https://github.com/randogoth/lxmf-bot)
|
||||
- [LXMF Messageboard](https://github.com/chengtripp/lxmf_messageboard)
|
||||
- [LXMEvent](https://github.com/faragher/LXMEvent)
|
||||
- [RangeMap](https://github.com/faragher/RangeMap)
|
||||
- [LXMF Tools](https://github.com/SebastianObi/LXMF-Tools)
|
||||
|
||||
## Structure
|
||||
|
||||
@@ -29,10 +36,10 @@ LXMF messages are stored in a simple and efficient format, that's easy to parse
|
||||
|
||||
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.
|
||||
@@ -46,7 +53,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.
|
||||
|
||||
@@ -85,11 +92,11 @@ The LXM Router then handles the heavy lifting, such as message packing, encrypti
|
||||
|
||||
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.
|
||||
- If a message is delivered over a Reticulum link (which is the default method), the message will be encrypted with ephemeral AES-128 keys derived with ECDH on Curve25519. This mode offers forward secrecy.
|
||||
|
||||
- If a message is delivered to the Reticulum GROUP destination type, the message will be transported using _AES-128_ encryption.
|
||||
- A message can be delivered opportunistically, embedded in a single Reticulum packet. In this cases the message will be opportunistically routed through the network, and will be encrypted with per-packet AES-128 keys derived with ECDH on Curve25519.
|
||||
|
||||
- If a message is delivered over a Reticulum link (which is the default method), the message will be encrypted with _ephemeral_ keys derived with _ECDH_ on _Curve25519_. This mode offers Perfect Forward Secrecy.
|
||||
- If a message is delivered to the Reticulum GROUP destination type, the message will be encrypted using the symmetric AES-128 key of the GROUP destination.
|
||||
|
||||
## Wire Format & Overhead
|
||||
|
||||
@@ -100,15 +107,19 @@ Assuming the default Reticulum configuration, the binary wire-format is as follo
|
||||
- 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.
|
||||
|
||||
## Code Examples
|
||||
|
||||
Before writing your own programs using LXMF, you need to have a basic understanding of how the [Reticulum](https://reticulum.network) protocol and API works. Please see the [Reticulum Manual](https://reticulum.network/manual/). For a few simple examples of how to send and receive messages with LXMF, please see the [receiver example](./docs/example_receiver.py) and the [sender example](./docs/example_sender.py) included in this repository.
|
||||
|
||||
## Example Paper Message
|
||||
|
||||
You can try out the paper messaging functionality by using the following QR-code. It is a paper message sent to the LXMF address `6b3362bd2c1dbf87b66a85f79a8d8c75`. To be able to decrypt and read the message, you will need to import the following Reticulum Identity to an LXMF messaging app:
|
||||
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.
|
||||
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>
|
||||
|
||||
@@ -120,14 +131,29 @@ On operating systems that allow for registering custom URI-handlers, you can cli
|
||||
|
||||
## 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
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import RNS
|
||||
import LXMF
|
||||
import time
|
||||
|
||||
def delivery_callback(message):
|
||||
time_string = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(message.timestamp))
|
||||
signature_string = "Signature is invalid, reason undetermined"
|
||||
if message.signature_validated:
|
||||
signature_string = "Validated"
|
||||
else:
|
||||
if message.unverified_reason == LXMF.LXMessage.SIGNATURE_INVALID:
|
||||
signature_string = "Invalid signature"
|
||||
if message.unverified_reason == LXMF.LXMessage.SOURCE_UNKNOWN:
|
||||
signature_string = "Cannot verify, source is unknown"
|
||||
|
||||
RNS.log("\t+--- LXMF Delivery ---------------------------------------------")
|
||||
RNS.log("\t| Source hash : "+RNS.prettyhexrep(message.source_hash))
|
||||
RNS.log("\t| Source instance : "+str(message.get_source()))
|
||||
RNS.log("\t| Destination hash : "+RNS.prettyhexrep(message.destination_hash))
|
||||
RNS.log("\t| Destination instance : "+str(message.get_destination()))
|
||||
RNS.log("\t| Transport Encryption : "+str(message.transport_encryption))
|
||||
RNS.log("\t| Timestamp : "+time_string)
|
||||
RNS.log("\t| Title : "+message.title_as_string())
|
||||
RNS.log("\t| Content : "+message.content_as_string())
|
||||
RNS.log("\t| Fields : "+str(message.fields))
|
||||
RNS.log("\t| Message signature : "+signature_string)
|
||||
RNS.log("\t+---------------------------------------------------------------")
|
||||
|
||||
r = RNS.Reticulum()
|
||||
|
||||
router = LXMF.LXMRouter(storagepath="./tmp1")
|
||||
identity = RNS.Identity()
|
||||
my_lxmf_destination = router.register_delivery_identity(identity)
|
||||
router.register_delivery_callback(delivery_callback)
|
||||
|
||||
RNS.log("Ready to receive on: "+RNS.prettyhexrep(my_lxmf_destination.hash))
|
||||
input()
|
||||
@@ -0,0 +1,39 @@
|
||||
import LXMF
|
||||
import RNS
|
||||
import time
|
||||
import random
|
||||
|
||||
random_names = ["Tom", "Delilah", "Nancey", "Williams", "Neomi", "Curtis", "Alexa", "Theodora", "Ted", "Dinorah", "Nicol", "Drusilla", "Annalisa", "Verlene", "Latesha", "Tina", "Mia", "Brock", "Timothy", "Philip", "Willian", "Reyna", "Simona", "Mimi", "Stanford", "Ferne", "Catalina", "Lucie", "Jaye", "Natasha", "Willetta", "Isabel", "Esperanza", "Ciara", "Eusebio", "William", "Elma", "Angelica", "Coreen", "Melani", "Jonathan", "Maryland", "Caroline", "Gregg", "Ora", "Jacqui", "Letty", "Roselle", "Oralee", "Angla"]
|
||||
random_titles = ["Long time", "Hi again", "Re: Hi there", "Test message", "", "", "Something different"]
|
||||
random_msgs = ["If wishes were horses then beggars might fly. Stuff like that. It's enough to drive you crazy.", "'My ident cards were stolen,' Jason said. 'That fivehundred-dollar bill is yours if you can get me to someone who can replace them. If you're going to do it, do it right now; I'm not going to wait.' Wait to be picked up by a pol or a nat, he thought. Caught here in this rundown dingy hotel.", "A six, no matter what the external circumstances, will always prevail. Because that's the way they genetically defined us.", "'Should be there in an hour,' he called back over his shoulder to Chuck. Then he added, in an afterthought, 'Wonder if the computer’s finished its run. It was due about now.'. Chuck didn’t reply, so George swung round in his saddle. He could just see Chuck’s face, a white oval turned toward the sky."]
|
||||
|
||||
def delivery_callback(message):
|
||||
pass
|
||||
|
||||
r = RNS.Reticulum()
|
||||
router = LXMF.LXMRouter(storagepath="./tmp2")
|
||||
router.register_delivery_callback(delivery_callback)
|
||||
ident = RNS.Identity()
|
||||
source = router.register_delivery_identity(ident, display_name=random_names[random.randint(0,len(random_names)-1)])
|
||||
router.announce(source.hash)
|
||||
RNS.log("Source announced")
|
||||
|
||||
print("Recipient: ", end=" ")
|
||||
recipient_hexhash = input()
|
||||
recipient_hash = bytes.fromhex(recipient_hexhash)
|
||||
|
||||
if not RNS.Transport.has_path(recipient_hash):
|
||||
RNS.log("Destination is not yet known. Requesting path and waiting for announce to arrive...")
|
||||
RNS.Transport.request_path(recipient_hash)
|
||||
while not RNS.Transport.has_path(recipient_hash):
|
||||
time.sleep(0.1)
|
||||
|
||||
# Recall the server identity
|
||||
recipient_identity = RNS.Identity.recall(recipient_hash)
|
||||
|
||||
dest = RNS.Destination(recipient_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, "lxmf", "delivery")
|
||||
|
||||
while True:
|
||||
lxm = LXMF.LXMessage(dest, source, random_msgs[random.randint(0,len(random_msgs)-1)], random_titles[random.randint(0,len(random_titles)-1)], desired_method=LXMF.LXMessage.DIRECT)
|
||||
router.handle_outbound(lxm)
|
||||
input()
|
||||
Reference in new issue
Block a user