Validate propagation node data before logging it

This commit is contained in:
Mark Qvist 2024-11-17 11:43:03 +01:00
parent c14699151d
commit 46450098b4

View File

@ -10,6 +10,7 @@ import shlex
import RNS.vendor.umsgpack as msgpack
import RNS.Interfaces.Interface as Interface
from LXMF import pn_announce_data_is_valid
import multiprocessing.connection
@ -46,6 +47,7 @@ class PropagationNodeDetector():
def received_announce(self, destination_hash, announced_identity, app_data):
try:
if app_data != None and len(app_data) > 0:
if pn_announce_data_is_valid(app_data):
unpacked = msgpack.unpackb(app_data)
node_active = unpacked[0]
emitted = unpacked[1]
@ -62,7 +64,7 @@ class PropagationNodeDetector():
pass
RNS.log("Detected active propagation node "+RNS.prettyhexrep(destination_hash)+" emission "+str(age)+" seconds ago, "+str(hops)+" hops away")
self.owner.log_announce(destination_hash, RNS.prettyhexrep(destination_hash).encode("utf-8"), dest_type=PropagationNodeDetector.aspect_filter)
self.owner.log_announce(destination_hash, app_data, dest_type=PropagationNodeDetector.aspect_filter)
if self.owner.config["lxmf_propagation_node"] == None:
if self.owner.active_propagation_node == None:
@ -76,6 +78,12 @@ class PropagationNodeDetector():
else:
pass
else:
RNS.log(f"Received malformed propagation node announce from {RNS.prettyhexrep(destination_hash)} with data: {app_data}", RNS.LOG_DEBUG)
else:
RNS.log(f"Received malformed propagation node announce from {RNS.prettyhexrep(destination_hash)} with data: {app_data}", RNS.LOG_DEBUG)
except Exception as e:
RNS.log("Error while processing received propagation node announce: "+str(e))
@ -910,6 +918,7 @@ class SidebandCore():
try:
if app_data == None:
app_data = b""
if type(app_data) != bytes:
app_data = msgpack.packb([app_data, stamp_cost])
RNS.log("Received "+str(dest_type)+" announce for "+RNS.prettyhexrep(dest)+" with data: "+str(app_data), RNS.LOG_DEBUG)
self._db_save_announce(dest, app_data, dest_type)