summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/backend
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2014-07-02 12:14:59 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2014-07-14 12:14:20 -0300
commit13c0b7cac822a33f7395e3f099a2d37251e2c759 (patch)
treedce4f3fa80a3b6e9fade199fdff30a5c055a8cab /src/leap/bitmask/backend
parentcf75e3575c33249a6f756dceb423c6ec7f6cd50e (diff)
Ask the backend for the country code.
Remove global variable in favor of a helper method that returns the country code. Needed in order to split backend/frontend.
Diffstat (limited to 'src/leap/bitmask/backend')
-rw-r--r--src/leap/bitmask/backend/api.py3
-rw-r--r--src/leap/bitmask/backend/components.py42
-rw-r--r--src/leap/bitmask/backend/leapbackend.py13
-rw-r--r--src/leap/bitmask/backend/leapsignaler.py2
4 files changed, 60 insertions, 0 deletions
diff --git a/src/leap/bitmask/backend/api.py b/src/leap/bitmask/backend/api.py
index 012b3cbc..f8b8c699 100644
--- a/src/leap/bitmask/backend/api.py
+++ b/src/leap/bitmask/backend/api.py
@@ -26,6 +26,7 @@ API = (
"eip_can_start",
"eip_cancel_setup",
"eip_check_dns",
+ "eip_get_gateway_country_code",
"eip_get_gateways_list",
"eip_get_initialized_providers",
"eip_setup",
@@ -75,10 +76,12 @@ SIGNALS = (
"eip_disconnected",
"eip_dns_error",
"eip_dns_ok",
+ "eip_get_gateway_country_code",
"eip_get_gateways_list",
"eip_get_gateways_list_error",
"eip_get_initialized_providers",
"eip_network_unreachable",
+ "eip_no_gateway",
"eip_no_pkexec_error",
"eip_no_polkit_agent_error",
"eip_no_tun_kext_error",
diff --git a/src/leap/bitmask/backend/components.py b/src/leap/bitmask/backend/components.py
index 5357bed5..fe7b566a 100644
--- a/src/leap/bitmask/backend/components.py
+++ b/src/leap/bitmask/backend/components.py
@@ -31,6 +31,7 @@ from twisted.python import log
import zope.interface
import zope.proxy
+from leap.bitmask.config.leapsettings import LeapSettings
from leap.bitmask.config.providerconfig import ProviderConfig
from leap.bitmask.crypto.srpauth import SRPAuth
from leap.bitmask.crypto.srpregister import SRPRegister
@@ -589,6 +590,47 @@ class EIP(object):
self._signaler.signal(
self._signaler.eip_get_gateways_list, gateways)
+ def get_gateway_country_code(self, domain):
+ """
+ Signal the country code for the currently used gateway for the given
+ provider.
+
+ :param domain: the domain to get country code.
+ :type domain: str
+
+ Signals:
+ eip_get_gateway_country_code -> str
+ eip_no_gateway
+ """
+ leap_settings = LeapSettings()
+
+ eip_config = eipconfig.EIPConfig()
+ provider_config = ProviderConfig.get_provider_config(domain)
+
+ api_version = provider_config.get_api_version()
+ eip_config.set_api_version(api_version)
+ eip_config.load(eipconfig.get_eipconfig_path(domain))
+
+ gateway_selector = eipconfig.VPNGatewaySelector(eip_config)
+ gateway_conf = leap_settings.get_selected_gateway(domain)
+
+ if gateway_conf == leap_settings.GATEWAY_AUTOMATIC:
+ gateways = gateway_selector.get_gateways()
+ else:
+ gateways = [gateway_conf]
+
+ if not gateways:
+ self._signaler.signal(self._signaler.eip_no_gateway)
+ return
+
+ # this only works for selecting the first gateway, as we're
+ # currently doing.
+ ccodes = gateway_selector.get_gateways_country_code()
+ gateway_ccode = ccodes[gateways[0]]
+
+ self._signaler.signal(self._signaler.eip_get_gateway_country_code,
+ gateway_ccode)
+
def _can_start(self, domain):
"""
Returns True if it has everything that is needed to run EIP,
diff --git a/src/leap/bitmask/backend/leapbackend.py b/src/leap/bitmask/backend/leapbackend.py
index 4794d988..3bc7a513 100644
--- a/src/leap/bitmask/backend/leapbackend.py
+++ b/src/leap/bitmask/backend/leapbackend.py
@@ -256,6 +256,19 @@ class LeapBackend(Backend):
"""
self._eip.get_gateways_list(domain)
+ def eip_get_gateway_country_code(self, domain):
+ """
+ Signal a list of gateways for the given provider.
+
+ :param domain: the domain to get the gateways.
+ :type domain: str
+
+ Signals:
+ eip_get_gateways_list -> str
+ eip_no_gateway
+ """
+ self._eip.get_gateway_country_code(domain)
+
def eip_get_initialized_providers(self, domains):
"""
Signal a list of the given domains and if they are initialized or not.
diff --git a/src/leap/bitmask/backend/leapsignaler.py b/src/leap/bitmask/backend/leapsignaler.py
index 47df0911..7912fc20 100644
--- a/src/leap/bitmask/backend/leapsignaler.py
+++ b/src/leap/bitmask/backend/leapsignaler.py
@@ -37,10 +37,12 @@ class LeapSignaler(SignalerQt):
eip_disconnected = QtCore.Signal(object)
eip_dns_error = QtCore.Signal()
eip_dns_ok = QtCore.Signal()
+ eip_get_gateway_country_code = QtCore.Signal(object)
eip_get_gateways_list = QtCore.Signal(object)
eip_get_gateways_list_error = QtCore.Signal()
eip_get_initialized_providers = QtCore.Signal(object)
eip_network_unreachable = QtCore.Signal()
+ eip_no_gateway = QtCore.Signal()
eip_no_pkexec_error = QtCore.Signal()
eip_no_polkit_agent_error = QtCore.Signal()
eip_no_tun_kext_error = QtCore.Signal()