pass network to NetworkDialog and Blockchain
authorthomasv <thomasv@gitorious>
Tue, 10 Sep 2013 16:27:32 +0000 (18:27 +0200)
committerthomasv <thomasv@gitorious>
Tue, 10 Sep 2013 16:27:32 +0000 (18:27 +0200)
gui/gui_classic.py
gui/installwizard.py
gui/network_dialog.py
lib/blockchain.py
lib/network.py

index 15318e8..8b9d366 100644 (file)
@@ -1366,7 +1366,7 @@ class ElectrumWindow(QMainWindow):
         console.history = self.config.get("console-history",[])
         console.history_index = len(console.history)
 
-        console.updateNamespace({'wallet' : self.wallet, 'network' : self.wallet.network, 'gui':self})
+        console.updateNamespace({'wallet' : self.wallet, 'network' : self.network, 'gui':self})
         console.updateNamespace({'util' : util, 'bitcoin':bitcoin})
 
         c = commands.Commands(self.wallet, self.wallet.interface, lambda: self.console.set_json(True))
@@ -2230,7 +2230,7 @@ class ElectrumWindow(QMainWindow):
         self.receive_tab_set_mode(expert_cb.isChecked())
 
     def run_network_dialog(self):
-        NetworkDialog(self.wallet.interface, self.config, self).do_exec()
+        NetworkDialog(self.wallet.network, self.config, self).do_exec()
 
     def closeEvent(self, event):
         g = self.geometry()
index 6065735..8157936 100644 (file)
@@ -18,8 +18,6 @@ class InstallWizard(QDialog):
         QDialog.__init__(self)
         self.config = config
         self.network = network
-        self.interface = network.interface
-        self.blockchain = network.blockchain
         self.storage = storage
 
 
@@ -217,7 +215,7 @@ class InstallWizard(QDialog):
             return
         
         if b2.isChecked():
-            return NetworkDialog(self.interface, self.config, None).do_exec()
+            return NetworkDialog(self.network, self.config, None).do_exec()
 
         elif b1.isChecked():
             self.config.set_key('auto_cycle', True, True)
index b197ef3..d725253 100644 (file)
@@ -31,20 +31,21 @@ protocol_names = ['TCP', 'HTTP', 'SSL', 'HTTPS']
 protocol_letters = 'thsg'
 
 class NetworkDialog(QDialog):
-    def __init__(self, interface, config, parent):
+    def __init__(self, network, config, parent):
 
         QDialog.__init__(self,parent)
         self.setModal(1)
         self.setWindowTitle(_('Server'))
         self.setMinimumSize(375, 20)
 
-        self.interface = interface
+        self.network = network
+        self.interface = interface = network.interface
         self.config = config
         self.protocol = None
 
         if parent:
             if interface.is_connected:
-                status = _("Connected to")+" %s"%(interface.host) + "\n%d "%(parent.wallet.verifier.blockchain.height)+_("blocks")
+                status = _("Connected to")+" %s"%(interface.host) + "\n%d "%(network.blockchain.height)+_("blocks")
             else:
                 status = _("Not connected")
             server = interface.server
@@ -55,6 +56,7 @@ class NetworkDialog(QDialog):
 
         self.servers = interface.get_servers()
 
+
         vbox = QVBoxLayout()
         vbox.setSpacing(30)
 
index e16d916..5c2c13f 100644 (file)
@@ -24,10 +24,11 @@ from bitcoin import *
 
 class Blockchain(threading.Thread):
 
-    def __init__(self, config):
+    def __init__(self, config, network):
         threading.Thread.__init__(self)
         self.daemon = True
         self.config = config
+        self.network = network
         self.lock = threading.Lock()
         self.height = 0
         self.local_height = 0
@@ -35,6 +36,7 @@ class Blockchain(threading.Thread):
         self.headers_url = 'http://headers.electrum.org/blockchain_headers'
         self.set_local_height()
         self.queue = Queue.Queue()
+        self.servers_height = {}
 
     
     def stop(self):
@@ -63,12 +65,13 @@ class Blockchain(threading.Thread):
             if not result: continue
 
             i, result = result
-            header= result.get('result')
+            header = result.get('result')
             height = header.get('block_height')
+            self.servers_height[i.server] = height
 
             if height > self.local_height + 50:
                 self.get_chunks(i, header, height)
-                i.network.trigger_callback('updated')
+                self.network.trigger_callback('updated')
 
             if height > self.local_height:
                 # get missing parts from interface (until it connects to my chain)
@@ -87,8 +90,12 @@ class Blockchain(threading.Thread):
                     print_error("error", i.server)
                     # todo: dismiss that server
 
-                i.network.trigger_callback('updated')
+                self.network.trigger_callback('updated')
 
+            h = self.servers_height.get(self.network.interface.server)
+            if h is not None and h < height:
+                print "server is lagging", height - i.network.interface.height
+                self.network.interface.stop()
 
 
                     
index e8b869a..c7e09b3 100644 (file)
@@ -12,7 +12,7 @@ class Network(threading.Thread):
         self.daemon = True
         self.config = config
         self.lock = threading.Lock()
-        self.blockchain = Blockchain(config)
+        self.blockchain = Blockchain(config, self)
         self.interfaces = {}
         self.queue = Queue.Queue()
         self.default_server = self.config.get('server')