Explorar o código

initial vpn key check: use cache and save database afterwards

Helge Jung %!s(int64=10) %!d(string=hai) anos
pai
achega
5765dceeaa
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  1. 10 2
      ffstatus/server.py

+ 10 - 2
ffstatus/server.py

@@ -26,6 +26,7 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
 
 		# check all entries for a proper 'remote' entry
 		vpn = self.server.storage.data[self.DATAKEY_VPN]
+		init_vpn_cache = {}
 		for key in vpn:
 			if not isinstance(vpn[key], dict):
 				continue
@@ -38,10 +39,17 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
 					item = vpn[key][mode][gw]
 					if 'remote' in item and not 'remote_raw' in item:
 						item['remote_raw'] = item['remote']
-						resolved = ffstatus.resolve_ipblock(item['remote'])
+						resolved = None
+						if item['remote'] in init_vpn_cache:
+							resolved = init_vpn_cache[item['remote']]
+						else:
+							resolved = ffstatus.resolve_ipblock(item['remote'])
+							init_vpn_cache[item['remote']] = resolved
+							if not resolved is None:
+								self.logger.info('Startup: resolved VPN entry \'{0}\' to net \'{1}\'.'.format(item['remote'], resolved['name']))
 						if not resolved is None:
-							self.logger.info('Startup: resolved VPN entry \'{0}\' to net \'{1}\'.'.format(item['remote'], resolved['name']))
 							item['remote'] = resolved
+		self.server.storage.save()
 
 	def parse_url_pathquery(self):
 		"""Extracts the query parameters from the request path."""