add a sleep() to sessions, and remove some dead code
authorThomasV <thomasv@gitorious>
Wed, 4 Dec 2013 11:24:01 +0000 (15:24 +0400)
committerThomasV <thomasv@gitorious>
Wed, 4 Dec 2013 11:24:01 +0000 (15:24 +0400)
processor.py
transports/stratum_tcp.py

index 9210fd6..9151936 100644 (file)
@@ -80,8 +80,6 @@ class RequestDispatcher(threading.Thread):
         self.daemon = True
         self.request_queue = queue.Queue()
         self.response_queue = queue.Queue()
-        self.internal_ids = {}
-        self.internal_id = 1
         self.lock = threading.Lock()
         self.idlock = threading.Lock()
         self.sessions = []
@@ -99,22 +97,6 @@ class RequestDispatcher(threading.Thread):
     def pop_request(self):
         return self.request_queue.get()
 
-    def get_session_by_address(self, address):
-        for x in self.sessions:
-            if x.address == address:
-                return x
-
-    def get_session_id(self, internal_id):
-        with self.idlock:
-            return self.internal_ids.pop(internal_id)
-
-    def store_session_id(self, session, msgid):
-        with self.idlock:
-            self.internal_ids[self.internal_id] = session, msgid
-            r = self.internal_id
-            self.internal_id += 1
-            return r
-
     def run(self):
         if self.shared is None:
             raise TypeError("self.shared not set in Processor")
index a1ac042..6ae2940 100644 (file)
@@ -144,6 +144,8 @@ class TcpClientRequestor(threading.Thread):
             self.dispatcher.push_response({"error": "syntax error", "request": raw_command})
         else:
             self.dispatcher.push_request(self.session, command)
+            # sleep a bit to prevent a single session from DOSing the queue
+            time.sleep(0.01)
 
         return True