diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2017-02-06 14:26:14 +0100 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2017-02-23 00:40:39 +0100 |
commit | 1ba66d113ae0e3ce1651709c812426a3453d94d2 (patch) | |
tree | 49170c4e5871f5937cdd99d9e020d1c074c261f7 /src/leap/bitmask/vpn/_control.py | |
parent | 7f07ffa13eaa51419af6f019bf9b36b298274485 (diff) |
[feature] hard restarts upon ping-restart received
Diffstat (limited to 'src/leap/bitmask/vpn/_control.py')
-rw-r--r-- | src/leap/bitmask/vpn/_control.py | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/leap/bitmask/vpn/_control.py b/src/leap/bitmask/vpn/_control.py index 31a1216..49d7ace 100644 --- a/src/leap/bitmask/vpn/_control.py +++ b/src/leap/bitmask/vpn/_control.py @@ -28,38 +28,34 @@ class VPNControl(object): """ TERMINATE_MAXTRIES = 10 TERMINATE_WAIT = 1 # secs + RESTART_WAIT = 2 # secs OPENVPN_VERB = "openvpn_verb" - def __init__(self, **kwargs): - # TODO what the fuck this is doing that is different from - # the manager? + def __init__(self, remotes, eipconfig, + providerconfig, socket_host, socket_port): self._vpnproc = None self._pollers = [] - # self._openvpn_verb = flags.OPENVPN_VERBOSITY self._openvpn_verb = None self._user_stopped = False - self._remotes = kwargs['remotes'] - def start(self, *args, **kwargs): - """ - Starts the openvpn subprocess. - - :param args: args to be passed to the VPNProcess - :type args: tuple + self._remotes = remotes + self._eipconfig = eipconfig + self._providerconfig = providerconfig + self._host = socket_host + self._port = socket_port - :param kwargs: kwargs to be passed to the VPNProcess - :type kwargs: dict - """ + def start(self): logger.debug('VPN: start') + self._user_stopped = False self._stop_pollers() - kwargs['openvpn_verb'] = self._openvpn_verb - kwargs['remotes'] = self._remotes - # start the main vpn subprocess - vpnproc = VPNProcess(*args, **kwargs) + vpnproc = VPNProcess( + self._eipconfig, self._providerconfig, self._host, + self._port, openvpn_verb=7, remotes=self._remotes, + restartfun=self.restart) if vpnproc.get_openvpn_process(): logger.info("Another vpn process is running. Will try to stop it.") @@ -91,17 +87,12 @@ class VPNControl(object): LoopingCall(vpnproc.pollState)] self._pollers.extend(poll_list) self._start_pollers() + return True - @property - def status(self): - if not self._vpnproc: - return 'OFFLINE' - return self._vpnproc.status - - @property - def traffic_status(self): - return self._vpnproc.traffic_status - + def restart(self): + self.stop(shutdown=False, restart=True) + reactor.callLater( + self.RESTART_WAIT, self.start) def stop(self, shutdown=False, restart=False): """ @@ -122,7 +113,7 @@ class VPNControl(object): # We assume that the only valid stops are initiated # by an user action, not hard restarts self._user_stopped = not restart - self._vpnproc.is_restart = restart + self._vpnproc.restarting = restart self._sentterm = True self._vpnproc.terminate_openvpn(shutdown=shutdown) @@ -134,6 +125,10 @@ class VPNControl(object): else: logger.debug("VPN is not running.") + return True + + + # FIXME -- is this used from somewhere??? def bitmask_root_vpn_down(self): """ Bring openvpn down using the privileged wrapper. @@ -148,6 +143,16 @@ class VPNControl(object): BM_ROOT, "openvpn", "stop"]) return True if exitCode is 0 else False + @property + def status(self): + if not self._vpnproc: + return 'OFFLINE' + return self._vpnproc.status + + @property + def traffic_status(self): + return self._vpnproc.traffic_status + def _killit(self): """ Sends a kill signal to the process. @@ -159,8 +164,6 @@ class VPNControl(object): self._vpnproc.aborted = True self._vpnproc.killProcess() - - def _kill_if_left_alive(self, tries=0): """ Check if the process is still alive, and send a |