diff options
author | Kali Kaneko <kali@leap.se> | 2017-08-23 01:05:03 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2017-08-30 16:18:03 -0400 |
commit | 52b4885602b9b072032e75556c21d475ef7d696d (patch) | |
tree | 79e289efe798262b7ad4e77e819e8160d4ec14f4 /src | |
parent | 8d1ff2f0e4ec1ce86051bbe7121dbb9e1ca00de7 (diff) |
[refactor] catch failures
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/bitmask/vpn/process.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py index 5d23a0af..ecbc1505 100644 --- a/src/leap/bitmask/vpn/process.py +++ b/src/leap/bitmask/vpn/process.py @@ -90,6 +90,7 @@ class _VPNProcess(protocol.ProcessProtocol): self.restarting = True self.failed = False + self.errmsg = None self.proto = None self._remotes = remotes @@ -129,6 +130,7 @@ class _VPNProcess(protocol.ProcessProtocol): lambda f: retry(retries)) def connectionMade(self): + self.failed = False reactor.callLater(0.1, self._connect_to_management) def processExited(self, failure): @@ -136,19 +138,19 @@ class _VPNProcess(protocol.ProcessProtocol): internet_error.ProcessDone, internet_error.ProcessTerminated) if err == internet_error.ProcessDone: - status, errmsg = 'off', None + pass + elif err == internet_error.ProcessTerminated: - status, errmsg = 'failure', failure.value.exitCode - if errmsg: - self.log.debug('Process Exited, status %d' % (errmsg,)) + self.failed = True + self.errmsg = failure.value.exitCode + if self.errmsg: + self.log.debug('Process Exited, status %d' % (self.errmsg,)) else: self.log.warn('%r' % failure.value) if IS_MAC: # TODO: need to exit properly! - status, errmsg = 'off', None - - # TODO ---- propagate this status upwards!! - # XXX do something with status + self.errmsg = None + self.proto = None def processEnded(self, reason): """ @@ -185,13 +187,17 @@ class _VPNProcess(protocol.ProcessProtocol): @property def status(self): + if self.failed: + return {'status': 'failed', 'error': self.errmsg} if not self.proto: - status = {'status': 'off', 'error': None} - return status + return {'status': 'off', 'error': None} status = {'status': self.proto.state.simple.lower(), 'error': None} if self.proto.traffic: + remote = self.proto.remote + rport = self.proto.rport + status['remote'] = '%s:%s' % (remote, rport) down, up = self.proto.traffic.get_rate() status['up'] = up status['down'] = down |