diff options
author | Ruben Pollan <meskio@sindominio.net> | 2017-06-29 18:54:30 +0200 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2017-07-20 21:37:03 +0200 |
commit | d25757fba7d98b4535629de9dccf3f32b3e03487 (patch) | |
tree | a309c339c75bef34067d63f3bcffa2fc07c61f7c /src/leap/bitmask/vpn/process.py | |
parent | 05cdff086cfa4b4770d1d1af50b1f462e09b1632 (diff) |
[refactor] use VPNManagment in composition instead of inheritance
We make an ugly step for that moving the VPNStatus into VPNManagement.
Let's iterate on it a second time to clean up that.
- Related: #8942
Diffstat (limited to 'src/leap/bitmask/vpn/process.py')
-rw-r--r-- | src/leap/bitmask/vpn/process.py | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py index daf3576b..aaf990c1 100644 --- a/src/leap/bitmask/vpn/process.py +++ b/src/leap/bitmask/vpn/process.py @@ -29,8 +29,8 @@ from twisted.internet import error as internet_error from twisted.logger import Logger from leap.bitmask.vpn.utils import get_vpn_launcher -from leap.bitmask.vpn import _status -from leap.bitmask.vpn import _management +from leap.bitmask.vpn._status import VPNStatus +from leap.bitmask.vpn._management import VPNManagement from leap.bitmask.vpn.launchers import darwin from leap.bitmask.vpn.constants import IS_MAC, IS_LINUX @@ -40,7 +40,7 @@ from leap.bitmask.vpn.constants import IS_MAC, IS_LINUX OPENVPN_VERBOSITY = 1 -class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): +class _VPNProcess(protocol.ProcessProtocol): """ A ProcessProtocol class that can be used to spawn a process that will @@ -76,16 +76,15 @@ class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): openvpn invocation :type openvpn_verb: int """ - # TODO handle management as a component - _management.VPNManagement.__init__(self) - self.set_connection(socket_host, socket_port) + self._management = VPNManagement() + self._management.set_connection(socket_host, socket_port) + self._host = socket_host + self._port = socket_port self._vpnconfig = vpnconfig self._providerconfig = providerconfig self._launcher = get_vpn_launcher() - self._last_state = None - self._last_status = None self._alive = False # XXX use flags, maybe, instead of passing @@ -93,8 +92,8 @@ class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): self._openvpn_verb = openvpn_verb self._restartfun = restartfun - self._status = _status.VPNStatus() - self.set_watcher(self._status) + self._status = VPNStatus() + self._management.set_watcher(self._status) self.restarting = True self._remotes = remotes @@ -110,10 +109,6 @@ class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): def traffic_status(self): return self._status.get_traffic_status() - @traffic_status.setter - def traffic_status(self, value): - self._status.set_traffic_status(value) - # processProtocol methods def connectionMade(self): @@ -122,7 +117,7 @@ class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): """ self._alive = True self.aborted = False - self.connect_retry(max_retries=10) + self._management.connect_retry(max_retries=10) def outReceived(self, data): """ @@ -183,18 +178,20 @@ class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): Polls connection status. """ if self._alive: - self.get_status() + up, down = self._management.get_traffic_status() + self._status.set_traffic_status(up, down) def pollState(self): """ Polls connection state. """ if self._alive: - self.get_state() + state = self._management.get_state() + self._status.set_status(state, None) def pollLog(self): if self._alive: - self.process_log() + self._management.process_log() # launcher @@ -243,8 +240,17 @@ class _VPNProcess(protocol.ProcessProtocol, _management.VPNManagement): # filter out ports since we don't need that info return [gateway for gateway, port in gateways_ports] + def get_openvpn_process(self): + return self._management.get_openvpn_process() + # shutdown + def stop_if_already_running(self): + return self._management.stop_if_already_running() + + def terminate(self, shutdown=False): + self._management.terminate(shutdown) + def killProcess(self): """ Sends the KILL signal to the running process. |