mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-22 21:50:18 +00:00
Added periodic data persistence for shared and standalone instances
This commit is contained in:
parent
9775893840
commit
75e32af1c5
@ -139,7 +139,7 @@ class Identity:
|
||||
if not destination_hash in Identity.known_destinations:
|
||||
Identity.known_destinations[destination_hash] = storage_known_destinations[destination_hash]
|
||||
|
||||
RNS.log("Saving known destinations to storage...", RNS.LOG_VERBOSE)
|
||||
RNS.log("Saving "+str(len(Identity.known_destinations))+" known destinations to storage...", RNS.LOG_VERBOSE)
|
||||
file = open(RNS.Reticulum.storagepath+"/known_destinations","wb")
|
||||
umsgpack.dump(Identity.known_destinations, file)
|
||||
file.close()
|
||||
@ -247,9 +247,14 @@ class Identity:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
def persist_data():
|
||||
if not RNS.Transport.owner.is_connected_to_shared_instance:
|
||||
Identity.save_known_destinations()
|
||||
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
Identity.persist_data()
|
||||
|
||||
|
||||
@staticmethod
|
||||
def from_bytes(prv_bytes):
|
||||
|
@ -127,7 +127,9 @@ class Reticulum:
|
||||
MDU = MTU - HEADER_MAXSIZE - IFAC_MIN_SIZE
|
||||
|
||||
RESOURCE_CACHE = 24*60*60
|
||||
JOB_INTERVAL = 15*60
|
||||
JOB_INTERVAL = 5*60
|
||||
CLEAN_INTERVAL = 15*60
|
||||
PERSIST_INTERVAL = 60*60*12
|
||||
|
||||
router = None
|
||||
config = None
|
||||
@ -206,6 +208,8 @@ class Reticulum:
|
||||
self.is_connected_to_shared_instance = False
|
||||
self.is_standalone_instance = False
|
||||
self.jobs_thread = None
|
||||
self.last_data_persist = time.time()
|
||||
self.last_cache_clean = 0
|
||||
|
||||
if not os.path.isdir(Reticulum.storagepath):
|
||||
os.makedirs(Reticulum.storagepath)
|
||||
@ -230,7 +234,6 @@ class Reticulum:
|
||||
RNS.log("Could not load config file, creating default configuration file...")
|
||||
self.__create_default_config()
|
||||
RNS.log("Default config file created. Make any necessary changes in "+Reticulum.configdir+"/config and restart Reticulum if needed.")
|
||||
import time
|
||||
time.sleep(1.5)
|
||||
|
||||
self.__apply_config()
|
||||
@ -261,8 +264,15 @@ class Reticulum:
|
||||
|
||||
def __jobs(self):
|
||||
while True:
|
||||
# Clean caches
|
||||
now = time.time()
|
||||
|
||||
if now > self.last_cache_clean+Reticulum.CLEAN_INTERVAL:
|
||||
self.__clean_caches()
|
||||
self.last_cache_clean = time.time()
|
||||
|
||||
if now > self.last_data_persist+Reticulum.PERSIST_INTERVAL:
|
||||
self.__persist_data()
|
||||
self.last_data_persist = time.time()
|
||||
|
||||
time.sleep(Reticulum.JOB_INTERVAL)
|
||||
|
||||
@ -928,7 +938,9 @@ class Reticulum:
|
||||
|
||||
RNS.Transport.interfaces.append(interface)
|
||||
|
||||
|
||||
def __persist_data(self):
|
||||
RNS.Transport.persist_data()
|
||||
RNS.Identity.persist_data()
|
||||
|
||||
def __clean_caches(self):
|
||||
RNS.log("Cleaning resource and packet caches...", RNS.LOG_EXTREME)
|
||||
|
@ -2240,9 +2240,13 @@ class Transport:
|
||||
|
||||
Transport.saving_tunnel_table = False
|
||||
|
||||
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
def persist_data():
|
||||
Transport.save_packet_hashlist()
|
||||
Transport.save_path_table()
|
||||
Transport.save_tunnel_table()
|
||||
|
||||
@staticmethod
|
||||
def exit_handler():
|
||||
if not Transport.owner.is_connected_to_shared_instance:
|
||||
Transport.persist_data()
|
Loading…
Reference in New Issue
Block a user