summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-10-05 21:21:22 +0900
committerkali <kali@leap.se>2012-10-05 21:21:22 +0900
commit1cbf954d9eda71cabfa58811c09bc63cfe9465d5 (patch)
treeef7b869fb7f59c9f8cbeb328427a8f9ac854aa7c /src/leap
parent31c0afa5eb9bc7566ca39099520e8adc7b531e22 (diff)
add comments to netchecks
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/base/checks.py40
-rw-r--r--src/leap/base/network.py15
-rw-r--r--src/leap/baseapp/network.py9
3 files changed, 53 insertions, 11 deletions
diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py
index d02c9a3d..0dbb2846 100644
--- a/src/leap/base/checks.py
+++ b/src/leap/base/checks.py
@@ -17,8 +17,15 @@ class LeapNetworkChecker(object):
"""
all network related checks
"""
- # TODO eventually, use a more portable solution
- # like psutil
+ # TODO refactor to use psutil ---
+
+ # #718
+ # XXX get provider gateway as a parameter
+ # for constructor.
+ # def __init__(self, *args, **kwargs):
+ # ...
+ # provider_gw = kwargs.pop('provider_gw', None)
+ # self.provider_gateway = provider_gw
def run_all(self, checker=None):
if not checker:
@@ -29,12 +36,23 @@ class LeapNetworkChecker(object):
checker.check_tunnel_default_interface()
checker.check_internet_connection()
checker.is_internet_up()
+
+ # XXX We are pinging the default gateway for our connection right?
+ # kali: 2012-10-05 20:59 -- I think we should get
+ # also the default gateway and ping it instead.
checker.ping_gateway()
+ # something like: ?
+ # see __init__ above
+ # if self.provider_gateway:
+ # checker.ping_gateway(self.provider_gateway)
+
def check_internet_connection(self):
try:
# XXX remove this hardcoded random ip
+ # ping leap.se or eip provider instead...?
requests.get('http://216.172.161.165')
+
except (requests.HTTPError, requests.RequestException) as e:
raise exceptions.NoInternetConnection(e.message)
except requests.ConnectionError as e:
@@ -44,6 +62,7 @@ class LeapNetworkChecker(object):
error = "No valid internet connection found."
else:
error = "Provider server appears to be down."
+ logger.error(error)
raise exceptions.NoInternetConnection(error)
logger.debug('Network appears to be up.')
@@ -78,6 +97,7 @@ class LeapNetworkChecker(object):
if not platform.system() == "Linux":
raise NotImplementedError
+ # XXX use psutil
f = open("/proc/net/route")
route_table = f.readlines()
f.close()
@@ -102,7 +122,21 @@ class LeapNetworkChecker(object):
return default_iface, gateway
def ping_gateway(self, gateway):
- #TODO: Discuss how much packet loss (%) is acceptable.
+ # TODO: Discuss how much packet loss (%) is acceptable.
+
+ # XXX -- validate gateway
+ # -- is it a valid ip? (there's something in util)
+ # -- is it a domain?
+ # -- can we resolve? -- raise NoDNSError if not.
packet_loss = ping.quiet_ping(gateway)[0]
if packet_loss > constants.MAX_ICMP_PACKET_LOSS:
raise exceptions.NoConnectionToGateway
+
+ # XXX check for name resolution servers
+ # dunno what's the best way to do this...
+ # check for etc/resolv entries or similar?
+ # just try to resolve?
+ # is there something in psutil?
+
+ # def check_name_resolution(self):
+ # pass
diff --git a/src/leap/base/network.py b/src/leap/base/network.py
index 4a90f2f4..e90139c4 100644
--- a/src/leap/base/network.py
+++ b/src/leap/base/network.py
@@ -13,18 +13,22 @@ from time import sleep
logger = logging.getLogger(name=__name__)
-class NetworkChecker(object):
+class NetworkCheckerThread(object):
"""
Manages network checking thread that makes sure we have a working network
connection.
"""
def __init__(self, *args, **kwargs):
self.status_signals = kwargs.pop('status_signals', None)
- self.watcher_cb = kwargs.pop('status_signals', None)
+ #self.watcher_cb = kwargs.pop('status_signals', None)
self.error_cb = kwargs.pop(
'error_cb',
lambda exc: logger.error("%s", exc.message))
self.shutdown = threading.Event()
+
+ # XXX get provider_gateway and pass it to checker
+ # see in eip.config for function
+ # #718
self.checker = LeapNetworkChecker()
def start(self):
@@ -50,9 +54,10 @@ class NetworkChecker(object):
self.checker.check_tunnel_default_interface()
break
except TunnelNotDefaultRouteError:
+ # XXX ??? why do we sleep here???
sleep(1)
- observer_dict = dict(((
+ fail_observer_dict = dict(((
observer,
process_events(observer)) for observer in fail_callbacks))
while not self.shutdown.is_set():
@@ -61,8 +66,8 @@ class NetworkChecker(object):
self.checker.check_internet_connection()
sleep(ROUTE_CHECK_INTERVAL)
except Exception as exc:
- for obs in observer_dict:
- observer_dict[obs].send(exc)
+ for obs in fail_observer_dict:
+ fail_observer_dict[obs].send(exc)
sleep(ROUTE_CHECK_INTERVAL)
#reset event
self.shutdown.clear()
diff --git a/src/leap/baseapp/network.py b/src/leap/baseapp/network.py
index f1859c7a..fbf9376f 100644
--- a/src/leap/baseapp/network.py
+++ b/src/leap/baseapp/network.py
@@ -3,7 +3,7 @@ from __future__ import print_function
import logging
logger = logging.getLogger(name=__name__)
-from leap.base.network import NetworkChecker
+from leap.base.network import NetworkCheckerThread
#from leap.baseapp.dialogs import ErrorDialog
@@ -14,9 +14,12 @@ class NetworkCheckerAppMixin(object):
"""
def __init__(self, *args, **kwargs):
- self.network_checker = NetworkChecker(
+ self.network_checker = NetworkCheckerThread(
+ # XXX watcher? remove -----
watcher_cb=self.newLogLine.emit,
- error_cb=self.handle_network_error,
+ # XXX what callback? ------
+ error_cb=None,
debug=self.debugmode)
+ # XXX move run_checks to slot
self.network_checker.run_checks()