mirror of
https://github.com/markqvist/LXMF
synced 2026-11-23 15:30:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5be161cb1e | ||
|
|
bf924c739c | ||
|
|
044f3d2879 | ||
|
|
312e0a8ded | ||
|
|
575fb7d77d | ||
|
|
2ac2b100ae | ||
|
|
599406ed0f | ||
|
|
55620bf45c | ||
|
|
b53a3ce37d | ||
|
|
764758d185 | ||
|
|
b415a136f3 |
No files matched your search
+38
-5
@@ -12,7 +12,7 @@ FIELD_ICON_APPEARANCE = 0x04
|
||||
FIELD_FILE_ATTACHMENTS = 0x05
|
||||
FIELD_IMAGE = 0x06
|
||||
FIELD_AUDIO = 0x07
|
||||
FIELD_THREAD = 0x08
|
||||
FIELD_THREAD = 0x08 # Bytes, full thread ID hash
|
||||
FIELD_COMMANDS = 0x09
|
||||
FIELD_RESULTS = 0x0A
|
||||
FIELD_GROUP = 0x0B
|
||||
@@ -20,6 +20,16 @@ FIELD_TICKET = 0x0C
|
||||
FIELD_EVENT = 0x0D
|
||||
FIELD_RNR_REFS = 0x0E
|
||||
FIELD_RENDERER = 0x0F
|
||||
FIELD_REPLY_TO = 0x30 # Bytes, full LXMessage.hash
|
||||
FIELD_REPLY_QUOTE = 0x31 # Bytes, quoted content in UTF-8 encoding
|
||||
FIELD_REACTION = 0x40 # Dict, see "Reaction dict indices" below
|
||||
FIELD_COMMENT = 0x41 # Dict, see "Comment dict indices" below
|
||||
FIELD_CONTINUATION = 0x42 # Dict, see "Continuation dict indices" below
|
||||
|
||||
# Unallocated fields between 0x00 and 0x80, both included,
|
||||
# should be considered reserved for future extensibility
|
||||
# For experimental and unstable features, it is recommended
|
||||
# to use fields above 0xFF.
|
||||
|
||||
# For usecases such as including custom data structures,
|
||||
# embedding or encapsulating other data types or protocols
|
||||
@@ -91,6 +101,30 @@ RENDERER_MICRON = 0x01
|
||||
RENDERER_MARKDOWN = 0x02
|
||||
RENDERER_BBCODE = 0x03
|
||||
|
||||
# Clients choose how to handle reaction content, if at all.
|
||||
# While reactions are typically a single unicode emoji or
|
||||
# similar, the exact implementation and sanitization is
|
||||
# left up to the client. When using the FIELD_REACTION
|
||||
# field, the contents is a dict with the following keys:
|
||||
REACTION_TO = 0x00 # Bytes, full LXMessage.hash
|
||||
REACTION_CONTENT = 0x01 # Bytes, the reaction content in UTF-8 encoding
|
||||
|
||||
# Clients choose how to handle messages intended as comments
|
||||
# for other message, if at all. The actual comment content
|
||||
# is carried as the normal LXM content, meaning clients that
|
||||
# do not support comments will display them as normal messages.
|
||||
# When using the FIELD_COMMENT field, the contents is a dict
|
||||
# with the following keys:
|
||||
COMMENT_FOR = 0x00 # Bytes, full LXMessage.hash
|
||||
|
||||
# Clients choose how to handle messages that continue earlier
|
||||
# messages, if at all. The actual continuation content is
|
||||
# carried as the normal LXM content, meaning clients that
|
||||
# do not support continuations will display them as normal.
|
||||
# When using the FIELD_CONTINUATION field, the contents is a
|
||||
# dict with the following keys:
|
||||
CONTINUATION_OF = 0x00 # Bytes, full LXMessage.hash
|
||||
|
||||
# Optional propagation node metadata fields. These
|
||||
# fields may be highly unstable in allocation and
|
||||
# availability until the version 1.0.0 release, so use
|
||||
@@ -135,8 +169,7 @@ def display_name_from_app_data(app_data=None):
|
||||
return None
|
||||
|
||||
# Original announce format
|
||||
else:
|
||||
return app_data.decode("utf-8")
|
||||
else: return app_data.decode("utf-8")
|
||||
|
||||
def stamp_cost_from_app_data(app_data=None):
|
||||
if app_data == None or app_data == b"": return None
|
||||
@@ -185,8 +218,8 @@ def pn_stamp_cost_from_app_data(app_data=None):
|
||||
if pn_announce_data_is_valid(app_data):
|
||||
data = msgpack.unpackb(app_data)
|
||||
return data[5][0]
|
||||
else:
|
||||
return None
|
||||
|
||||
else: return None
|
||||
|
||||
def pn_announce_data_is_valid(data):
|
||||
try:
|
||||
|
||||
+7
-5
@@ -996,7 +996,7 @@ class LXMRouter:
|
||||
stamp_cost = delivery_destination.stamp_cost
|
||||
|
||||
supported_functionality = [SF_COMPRESSION]
|
||||
peer_data = [display_name, stamp_cost]
|
||||
peer_data = [display_name, stamp_cost, supported_functionality]
|
||||
|
||||
return msgpack.packb(peer_data)
|
||||
|
||||
@@ -1735,11 +1735,13 @@ class LXMRouter:
|
||||
def lxmf_delivery(self, lxmf_data, destination_type = None, phy_stats = None, ratchet_id = None, method = None, no_stamp_enforcement=False, allow_duplicate=False):
|
||||
try:
|
||||
message = LXMessage.unpack_from_bytes(lxmf_data)
|
||||
if ratchet_id and not message.ratchet_id:
|
||||
message.ratchet_id = ratchet_id
|
||||
|
||||
if method:
|
||||
message.method = method
|
||||
if message.source_blackholed:
|
||||
RNS.log(f"Dropping LXM from blackholed identity {message.source.identity}", RNS.LOG_DEBUG)
|
||||
return False
|
||||
|
||||
if ratchet_id and not message.ratchet_id: message.ratchet_id = ratchet_id
|
||||
if method: message.method = method
|
||||
|
||||
if message.signature_validated and FIELD_TICKET in message.fields:
|
||||
ticket_entry = message.fields[FIELD_TICKET]
|
||||
|
||||
+24
-16
@@ -8,6 +8,7 @@ import multiprocessing
|
||||
|
||||
import LXMF.LXStamper as LXStamper
|
||||
from .LXMF import APP_NAME, compression_support_from_app_data
|
||||
from threading import Lock
|
||||
|
||||
|
||||
class LXMessage:
|
||||
@@ -168,6 +169,7 @@ class LXMessage:
|
||||
self.paper_packed = None
|
||||
|
||||
self.incoming = False
|
||||
self.source_blackholed = False
|
||||
self.signature_validated = False
|
||||
self.unverified_reason = None
|
||||
self.ratchet_id = None
|
||||
@@ -183,6 +185,7 @@ class LXMessage:
|
||||
self.__delivery_destination = None
|
||||
self.__delivery_callback = None
|
||||
self.__pn_encrypted_data = None
|
||||
self.__persist_lock = Lock()
|
||||
self.failed_callback = None
|
||||
|
||||
self.deferred_stamp_generating = False
|
||||
@@ -671,25 +674,26 @@ class LXMessage:
|
||||
def write_to_directory(self, directory_path):
|
||||
file_name = RNS.hexrep(self.hash, delimit=False)
|
||||
file_path = directory_path+"/"+file_name
|
||||
tmp_path = file_path+".tmp."+str(os.getpid() or time.time())
|
||||
tmp_path = file_path+".tmp."+str(os.getpid() or time.time())+"."+RNS.hexrep(os.urandom(8), delimit=False)
|
||||
|
||||
try:
|
||||
with open(tmp_path, "wb") as file:
|
||||
file.write(self.packed_container())
|
||||
file.flush()
|
||||
try: os.fsync(file.fileno())
|
||||
except OSError: pass
|
||||
|
||||
os.replace(tmp_path, file_path)
|
||||
return file_path
|
||||
|
||||
except Exception as e:
|
||||
with self.__persist_lock:
|
||||
try:
|
||||
if os.path.exists(tmp_path): os.unlink(tmp_path)
|
||||
except Exception: pass
|
||||
with open(tmp_path, "wb") as file:
|
||||
file.write(self.packed_container())
|
||||
file.flush()
|
||||
try: os.fsync(file.fileno())
|
||||
except OSError as e: RNS.log(f"Error while waiting for persist fsync for {self}: {e}", RNS.LOG_WARNING)
|
||||
|
||||
RNS.log("Error while writing LXMF message to file \""+str(file_path)+"\". The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||
return None
|
||||
os.replace(tmp_path, file_path)
|
||||
return file_path
|
||||
|
||||
except Exception as e:
|
||||
try:
|
||||
if os.path.exists(tmp_path): os.unlink(tmp_path)
|
||||
except Exception as e: RNS.log(f"Error while cleaning temporary file {tmp_path} for {self}: {e}", RNS.LOG_ERROR)
|
||||
|
||||
RNS.log(f"Error while writing LXMF message to file \"{file_path}\". The contained exception was: {e}", RNS.LOG_ERROR)
|
||||
return None
|
||||
|
||||
def as_uri(self, finalise=True):
|
||||
if not self.packed:
|
||||
@@ -796,6 +800,10 @@ class LXMessage:
|
||||
message.set_title_from_bytes(title_bytes)
|
||||
message.set_content_from_bytes(content_bytes)
|
||||
|
||||
try:
|
||||
if source_identity != None: message.source_blackholed = RNS.Reticulum.get_instance().is_blackholed(source_identity)
|
||||
except Exception as e: RNS.log(f"Could not determine message source blackhole status: {e}", RNS.LOG_WARNING)
|
||||
|
||||
try:
|
||||
if source:
|
||||
if source.identity.validate(signature, signed_part):
|
||||
|
||||
@@ -307,7 +307,7 @@ def program_setup(configdir = None, rnsconfigdir = None, run_pn = False, on_inbo
|
||||
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"):
|
||||
elif os.path.isdir(RNS.Reticulum.userdir+"/.config/lxmd") and os.path.isfile(RNS.Reticulum.userdir+"/.config/lxmd/config"):
|
||||
configdir = RNS.Reticulum.userdir+"/.config/lxmd"
|
||||
else:
|
||||
configdir = RNS.Reticulum.userdir+"/.lxmd"
|
||||
@@ -822,7 +822,7 @@ def _remote_init(configdir=None, rnsconfigdir=None, verbosity=0, quietness=0, id
|
||||
if identity_path == None:
|
||||
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"
|
||||
elif os.path.isdir(RNS.Reticulum.userdir+"/.config/lxmd") and os.path.isfile(RNS.Reticulum.userdir+"/.config/lxmd/config"): configdir = RNS.Reticulum.userdir+"/.config/lxmd"
|
||||
else: configdir = RNS.Reticulum.userdir+"/.lxmd"
|
||||
|
||||
configpath = configdir+"/config"
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__ = "0.9.9"
|
||||
__version__ = "1.0.0"
|
||||
@@ -27,4 +27,4 @@ release: remove_symlinks build_wheel build_spkg create_symlinks
|
||||
|
||||
upload:
|
||||
@echo Uploading to PyPi...
|
||||
twine upload dist/*
|
||||
twine upload dist/*.whl dist/*.tar.gz
|
||||
Reference in new issue
Block a user