From b70e259490f8030931924cc9ccf6cb3708b06746 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Wed, 17 Jan 2018 19:34:45 +0100 Subject: [feat] implement vpn status watchdog --- src/leap/bitmask/vpn/service.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/leap/bitmask/vpn/service.py b/src/leap/bitmask/vpn/service.py index 609d70ee..6f182fcc 100644 --- a/src/leap/bitmask/vpn/service.py +++ b/src/leap/bitmask/vpn/service.py @@ -23,6 +23,7 @@ import json import os from twisted.internet import defer +from twisted.internet.task import LoopingCall from twisted.logger import Logger from leap.bitmask.hooks import HookableService @@ -39,6 +40,10 @@ from leap.bitmask.vpn._checks import ( from leap.bitmask.vpn import privilege, helpers from leap.common.config import get_path_prefix from leap.common.files import check_and_fix_urw_only +from leap.common.events import catalog, emit_async + + +WATCHDOG_PERIOD = 30 # in seconds class ImproperlyConfigured(Exception): @@ -89,6 +94,8 @@ class VPNService(HookableService): if helpers.check() and self._firewall.is_up(): self._firewall.stop() + self.watchdog = LoopingCall(self.push_status) + def startService(self): # TODO trigger a check for validity of the certificates, # and schedule a re-download if needed. @@ -144,6 +151,7 @@ class VPNService(HookableService): else: data = {'result': 'failed', 'error': '%r' % result} + self.watchdog.start(WATCHDOG_PERIOD) defer.returnValue(data) def stop_vpn(self): @@ -159,8 +167,17 @@ class VPNService(HookableService): if not vpn_ok: raise Exception("Error stopping VPN") + self.watchdog.stop() return {'result': 'vpn stopped'} + def push_status(self): + try: + statusdict = self.do_status() + status = statusdict.get('status').upper() + emit_async(catalog.VPN_STATUS_CHANGED, status) + except ValueError: + pass + def do_status(self): # TODO - add the current gateway and CC to the status childrenStatus = { -- cgit v1.2.3