URI: 
       tMerge pull request #1232 from kyuupichan/switch-or-start - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 0fbbeb16bebca6f46f6ae5d4f4f0e9fb1c27c382
   DIR parent 4aaa9e24f272a1ad2f306cdb562d6b9049e0ef4a
  HTML Author: ThomasV <electrumdev@gmail.com>
       Date:   Sat, 23 May 2015 07:30:00 +0200
       
       Merge pull request #1232 from kyuupichan/switch-or-start
       
       switch_to_interface() to start interface if not connected
       Diffstat:
         M lib/network.py                      |      42 +++++++++++++------------------
       
       1 file changed, 17 insertions(+), 25 deletions(-)
       ---
   DIR diff --git a/lib/network.py b/lib/network.py
       t@@ -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()
       t@@ -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):
       t@@ -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():