mirror of
https://github.com/gryf/wicd.git
synced 2025-12-20 04:48:00 +01:00
Added checks to auto-reconnection code to keep it from constantly trying to reconnect when it isn't working.
Added a ShouldAutoReconnect method to the daemon, to simply the call needed in monitor.py's auto_reconnect method.
This commit is contained in:
13
daemon.py
13
daemon.py
@@ -391,10 +391,6 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
time.sleep(1.5)
|
time.sleep(1.5)
|
||||||
gobject.timeout_add(3000, self._monitor_wired_autoconnect)
|
gobject.timeout_add(3000, self._monitor_wired_autoconnect)
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
|
||||||
def GetAutoConnecting(self):
|
|
||||||
return self.auto_connecting
|
|
||||||
|
|
||||||
def _wireless_autoconnect(self):
|
def _wireless_autoconnect(self):
|
||||||
""" Attempts to autoconnect to a wireless network. """
|
""" Attempts to autoconnect to a wireless network. """
|
||||||
print "No wired connection present, attempting to autoconnect" + \
|
print "No wired connection present, attempting to autoconnect" + \
|
||||||
@@ -497,6 +493,15 @@ class ConnectionWizard(dbus.service.Object):
|
|||||||
"""
|
"""
|
||||||
self.need_profile_chooser = misc.to_bool(val)
|
self.need_profile_chooser = misc.to_bool(val)
|
||||||
|
|
||||||
|
@dbus.service.method('org.wicd.daemon')
|
||||||
|
def ShouldAutoReconnect(self):
|
||||||
|
""" Returns True if it's the right time to try autoreconnecting. """
|
||||||
|
if self.GetAutoReconnect() and not self.CheckIfConnecting() and \
|
||||||
|
not self.GetForcedDisconnect() and not self.auto_connecting:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def GetForcedDisconnect(self):
|
def GetForcedDisconnect(self):
|
||||||
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
|
""" Returns the forced_disconnect status. See SetForcedDisconnect. """
|
||||||
|
|||||||
15
monitor.py
15
monitor.py
@@ -21,6 +21,7 @@ import dbus
|
|||||||
import gobject
|
import gobject
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from dbus.mainloop.glib import DBusGMainLoop
|
from dbus.mainloop.glib import DBusGMainLoop
|
||||||
|
|
||||||
import wpath
|
import wpath
|
||||||
@@ -56,6 +57,8 @@ class ConnectionStatus():
|
|||||||
self.connection_lost_counter = 0
|
self.connection_lost_counter = 0
|
||||||
self.last_state = misc.NOT_CONNECTED
|
self.last_state = misc.NOT_CONNECTED
|
||||||
self.reconnecting = False
|
self.reconnecting = False
|
||||||
|
self.reconnect_tries = 0
|
||||||
|
self.last_reconnect_time = time.time()
|
||||||
self.signal_changed = False
|
self.signal_changed = False
|
||||||
|
|
||||||
def check_for_wired_connection(self, wired_ip):
|
def check_for_wired_connection(self, wired_ip):
|
||||||
@@ -184,10 +187,12 @@ class ConnectionStatus():
|
|||||||
else:
|
else:
|
||||||
info = ["wireless", wireless.GetCurrentNetwork(self.iwconfig)]
|
info = ["wireless", wireless.GetCurrentNetwork(self.iwconfig)]
|
||||||
elif state == misc.WIRELESS:
|
elif state == misc.WIRELESS:
|
||||||
|
self.reconnect_tries = 0
|
||||||
info = [wifi_ip, wireless.GetCurrentNetwork(self.iwconfig),
|
info = [wifi_ip, wireless.GetCurrentNetwork(self.iwconfig),
|
||||||
str(wireless.GetPrintableSignalStrength(self.iwconfig)),
|
str(wireless.GetPrintableSignalStrength(self.iwconfig)),
|
||||||
str(wireless.GetCurrentNetworkID(self.iwconfig))]
|
str(wireless.GetCurrentNetworkID(self.iwconfig))]
|
||||||
elif state == misc.WIRED:
|
elif state == misc.WIRED:
|
||||||
|
self.reconnect_tries = 0
|
||||||
info = [wired_ip]
|
info = [wired_ip]
|
||||||
else:
|
else:
|
||||||
print 'ERROR: Invalid state!'
|
print 'ERROR: Invalid state!'
|
||||||
@@ -212,13 +217,19 @@ class ConnectionStatus():
|
|||||||
if self.reconnecting:
|
if self.reconnecting:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Some checks to keep reconnect retries from going crazy.
|
||||||
|
if self.reconnect_tries > 2 and \
|
||||||
|
time.time() - self.last_reconnect_time < 30:
|
||||||
|
return
|
||||||
|
|
||||||
self.reconnecting = True
|
self.reconnecting = True
|
||||||
daemon.SetCurrentInterface('')
|
daemon.SetCurrentInterface('')
|
||||||
|
|
||||||
print 'autoreconnect'
|
print 'autoreconnect'
|
||||||
if daemon.GetAutoReconnect() and not daemon.CheckIfConnecting() and \
|
if daemon.ShouldAutoReconnect():
|
||||||
not daemon.GetForcedDisconnect() and not daemon.GetAutoConnecting():
|
|
||||||
print 'Starting automatic reconnect process'
|
print 'Starting automatic reconnect process'
|
||||||
|
self.last_reconnect_time = time.time()
|
||||||
|
self.reconnect_tries += 1
|
||||||
|
|
||||||
# If we just lost a wireless connection, try to connect to that
|
# If we just lost a wireless connection, try to connect to that
|
||||||
# network again. Otherwise just call Autoconnect.
|
# network again. Otherwise just call Autoconnect.
|
||||||
|
|||||||
Reference in New Issue
Block a user