mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-26 23:40: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:
|
if not destination_hash in Identity.known_destinations:
|
||||||
Identity.known_destinations[destination_hash] = storage_known_destinations[destination_hash]
|
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")
|
file = open(RNS.Reticulum.storagepath+"/known_destinations","wb")
|
||||||
umsgpack.dump(Identity.known_destinations, file)
|
umsgpack.dump(Identity.known_destinations, file)
|
||||||
file.close()
|
file.close()
|
||||||
@ -246,9 +246,14 @@ class Identity:
|
|||||||
RNS.log("Error occurred while validating announce. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
RNS.log("Error occurred while validating announce. The contained exception was: "+str(e), RNS.LOG_ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def persist_data():
|
||||||
|
if not RNS.Transport.owner.is_connected_to_shared_instance:
|
||||||
|
Identity.save_known_destinations()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
Identity.save_known_destinations()
|
Identity.persist_data()
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -119,25 +119,27 @@ class Reticulum:
|
|||||||
# Length of truncated hashes in bits.
|
# Length of truncated hashes in bits.
|
||||||
TRUNCATED_HASHLENGTH = 128
|
TRUNCATED_HASHLENGTH = 128
|
||||||
|
|
||||||
HEADER_MINSIZE = 2+1+(TRUNCATED_HASHLENGTH//8)*1
|
HEADER_MINSIZE = 2+1+(TRUNCATED_HASHLENGTH//8)*1
|
||||||
HEADER_MAXSIZE = 2+1+(TRUNCATED_HASHLENGTH//8)*2
|
HEADER_MAXSIZE = 2+1+(TRUNCATED_HASHLENGTH//8)*2
|
||||||
IFAC_MIN_SIZE = 1
|
IFAC_MIN_SIZE = 1
|
||||||
IFAC_SALT = bytes.fromhex("adf54d882c9a9b80771eb4995d702d4a3e733391b2a0f53f416d9f907e55cff8")
|
IFAC_SALT = bytes.fromhex("adf54d882c9a9b80771eb4995d702d4a3e733391b2a0f53f416d9f907e55cff8")
|
||||||
|
|
||||||
MDU = MTU - HEADER_MAXSIZE - IFAC_MIN_SIZE
|
MDU = MTU - HEADER_MAXSIZE - IFAC_MIN_SIZE
|
||||||
|
|
||||||
RESOURCE_CACHE = 24*60*60
|
RESOURCE_CACHE = 24*60*60
|
||||||
JOB_INTERVAL = 15*60
|
JOB_INTERVAL = 5*60
|
||||||
|
CLEAN_INTERVAL = 15*60
|
||||||
|
PERSIST_INTERVAL = 60*60*12
|
||||||
|
|
||||||
router = None
|
router = None
|
||||||
config = None
|
config = None
|
||||||
|
|
||||||
# The default configuration path will be expanded to a directory
|
# The default configuration path will be expanded to a directory
|
||||||
# named ".reticulum" inside the current users home directory
|
# named ".reticulum" inside the current users home directory
|
||||||
configdir = os.path.expanduser("~")+"/.reticulum"
|
configdir = os.path.expanduser("~")+"/.reticulum"
|
||||||
configpath = ""
|
configpath = ""
|
||||||
storagepath = ""
|
storagepath = ""
|
||||||
cachepath = ""
|
cachepath = ""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
@ -206,6 +208,8 @@ class Reticulum:
|
|||||||
self.is_connected_to_shared_instance = False
|
self.is_connected_to_shared_instance = False
|
||||||
self.is_standalone_instance = False
|
self.is_standalone_instance = False
|
||||||
self.jobs_thread = None
|
self.jobs_thread = None
|
||||||
|
self.last_data_persist = time.time()
|
||||||
|
self.last_cache_clean = 0
|
||||||
|
|
||||||
if not os.path.isdir(Reticulum.storagepath):
|
if not os.path.isdir(Reticulum.storagepath):
|
||||||
os.makedirs(Reticulum.storagepath)
|
os.makedirs(Reticulum.storagepath)
|
||||||
@ -230,7 +234,6 @@ class Reticulum:
|
|||||||
RNS.log("Could not load config file, creating default configuration file...")
|
RNS.log("Could not load config file, creating default configuration file...")
|
||||||
self.__create_default_config()
|
self.__create_default_config()
|
||||||
RNS.log("Default config file created. Make any necessary changes in "+Reticulum.configdir+"/config and restart Reticulum if needed.")
|
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)
|
time.sleep(1.5)
|
||||||
|
|
||||||
self.__apply_config()
|
self.__apply_config()
|
||||||
@ -261,8 +264,15 @@ class Reticulum:
|
|||||||
|
|
||||||
def __jobs(self):
|
def __jobs(self):
|
||||||
while True:
|
while True:
|
||||||
# Clean caches
|
now = time.time()
|
||||||
self.__clean_caches()
|
|
||||||
|
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)
|
time.sleep(Reticulum.JOB_INTERVAL)
|
||||||
|
|
||||||
@ -928,7 +938,9 @@ class Reticulum:
|
|||||||
|
|
||||||
RNS.Transport.interfaces.append(interface)
|
RNS.Transport.interfaces.append(interface)
|
||||||
|
|
||||||
|
def __persist_data(self):
|
||||||
|
RNS.Transport.persist_data()
|
||||||
|
RNS.Identity.persist_data()
|
||||||
|
|
||||||
def __clean_caches(self):
|
def __clean_caches(self):
|
||||||
RNS.log("Cleaning resource and packet caches...", RNS.LOG_EXTREME)
|
RNS.log("Cleaning resource and packet caches...", RNS.LOG_EXTREME)
|
||||||
|
@ -2240,9 +2240,13 @@ class Transport:
|
|||||||
|
|
||||||
Transport.saving_tunnel_table = False
|
Transport.saving_tunnel_table = False
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exit_handler():
|
def persist_data():
|
||||||
Transport.save_packet_hashlist()
|
Transport.save_packet_hashlist()
|
||||||
Transport.save_path_table()
|
Transport.save_path_table()
|
||||||
Transport.save_tunnel_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