2019-10-31 13:13:36 +01:00
|
|
|
"""Most of the queues used by bitmessage threads are defined here."""
|
|
|
|
|
2017-02-08 13:41:56 +01:00
|
|
|
import Queue
|
2019-10-31 13:13:36 +01:00
|
|
|
import threading
|
|
|
|
import time
|
2017-06-27 13:25:12 +02:00
|
|
|
|
|
|
|
from multiqueue import MultiQueue
|
2017-02-08 13:41:56 +01:00
|
|
|
|
2019-10-31 13:13:36 +01:00
|
|
|
|
|
|
|
class ObjectProcessorQueue(Queue.Queue):
|
|
|
|
"""Special queue class using lock for `.threads.objectProcessor`"""
|
|
|
|
|
|
|
|
maxSize = 32000000
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
Queue.Queue.__init__(self)
|
|
|
|
self.sizeLock = threading.Lock()
|
|
|
|
#: in Bytes. We maintain this to prevent nodes from flooding us
|
|
|
|
#: with objects which take up too much memory. If this gets
|
|
|
|
#: too big we'll sleep before asking for further objects.
|
|
|
|
self.curSize = 0
|
|
|
|
|
|
|
|
def put(self, item, block=True, timeout=None):
|
|
|
|
while self.curSize >= self.maxSize:
|
|
|
|
time.sleep(1)
|
|
|
|
with self.sizeLock:
|
|
|
|
self.curSize += len(item[1])
|
|
|
|
Queue.Queue.put(self, item, block, timeout)
|
|
|
|
|
|
|
|
def get(self, block=True, timeout=None):
|
|
|
|
item = Queue.Queue.get(self, block, timeout)
|
|
|
|
with self.sizeLock:
|
|
|
|
self.curSize -= len(item[1])
|
|
|
|
return item
|
|
|
|
|
|
|
|
|
2017-02-08 13:41:56 +01:00
|
|
|
workerQueue = Queue.Queue()
|
|
|
|
UISignalQueue = Queue.Queue()
|
|
|
|
addressGeneratorQueue = Queue.Queue()
|
2019-11-06 10:38:42 +01:00
|
|
|
#: `.network.ReceiveQueueThread` instances dump objects they hear
|
|
|
|
#: on the network into this queue to be processed.
|
2017-02-08 13:41:56 +01:00
|
|
|
objectProcessorQueue = ObjectProcessorQueue()
|
2017-06-27 13:25:12 +02:00
|
|
|
invQueue = MultiQueue()
|
|
|
|
addrQueue = MultiQueue()
|
2017-05-25 14:59:18 +02:00
|
|
|
portCheckerQueue = Queue.Queue()
|
2017-07-06 19:45:36 +02:00
|
|
|
receiveDataQueue = Queue.Queue()
|
2019-10-31 13:13:36 +01:00
|
|
|
#: The address generator thread uses this queue to get information back
|
|
|
|
#: to the API thread.
|
2018-10-03 17:42:12 +02:00
|
|
|
apiAddressGeneratorReturnQueue = Queue.Queue()
|
2019-10-31 13:13:36 +01:00
|
|
|
#: for exceptions
|
2018-10-03 17:42:12 +02:00
|
|
|
excQueue = Queue.Queue()
|