electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 911a60c02d824b02e698c967420aebe14b937be1
parent 3c77eeba7db333bfe676725f49ec8a1864a6491c
Author: ThomasV <thomasv@gitorious>
Date:   Thu,  2 Apr 2015 15:12:01 +0200

separate timeouts for server and nodes retry

Diffstat:
Mlib/network.py | 22+++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/network.py b/lib/network.py @@ -34,7 +34,8 @@ DEFAULT_SERVERS = { 'us.electrum.be':DEFAULT_PORTS, } -DISCONNECTED_RETRY_INTERVAL = 60 +NODES_RETRY_INTERVAL = 60 +SERVER_RETRY_INTERVAL = 10 def parse_servers(result): @@ -459,18 +460,20 @@ class Network(util.DaemonThread): time.sleep(0.1) def run(self): - disconnected_time = time.time() + server_retry_time = time.time() + nodes_retry_time = time.time() while self.is_running(): try: i, response = self.queue.get(timeout=0.1) except Queue.Empty: + now = time.time() if len(self.interfaces) + len(self.pending_servers) < self.num_server: self.start_random_interface() if not self.interfaces: - if time.time() - disconnected_time > DISCONNECTED_RETRY_INTERVAL: + if now - nodes_retry_time > NODES_RETRY_INTERVAL: self.print_error('network: retrying connections') self.disconnected_servers = set([]) - disconnected_time = time.time() + nodes_retry_time = now if not self.interface.is_connected: if self.config.get('auto_cycle'): if self.interfaces: @@ -479,9 +482,14 @@ class Network(util.DaemonThread): if self.default_server in self.interfaces.keys(): self.switch_to_interface(self.interfaces[self.default_server]) else: - if self.default_server not in self.disconnected_servers and self.default_server not in self.pending_servers: - self.print_error("forcing reconnection") - self.interface = self.start_interface(self.default_server) + if self.default_server in self.disconnected_servers: + if now - server_retry_time > SERVER_RETRY_INTERVAL: + self.disconnected_servers.remove(self.default_server) + server_retry_time = now + else: + if self.default_server not in self.pending_servers: + self.print_error("forcing reconnection") + self.interface = self.start_interface(self.default_server) continue if response is not None: