Updated storage configuration

This commit is contained in:
Mark Qvist 2021-10-08 08:51:59 +02:00
parent 156109bf0b
commit 92b4aaaaee

View File

@ -771,7 +771,7 @@ class LXMRouter:
PR_ALL_MESSAGES = 0x00 PR_ALL_MESSAGES = 0x00
def __init__(self, identity = None, autopeer = AUTOPEER, autopeer_maxdepth = AUTOPEER_MAXDEPTH): def __init__(self, identity = None, storagepath = None, autopeer = AUTOPEER, autopeer_maxdepth = AUTOPEER_MAXDEPTH):
random.seed(os.urandom(10)) random.seed(os.urandom(10))
self.pending_inbound = [] self.pending_inbound = []
@ -786,6 +786,11 @@ class LXMRouter:
self.propagation_node = False self.propagation_node = False
if storagepath == None:
raise ValueError("LXMF cannot be initialised without a storage path")
else:
self.storagepath = storagepath+"/lxmf"
self.outbound_propagation_node = None self.outbound_propagation_node = None
self.outbound_propagation_link = None self.outbound_propagation_link = None
@ -815,6 +820,16 @@ class LXMRouter:
self.__delivery_callback = None self.__delivery_callback = None
try:
if os.path.isfile(self.storagepath+"/local_deliveries"):
locally_delivered_file = open(self.storagepath+"/local_deliveries", "rb")
data = locally_delivered_file.read()
self.locally_delivered_transient_ids = msgpack.unpackb(data)
locally_delivered_file.close()
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)
atexit.register(self.exit_handler) atexit.register(self.exit_handler)
job_thread = threading.Thread(target=self.jobloop) job_thread = threading.Thread(target=self.jobloop)
@ -838,6 +853,17 @@ class LXMRouter:
except Exception as e: except Exception as e:
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)
try:
if not os.path.isdir(self.storagepath):
os.makedirs(self.storagepath)
locally_delivered_file = open(self.storagepath+"/local_deliveries", "wb")
locally_delivered_file.write(msgpack.packb(self.locally_delivered_transient_ids))
locally_delivered_file.close()
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)
def register_delivery_identity(self, identity, display_name = None): 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, "lxmf", "delivery")
@ -1080,9 +1106,8 @@ class LXMRouter:
self.lxmf_delivery(resource.data.read(), resource.link.type) self.lxmf_delivery(resource.data.read(), resource.link.type)
def enable_propagation(self, storagepath): def enable_propagation(self):
try: try:
self.storagepath = storagepath+"/lxmf"
self.messagepath = self.storagepath+"/messagestore" self.messagepath = self.storagepath+"/messagestore"
if not os.path.isdir(self.storagepath): if not os.path.isdir(self.storagepath):