summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/tunnel.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-08-24 01:31:23 -0400
committerKali Kaneko <kali@leap.se>2017-08-30 16:18:06 -0400
commit116af66d410ee3a4ee69a8fa25c6036ed1c2411f (patch)
tree189771e66ca4ef0d62096d14eb6638e6fd05eec2 /src/leap/bitmask/vpn/tunnel.py
parent34d59f070d13ec2ac09c07cc7e0ec6a5d559fef9 (diff)
[refactor] restart by allowing to send SIGUSR1 to openvpn process
by properly allowing openvpn to restart when receiving SIGUSR1, we can reserve the hard process restarts for cases in which the process is aborted. this depends on bitmask-root adding --persist-tun and --persist-key as mandatory/allowed parameters.
Diffstat (limited to 'src/leap/bitmask/vpn/tunnel.py')
-rw-r--r--src/leap/bitmask/vpn/tunnel.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/leap/bitmask/vpn/tunnel.py b/src/leap/bitmask/vpn/tunnel.py
index d9a8be3..7c2274a 100644
--- a/src/leap/bitmask/vpn/tunnel.py
+++ b/src/leap/bitmask/vpn/tunnel.py
@@ -31,8 +31,6 @@ from .process import VPNProcess
# TODO ----------------- refactor --------------------
-# [ ] register change state listener
-# emit_async(catalog.VPN_STATUS_CHANGED)
# [ ] catch ping-restart
# 'NETWORK_UNREACHABLE': (
# 'Network is unreachable (code=101)',),
@@ -40,6 +38,8 @@ from .process import VPNProcess
# "SIGTERM[soft,tls-error]",),
# TODO ----------------- refactor --------------------
+RESTART_WAIT = 2 # in secs
+
class ConfiguredTunnel(object):
@@ -82,8 +82,8 @@ class ConfiguredTunnel(object):
defer.returnValue(started)
@defer.inlineCallbacks
- def stop(self):
- stopped = yield self._stop_vpn(restart=False)
+ def stop(self, restart=False):
+ stopped = yield self._stop_vpn(restart=restart)
defer.returnValue(stopped)
# status
@@ -110,14 +110,14 @@ class ConfiguredTunnel(object):
vpnproc = VPNProcess(*args, **kwargs)
self._vpnproc = vpnproc
- self.__start_pre_up(vpnproc)
- cmd = self.__start_get_cmd(vpnproc)
-
- running = yield self.__start_spawn_proc(vpnproc, cmd)
- if running:
+ try:
+ self.__start_pre_up(vpnproc)
+ cmd = self.__start_get_cmd(vpnproc)
+ running = yield self.__start_spawn_proc(vpnproc, cmd)
vpnproc.pid = running.pid
defer.returnValue(True)
- else:
+ except Exception:
+ # TODO need to propagate the error message properly.
defer.returnValue(False)
def __start_pre_up(self, proc):
@@ -150,7 +150,7 @@ class ConfiguredTunnel(object):
def _restart_vpn(self):
yield self.stop(restart=True)
reactor.callLater(
- self.RESTART_WAIT, self.start)
+ RESTART_WAIT, self.start)
@defer.inlineCallbacks
def _stop_vpn(self, restart=False):