Browse Source

don't set network.interface to None when disconnetced

283
ThomasV 11 years ago
parent
commit
4446cf44c7
  1. 35
      lib/network.py
  2. 5
      lib/wallet.py

35
lib/network.py

@ -133,7 +133,7 @@ class Network(threading.Thread):
if not choice_list: if not choice_list:
if not self.interfaces: if not self.interfaces:
# we are probably offline, retry later # we are probably offline, retry later
self.disconnected_servers = [] self.disconnected_servers = set([])
return return
server = random.choice( choice_list ) server = random.choice( choice_list )
@ -172,12 +172,17 @@ class Network(threading.Thread):
self.start_interfaces() self.start_interfaces()
threading.Thread.start(self) threading.Thread.start(self)
if wait: if wait:
if self.config.get('auto_cycle'): return self.wait_until_connected()
while not self.is_connected():
time.sleep(0.1) def wait_until_connected(self):
else: "wait until connection status is known"
self.interface.connect_event.wait() if self.config.get('auto_cycle'):
return self.interface.is_connected while not self.is_connected():
time.sleep(0.1)
else:
self.interface.connect_event.wait()
return self.interface.is_connected
def set_parameters(self, host, port, protocol, proxy, auto_connect): def set_parameters(self, host, port, protocol, proxy, auto_connect):
@ -193,11 +198,11 @@ class Network(threading.Thread):
self.protocol = protocol self.protocol = protocol
for i in self.interfaces.values(): i.stop() for i in self.interfaces.values(): i.stop()
if auto_connect: if auto_connect:
self.interface = None #self.interface = None
return return
if auto_connect: if auto_connect:
if not self.interface: if not self.interface.s_connected:
self.switch_to_random_interface() self.switch_to_random_interface()
else: else:
if self.server_lag > 0: if self.server_lag > 0:
@ -211,7 +216,7 @@ class Network(threading.Thread):
self.switch_to_interface(random.choice(self.interfaces.values())) self.switch_to_interface(random.choice(self.interfaces.values()))
def switch_to_interface(self, interface): def switch_to_interface(self, interface):
assert self.interface is None assert not self.interface.is_connected
server = interface.server server = interface.server
print_error("switching to", server) print_error("switching to", server)
self.interface = interface self.interface = interface
@ -226,17 +231,17 @@ class Network(threading.Thread):
def stop_interface(self): def stop_interface(self):
self.interface.stop() self.interface.stop()
self.interface = None #self.interface = None
def set_server(self, server): def set_server(self, server):
if self.default_server == server and self.interface: if self.default_server == server and self.interface.is_connected:
return return
if self.protocol != server.split(':')[2]: if self.protocol != server.split(':')[2]:
return return
# stop the interface in order to terminate subscriptions # stop the interface in order to terminate subscriptions
if self.interface: if self.interface.is_connected:
self.stop_interface() self.stop_interface()
# notify gui # notify gui
@ -307,10 +312,10 @@ class Network(threading.Thread):
if i.server in self.heights: if i.server in self.heights:
self.heights.pop(i.server) self.heights.pop(i.server)
if i == self.interface: if i == self.interface:
self.interface = None #self.interface = None
self.trigger_callback('disconnected') self.trigger_callback('disconnected')
if self.interface is None and self.config.get('auto_cycle'): if not self.interface.is_connected and self.config.get('auto_cycle'):
self.switch_to_random_interface() self.switch_to_random_interface()

5
lib/wallet.py

@ -1628,10 +1628,9 @@ class WalletSynchronizer(threading.Thread):
self.running = True self.running = True
while self.is_running(): while self.is_running():
if not self.network.is_connected(): if not self.network.is_connected():
print_error("synchronizer: waiting for interface") self.network.wait_until_connected()
self.network.interface.connect_event.wait()
self.run_interface(self.network.interface) self.run_interface(self.network.interface)

Loading…
Cancel
Save