summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/services/eip/eipconfig.py
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2014-06-05 16:38:56 -0500
committerKali Kaneko <kali@leap.se>2014-06-06 10:49:15 -0500
commit57aa4d51e37228333e56e98d9af3bfe7b278e2d1 (patch)
tree11e8766f74299e4c9708f04a4b6cd88cb02df108 /src/leap/bitmask/services/eip/eipconfig.py
parent0b8cd73171eee3bf3f3c7b91faa90104e85e492b (diff)
add icons for the vpn exit nodes
Diffstat (limited to 'src/leap/bitmask/services/eip/eipconfig.py')
-rw-r--r--src/leap/bitmask/services/eip/eipconfig.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/src/leap/bitmask/services/eip/eipconfig.py b/src/leap/bitmask/services/eip/eipconfig.py
index 09a3d257..e7419b22 100644
--- a/src/leap/bitmask/services/eip/eipconfig.py
+++ b/src/leap/bitmask/services/eip/eipconfig.py
@@ -110,7 +110,7 @@ class VPNGatewaySelector(object):
def get_gateways_list(self):
"""
- Returns the existing gateways, sorted by timezone proximity.
+ Return the existing gateways, sorted by timezone proximity.
:rtype: list of tuples (location, ip)
(str, IPv4Address or IPv6Address object)
@@ -148,16 +148,36 @@ class VPNGatewaySelector(object):
def get_gateways(self):
"""
- Returns the 4 best gateways, sorted by timezone proximity.
+ Return the 4 best gateways, sorted by timezone proximity.
:rtype: list of IPv4Address or IPv6Address object.
"""
gateways = [ip for location, ip in self.get_gateways_list()][:4]
return gateways
+ def get_gateways_country_code(self):
+ """
+ Return a dict with ipaddress -> country code mapping.
+
+ :rtype: dict
+ """
+ country_codes = {}
+
+ locations = self._eipconfig.get_locations()
+ gateways = self._eipconfig.get_gateways()
+
+ for idx, gateway in enumerate(gateways):
+ gateway_location = gateway.get('location')
+
+ ip = self._eipconfig.get_gateway_ip(idx)
+ if gateway_location is not None:
+ ccode = locations[gateway['location']]['country_code']
+ country_codes[ip] = ccode
+ return country_codes
+
def _get_timezone_distance(self, offset):
'''
- Returns the distance between the local timezone and
+ Return the distance between the local timezone and
the one with offset 'offset'.
:param offset: the distance of a timezone to GMT.
@@ -179,7 +199,7 @@ class VPNGatewaySelector(object):
def _get_local_offset(self):
'''
- Returns the distance between GMT and the local timezone.
+ Return the distance between GMT and the local timezone.
:rtype: int
'''