URI: 
       tslightly more robust connection procedure - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit c5d42f36142e0bcd480b19b72485bc83d1179962
   DIR parent 94cc6aa93a04a71a1a8618594cb713e2d5f3c789
  HTML Author: thomasv <thomasv@gitorious>
       Date:   Wed, 16 May 2012 17:29:05 +0200
       
       slightly more robust connection procedure
       
       Diffstat:
         M electrum                            |       1 -
         M lib/gui.py                          |       4 ++--
         M lib/gui_qt.py                       |       2 +-
         M lib/interface.py                    |      48 +++++++++++++++++--------------
       
       4 files changed, 30 insertions(+), 25 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -98,7 +98,6 @@ if __name__ == '__main__':
                    exit(1)
        
                if not found: exit(1)
       -
                gui.main(url)
                wallet.save()
                sys.exit(0)
   DIR diff --git a/lib/gui.py b/lib/gui.py
       t@@ -1140,7 +1140,7 @@ class ElectrumWindow:
                interface = self.wallet.interface
                if self.funds_error:
                    text = "Not enough funds"
       -        elif interface.is_connected:
       +        elif interface and interface.is_connected:
                    self.network_button.set_tooltip_text("Connected to %s:%d.\n%d blocks"%(interface.host, interface.port, self.wallet.blocks))
                    if self.wallet.blocks == -1:
                        self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
       t@@ -1159,7 +1159,7 @@ class ElectrumWindow:
                        if u: text +=  "[%s unconfirmed]"%( format_satoshis(u,True,self.wallet.num_zeros).strip() )
                else:
                    self.status_image.set_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU)
       -            self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(interface.host, self.wallet.blocks))
       +            self.network_button.set_tooltip_text("Trying to contact %s.\n%d blocks"%(self.wallet.server, self.wallet.blocks))
                    text = "Not connected"
        
                self.status_bar.pop(self.context_id) 
   DIR diff --git a/lib/gui_qt.py b/lib/gui_qt.py
       t@@ -206,7 +206,7 @@ class ElectrumWindow(QMainWindow):
                self.emit(QtCore.SIGNAL('updatesignal'))
        
            def update_wallet(self):
       -        if self.wallet.interface.is_connected:
       +        if self.wallet.interface and self.wallet.interface.is_connected:
                    if self.wallet.blocks == -1:
                        text = "Connecting..."
                        icon = QIcon(":icons/status_disconnected.png")
   DIR diff --git a/lib/interface.py b/lib/interface.py
       t@@ -211,6 +211,8 @@ class TcpStratumInterface(Interface):
        
            def __init__(self, host, port):
                Interface.__init__(self, host, port)
       +
       +    def init_socket(self):
                self.s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
                self.s.settimeout(5*60)
                self.s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
       t@@ -277,7 +279,28 @@ class WalletSynchronizer(threading.Thread):
                self.daemon = True
                self.wallet = wallet
                self.loop = loop
       -        self.start_interface()
       +        self.init_interface()
       +
       +    def init_interface(self):
       +        try:
       +            host, port, protocol = self.wallet.server.split(':')
       +            port = int(port)
       +        except:
       +            self.wallet.pick_random_server()
       +            host, port, protocol = self.wallet.server.split(':')
       +            port = int(port)
       +
       +        #print protocol, host, port
       +        if protocol == 't':
       +            InterfaceClass = TcpStratumInterface
       +        elif protocol == 'h':
       +            InterfaceClass = HttpStratumInterface
       +        else:
       +            print "unknown protocol"
       +            InterfaceClass = TcpStratumInterface
       +
       +        self.interface = InterfaceClass(host, port)
       +        self.wallet.interface = self.interface
        
        
            def handle_response(self, r):
       t@@ -330,27 +353,8 @@ class WalletSynchronizer(threading.Thread):
        
        
            def start_interface(self):
       -        try:
       -            host, port, protocol = self.wallet.server.split(':')
       -            port = int(port)
       -        except:
       -            self.wallet.pick_random_server()
       -            host, port, protocol = self.wallet.server.split(':')
       -            port = int(port)
       -
       -        #print protocol, host, port
       -        if protocol == 't':
       -            InterfaceClass = TcpStratumInterface
       -        elif protocol == 'h':
       -            InterfaceClass = HttpStratumInterface
       -        else:
       -            print "unknown protocol"
       -            InterfaceClass = TcpStratumInterface
       -
       -        self.interface = InterfaceClass(host, port)
       +        self.interface.init_socket()
                self.interface.start()
       -        self.wallet.interface = self.interface
       -
                if self.interface.is_connected:
                    self.wallet.start_session(self.interface)
        
       t@@ -358,6 +362,7 @@ class WalletSynchronizer(threading.Thread):
        
            def run(self):
                import socket, time
       +        self.start_interface()
                while True:
                    while self.interface.is_connected:
                        new_addresses = self.wallet.synchronize()
       t@@ -384,6 +389,7 @@ class WalletSynchronizer(threading.Thread):
                    self.wallet.gui_callback()
                    if self.loop:
                        time.sleep(5)
       +                self.init_interface()
                        self.start_interface()
                        continue
                    else: