Automatically drop LXMs from blackholed identities
This commit is contained in:
parent
599406ed0f
commit
2ac2b100ae
2 changed files with 14 additions and 7 deletions
|
|
@ -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):
|
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:
|
try:
|
||||||
message = LXMessage.unpack_from_bytes(lxmf_data)
|
message = LXMessage.unpack_from_bytes(lxmf_data)
|
||||||
if ratchet_id and not message.ratchet_id:
|
|
||||||
message.ratchet_id = ratchet_id
|
|
||||||
|
|
||||||
if method:
|
if message.source_blackholed:
|
||||||
message.method = method
|
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:
|
if message.signature_validated and FIELD_TICKET in message.fields:
|
||||||
ticket_entry = message.fields[FIELD_TICKET]
|
ticket_entry = message.fields[FIELD_TICKET]
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,7 @@ class LXMessage:
|
||||||
self.paper_packed = None
|
self.paper_packed = None
|
||||||
|
|
||||||
self.incoming = False
|
self.incoming = False
|
||||||
|
self.source_blackholed = False
|
||||||
self.signature_validated = False
|
self.signature_validated = False
|
||||||
self.unverified_reason = None
|
self.unverified_reason = None
|
||||||
self.ratchet_id = None
|
self.ratchet_id = None
|
||||||
|
|
@ -678,7 +679,7 @@ class LXMessage:
|
||||||
file.write(self.packed_container())
|
file.write(self.packed_container())
|
||||||
file.flush()
|
file.flush()
|
||||||
try: os.fsync(file.fileno())
|
try: os.fsync(file.fileno())
|
||||||
except OSError: pass
|
except OSError as e: RNS.log(f"Error while waiting for persist fsync for {self}: {e}", RNS.LOG_WARNING)
|
||||||
|
|
||||||
os.replace(tmp_path, file_path)
|
os.replace(tmp_path, file_path)
|
||||||
return file_path
|
return file_path
|
||||||
|
|
@ -686,9 +687,9 @@ class LXMessage:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
try:
|
try:
|
||||||
if os.path.exists(tmp_path): os.unlink(tmp_path)
|
if os.path.exists(tmp_path): os.unlink(tmp_path)
|
||||||
except Exception: pass
|
except Exception as e: RNS.log(f"Error while cleaning temporary file {tmp_path} for {self}: {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)
|
RNS.log(f"Error while writing LXMF message to file \"{file_path}\". The contained exception was: {e}", RNS.LOG_ERROR)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def as_uri(self, finalise=True):
|
def as_uri(self, finalise=True):
|
||||||
|
|
@ -796,6 +797,10 @@ class LXMessage:
|
||||||
message.set_title_from_bytes(title_bytes)
|
message.set_title_from_bytes(title_bytes)
|
||||||
message.set_content_from_bytes(content_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:
|
try:
|
||||||
if source:
|
if source:
|
||||||
if source.identity.validate(signature, signed_part):
|
if source.identity.validate(signature, signed_part):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue