summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2017-08-23 01:10:03 -0400
committerKali Kaneko <kali@leap.se>2017-08-30 16:18:04 -0400
commit8b77f3155288d51197dfa1082dd3e7079a9d7620 (patch)
tree335b3bffe9ed1b424bc7bc66b7da18b80ac02c50
parent52b4885602b9b072032e75556c21d475ef7d696d (diff)
[refactor] add state listener to signal state transition to UI
-rw-r--r--src/leap/bitmask/vpn/management.py6
-rw-r--r--src/leap/bitmask/vpn/process.py12
2 files changed, 15 insertions, 3 deletions
diff --git a/src/leap/bitmask/vpn/management.py b/src/leap/bitmask/vpn/management.py
index 4aa0e000..e692dc05 100644
--- a/src/leap/bitmask/vpn/management.py
+++ b/src/leap/bitmask/vpn/management.py
@@ -62,13 +62,16 @@ class ManagementProtocol(LineReceiver):
"""
self._state_listeners.add(listener)
+ # TODO -- this needs to be exposed by the API
+ # The UI needs this feature.
+
def getStateHistory(self):
return self._statelog
def lineReceived(self, line):
if self.verbose:
if int(self.verbose) > 1:
- print line
+ print line
elif line.startswith('>LOG'):
print line
@@ -152,7 +155,6 @@ class ManagementProtocol(LineReceiver):
elif len(data) == 8:
ts, state = data[:2]
except Exception as exc:
- print "ERROR", exc
log.error('Failure parsing data: %s' % exc)
if state != self.state:
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index ecbc1505..19115d66 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -33,14 +33,21 @@ from twisted.logger import Logger
from leap.bitmask.vpn.utils import get_vpn_launcher
from leap.bitmask.vpn.management import ManagementProtocol
-
from leap.bitmask.vpn.launchers import darwin
from leap.bitmask.vpn.constants import IS_MAC, IS_LINUX
+from leap.common.events import catalog, emit_async
+
OPENVPN_VERBOSITY = 4
+class VPNStateListener(object):
+
+ def change_state(self, state):
+ emit_async(catalog.VPN_STATUS_CHANGED)
+
+
class _VPNProcess(protocol.ProcessProtocol):
"""
@@ -99,6 +106,9 @@ class _VPNProcess(protocol.ProcessProtocol):
@defer.inlineCallbacks
def _got_management_protocol(self, proto):
self.proto = proto
+ listener = VPNStateListener()
+ proto.addStateListener(listener)
+
try:
yield proto.logOn()
yield proto.getVersion()