2019-10-31 13:13:36 +01:00
|
|
|
"""Most of the queues used by bitmessage threads are defined here."""
|
|
|
|
|
|
|
|
import threading
|
|
|
|
import time
|
2021-07-07 21:08:45 +02:00
|
|
|
|
|
|
|
from six.moves import queue
|
2017-06-27 13:25:12 +02:00
|
|
|
|
2021-04-30 22:01:50 +02:00
|
|
|
try:
|
2021-03-04 15:15:41 +01:00
|
|
|
from multiqueue import MultiQueue
|
2021-04-30 22:01:50 +02:00
|
|
|
except ImportError:
|
|
|
|
from .multiqueue import MultiQueue
|
|
|
|
|
2019-10-31 13:13:36 +01:00
|
|
|
|
2021-07-07 21:08:45 +02:00
|
|
|
class ObjectProcessorQueue(queue.Queue):
|
2019-10-31 13:13:36 +01:00
|
|
|
"""Special queue class using lock for `.threads.objectProcessor`"""
|
|
|
|
|
|
|
|
maxSize = 32000000
|
|
|
|
|
|
|
|
def __init__(self):
|
2021-07-07 21:08:45 +02:00
|
|
|
queue.Queue.__init__(self)
|
2019-10-31 13:13:36 +01:00
|
|
|
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])
|
2021-07-07 21:08:45 +02:00
|
|
|
queue.Queue.put(self, item, block, timeout)
|
2019-10-31 13:13:36 +01:00
|
|
|
|
|
|
|
def get(self, block=True, timeout=None):
|
2021-07-07 21:08:45 +02:00
|
|
|
item = queue.Queue.get(self, block, timeout)
|
2019-10-31 13:13:36 +01:00
|
|
|
with self.sizeLock:
|
|
|
|
self.curSize -= len(item[1])
|
|
|
|
return item
|
|
|
|
|
|
|
|
|
2021-07-07 21:08:45 +02: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()
|
2021-07-07 21:08:45 +02:00
|
|
|
portCheckerQueue = queue.Queue()
|
|
|
|
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.
|
2021-07-07 21:08:45 +02:00
|
|
|
apiAddressGeneratorReturnQueue = queue.Queue()
|
2019-10-31 13:13:36 +01:00
|
|
|
#: for exceptions
|
2021-07-07 21:08:45 +02:00
|
|
|
excQueue = queue.Queue()
|