mirror of
https://github.com/markqvist/Reticulum.git
synced 2024-11-05 05:40:14 +00:00
Improved cache handling
This commit is contained in:
parent
5e072affe4
commit
8cff18f8ce
@ -135,8 +135,14 @@ class Identity:
|
|||||||
if os.path.isfile(RNS.Reticulum.storagepath+"/known_destinations"):
|
if os.path.isfile(RNS.Reticulum.storagepath+"/known_destinations"):
|
||||||
try:
|
try:
|
||||||
file = open(RNS.Reticulum.storagepath+"/known_destinations","rb")
|
file = open(RNS.Reticulum.storagepath+"/known_destinations","rb")
|
||||||
Identity.known_destinations = umsgpack.load(file)
|
loaded_known_destinations = umsgpack.load(file)
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
|
Identity.known_destinations = {}
|
||||||
|
for known_destination in loaded_known_destinations:
|
||||||
|
if len(known_destination) == RNS.Reticulum.TRUNCATED_HASHLENGTH//8:
|
||||||
|
Identity.known_destinations[known_destination] = loaded_known_destinations[known_destination]
|
||||||
|
|
||||||
RNS.log("Loaded "+str(len(Identity.known_destinations))+" known destination from storage", RNS.LOG_VERBOSE)
|
RNS.log("Loaded "+str(len(Identity.known_destinations))+" known destination from storage", RNS.LOG_VERBOSE)
|
||||||
except:
|
except:
|
||||||
RNS.log("Error loading known destinations from disk, file will be recreated on exit", RNS.LOG_ERROR)
|
RNS.log("Error loading known destinations from disk, file will be recreated on exit", RNS.LOG_ERROR)
|
||||||
|
@ -126,7 +126,7 @@ class Reticulum:
|
|||||||
|
|
||||||
MDU = MTU - HEADER_MAXSIZE - IFAC_MIN_SIZE
|
MDU = MTU - HEADER_MAXSIZE - IFAC_MIN_SIZE
|
||||||
|
|
||||||
CACHE_TIME = 24*60*60
|
RESOURCE_CACHE = 24*60*60
|
||||||
JOB_INTERVAL = 15*60
|
JOB_INTERVAL = 15*60
|
||||||
|
|
||||||
router = None
|
router = None
|
||||||
@ -893,7 +893,7 @@ class Reticulum:
|
|||||||
filepath = self.resourcepath + "/" + filename
|
filepath = self.resourcepath + "/" + filename
|
||||||
mtime = os.path.getmtime(filepath)
|
mtime = os.path.getmtime(filepath)
|
||||||
age = now - mtime
|
age = now - mtime
|
||||||
if age > Reticulum.CACHE_TIME:
|
if age > Reticulum.RESOURCE_CACHE:
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -906,7 +906,7 @@ class Reticulum:
|
|||||||
filepath = self.cachepath + "/" + filename
|
filepath = self.cachepath + "/" + filename
|
||||||
mtime = os.path.getmtime(filepath)
|
mtime = os.path.getmtime(filepath)
|
||||||
age = now - mtime
|
age = now - mtime
|
||||||
if age > Reticulum.CACHE_TIME:
|
if age > RNS.Transport.DESTINATION_TIMEOUT:
|
||||||
os.unlink(filepath)
|
os.unlink(filepath)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
@ -68,7 +68,7 @@ class Transport:
|
|||||||
PATH_REQUEST_RW = 2 # Path request random window
|
PATH_REQUEST_RW = 2 # Path request random window
|
||||||
|
|
||||||
LINK_TIMEOUT = RNS.Link.STALE_TIME * 1.25
|
LINK_TIMEOUT = RNS.Link.STALE_TIME * 1.25
|
||||||
REVERSE_TIMEOUT = 30*60 # Reverse table entries are removed after max 30 minutes
|
REVERSE_TIMEOUT = 30*60 # Reverse table entries are removed after 30 minutes
|
||||||
DESTINATION_TIMEOUT = 60*60*24*7 # Destination table entries are removed if unused for one week
|
DESTINATION_TIMEOUT = 60*60*24*7 # Destination table entries are removed if unused for one week
|
||||||
MAX_RECEIPTS = 1024 # Maximum number of receipts to keep track of
|
MAX_RECEIPTS = 1024 # Maximum number of receipts to keep track of
|
||||||
MAX_RATE_TIMESTAMPS = 16 # Maximum number of announce timestamps to keep per destination
|
MAX_RATE_TIMESTAMPS = 16 # Maximum number of announce timestamps to keep per destination
|
||||||
@ -181,29 +181,31 @@ class Transport:
|
|||||||
|
|
||||||
for serialised_entry in serialised_destinations:
|
for serialised_entry in serialised_destinations:
|
||||||
destination_hash = serialised_entry[0]
|
destination_hash = serialised_entry[0]
|
||||||
timestamp = serialised_entry[1]
|
|
||||||
received_from = serialised_entry[2]
|
|
||||||
hops = serialised_entry[3]
|
|
||||||
expires = serialised_entry[4]
|
|
||||||
random_blobs = serialised_entry[5]
|
|
||||||
receiving_interface = Transport.find_interface_from_hash(serialised_entry[6])
|
|
||||||
announce_packet = Transport.get_cached_packet(serialised_entry[7])
|
|
||||||
|
|
||||||
if announce_packet != None and receiving_interface != None:
|
if len(destination_hash) == RNS.Reticulum.TRUNCATED_HASHLENGTH//8:
|
||||||
announce_packet.unpack()
|
timestamp = serialised_entry[1]
|
||||||
# We increase the hops, since reading a packet
|
received_from = serialised_entry[2]
|
||||||
# from cache is equivalent to receiving it again
|
hops = serialised_entry[3]
|
||||||
# over an interface. It is cached with it's non-
|
expires = serialised_entry[4]
|
||||||
# increased hop-count.
|
random_blobs = serialised_entry[5]
|
||||||
announce_packet.hops += 1
|
receiving_interface = Transport.find_interface_from_hash(serialised_entry[6])
|
||||||
Transport.destination_table[destination_hash] = [timestamp, received_from, hops, expires, random_blobs, receiving_interface, announce_packet]
|
announce_packet = Transport.get_cached_packet(serialised_entry[7])
|
||||||
RNS.log("Loaded path table entry for "+RNS.prettyhexrep(destination_hash)+" from storage", RNS.LOG_DEBUG)
|
|
||||||
else:
|
if announce_packet != None and receiving_interface != None:
|
||||||
RNS.log("Could not reconstruct path table entry from storage for "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
|
announce_packet.unpack()
|
||||||
if announce_packet == None:
|
# We increase the hops, since reading a packet
|
||||||
RNS.log("The announce packet could not be loaded from cache", RNS.LOG_DEBUG)
|
# from cache is equivalent to receiving it again
|
||||||
if receiving_interface == None:
|
# over an interface. It is cached with it's non-
|
||||||
RNS.log("The interface is no longer available", RNS.LOG_DEBUG)
|
# increased hop-count.
|
||||||
|
announce_packet.hops += 1
|
||||||
|
Transport.destination_table[destination_hash] = [timestamp, received_from, hops, expires, random_blobs, receiving_interface, announce_packet]
|
||||||
|
RNS.log("Loaded path table entry for "+RNS.prettyhexrep(destination_hash)+" from storage", RNS.LOG_DEBUG)
|
||||||
|
else:
|
||||||
|
RNS.log("Could not reconstruct path table entry from storage for "+RNS.prettyhexrep(destination_hash), RNS.LOG_DEBUG)
|
||||||
|
if announce_packet == None:
|
||||||
|
RNS.log("The announce packet could not be loaded from cache", RNS.LOG_DEBUG)
|
||||||
|
if receiving_interface == None:
|
||||||
|
RNS.log("The interface is no longer available", RNS.LOG_DEBUG)
|
||||||
|
|
||||||
if len(Transport.destination_table) == 1:
|
if len(Transport.destination_table) == 1:
|
||||||
specifier = "entry"
|
specifier = "entry"
|
||||||
|
Loading…
Reference in New Issue
Block a user