Browse Source

initial vpn key check: use cache and save database afterwards

Helge Jung 10 years ago
parent
commit
5765dceeaa
1 changed files with 10 additions and 2 deletions
  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."""