Suggested auto_connect daemon mode fix for #1336

This commit is contained in:
Neil Booth 2015-07-03 11:50:53 +09:00
parent 306756b42d
commit 5acbe00cbf
1 changed files with 5 additions and 6 deletions

View File

@ -180,6 +180,7 @@ class Network(util.DaemonThread):
# to or have an ongoing connection with # to or have an ongoing connection with
self.interface = None self.interface = None
self.interfaces = {} self.interfaces = {}
self.auto_connect = self.config.get('auto_connect', False)
self.start_network(deserialize_server(self.default_server)[2], self.start_network(deserialize_server(self.default_server)[2],
deserialize_proxy(self.config.get('proxy'))) deserialize_proxy(self.config.get('proxy')))
@ -256,10 +257,7 @@ class Network(util.DaemonThread):
def get_parameters(self): def get_parameters(self):
host, port, protocol = deserialize_server(self.default_server) host, port, protocol = deserialize_server(self.default_server)
return host, port, protocol, self.proxy, self.auto_connect() return host, port, protocol, self.proxy, self.auto_connect
def auto_connect(self):
return self.config.get('auto_connect', False)
def get_interfaces(self): def get_interfaces(self):
'''The interfaces that are in connected state''' '''The interfaces that are in connected state'''
@ -326,6 +324,7 @@ class Network(util.DaemonThread):
self.interfaces = {} self.interfaces = {}
def set_parameters(self, host, port, protocol, proxy, auto_connect): def set_parameters(self, host, port, protocol, proxy, auto_connect):
self.auto_connect = auto_connect
server = serialize_server(host, port, protocol) server = serialize_server(host, port, protocol)
if self.proxy != proxy or self.protocol != protocol: if self.proxy != proxy or self.protocol != protocol:
# Restart the network defaulting to the given server # Restart the network defaulting to the given server
@ -344,7 +343,7 @@ class Network(util.DaemonThread):
def switch_lagging_interface(self, suggestion = None): def switch_lagging_interface(self, suggestion = None):
'''If auto_connect and lagging, switch interface''' '''If auto_connect and lagging, switch interface'''
if self.server_is_lagging() and self.auto_connect(): if self.server_is_lagging() and self.auto_connect:
if suggestion and self.protocol == deserialize_server(suggestion)[2]: if suggestion and self.protocol == deserialize_server(suggestion)[2]:
self.switch_to_interface(suggestion) self.switch_to_interface(suggestion)
else: else:
@ -499,7 +498,7 @@ class Network(util.DaemonThread):
self.nodes_retry_time = now self.nodes_retry_time = now
# main interface # main interface
if not self.is_connected(): if not self.is_connected():
if self.auto_connect(): if self.auto_connect:
self.switch_to_random_interface() self.switch_to_random_interface()
else: else:
if self.default_server in self.disconnected_servers: if self.default_server in self.disconnected_servers: