소스 검색

initial vpn key check: use cache and save database afterwards

Helge Jung 10 년 전
부모
커밋
5765dceeaa
1개의 변경된 파일10개의 추가작업 그리고 2개의 파일을 삭제
  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."""