|
|
@ -359,15 +359,18 @@ class Network(util.DaemonThread): |
|
|
|
self.switch_to_interface(server) |
|
|
|
|
|
|
|
def switch_to_interface(self, server): |
|
|
|
'''Switch to server as our interface, it must be in self.interfaces''' |
|
|
|
assert server in self.interfaces |
|
|
|
self.print_error("switching to", server) |
|
|
|
self.interface = self.interfaces[server] |
|
|
|
'''Switch to server as our interface. If not already connected, start a |
|
|
|
connection - we will switch on receipt of the connection notification''' |
|
|
|
self.default_server = server |
|
|
|
self.send_subscriptions() |
|
|
|
self.set_status('connected') |
|
|
|
self.notify('updated') |
|
|
|
|
|
|
|
if server in self.interfaces: |
|
|
|
self.print_error("switching to", server) |
|
|
|
self.interface = self.interfaces[server] |
|
|
|
self.send_subscriptions() |
|
|
|
self.set_status('connected') |
|
|
|
self.notify('updated') |
|
|
|
elif server not in self.pending_servers: |
|
|
|
self.print_error("starting %s; will switch once connected" % server) |
|
|
|
self.start_interface(server) |
|
|
|
|
|
|
|
def stop_interface(self): |
|
|
|
self.interface.stop() |
|
|
@ -384,13 +387,7 @@ class Network(util.DaemonThread): |
|
|
|
if self.is_connected(): |
|
|
|
self.stop_interface() |
|
|
|
|
|
|
|
# start interface |
|
|
|
self.default_server = server |
|
|
|
|
|
|
|
if server in self.interfaces.keys(): |
|
|
|
self.switch_to_interface(server) |
|
|
|
else: |
|
|
|
self.start_interface(server) |
|
|
|
self.switch_to_interface(server) |
|
|
|
|
|
|
|
|
|
|
|
def add_recent_server(self, i): |
|
|
@ -508,17 +505,12 @@ class Network(util.DaemonThread): |
|
|
|
if self.config.get('auto_cycle'): |
|
|
|
self.switch_to_random_interface() |
|
|
|
else: |
|
|
|
if self.default_server in self.interfaces.keys(): |
|
|
|
self.switch_to_interface(self.default_server) |
|
|
|
if self.default_server in self.disconnected_servers: |
|
|
|
if now - self.server_retry_time > SERVER_RETRY_INTERVAL: |
|
|
|
self.disconnected_servers.remove(self.default_server) |
|
|
|
self.server_retry_time = now |
|
|
|
else: |
|
|
|
if self.default_server in self.disconnected_servers: |
|
|
|
if now - self.server_retry_time > SERVER_RETRY_INTERVAL: |
|
|
|
self.disconnected_servers.remove(self.default_server) |
|
|
|
self.server_retry_time = now |
|
|
|
else: |
|
|
|
if self.default_server not in self.pending_servers: |
|
|
|
self.print_error("forcing reconnection") |
|
|
|
self.start_interface(self.default_server) |
|
|
|
self.switch_to_interface(self.default_server) |
|
|
|
|
|
|
|
def run(self): |
|
|
|
while self.is_running(): |
|
|
|