do not queue requests that can be answered using the cache
[electrum-server.git] / processor.py
index 839a770..dfe6128 100644 (file)
@@ -40,6 +40,9 @@ class Processor(threading.Thread):
     def process(self, request):
         pass
 
+    def add_request(self, request):
+        self.queue.put(request)
+
     def push_response(self, response):
         #print "response", response
         self.dispatcher.request_dispatcher.push_response(response)
@@ -139,10 +142,7 @@ class RequestDispatcher(threading.Thread):
         params = request.get('params',[])
         suffix = method.split('.')[-1]
 
-        try:
-            is_new = float(session.version) >= 1.3
-        except:
-            is_new = False
+        is_new = session.protocol_version >= 0.5
 
         if is_new and method == 'blockchain.address.get_history': 
             method = 'blockchain.address.get_history2'
@@ -165,10 +165,14 @@ class RequestDispatcher(threading.Thread):
             print "error: no processor for", prefix
             return
 
-        p.queue.put(request)
+        p.add_request(request)
 
         if method in ['server.version']:
             session.version = params[0]
+            try:
+                session.protocol_version = float(params[1])
+            except:
+                pass
 
     def get_sessions(self):
         with self.lock:
@@ -201,6 +205,7 @@ class Session:
         self.address = ''
         self.name = ''
         self.version = 'unknown'
+        self.protocol_version = 0.
         self.time = time.time()
         threading.Timer(2, self.info).start()
 
@@ -283,6 +288,8 @@ class ResponseDispatcher(threading.Thread):
             if session.stopped():
                 continue
             if session.contains_subscription(subdesc):
+                if response.get('method') == "blockchain.address.subscribe2":
+                    response['method'] = "blockchain.address.subscribe"
                 session.send_response(response)
 
     def send_response(self, internal_id, response):