|
| 1 | +""" |
| 2 | +The objectProcessor thread, of which there is only one, |
| 3 | +processes the network objects |
| 4 | +""" |
| 5 | +import logging |
| 6 | +import random |
| 7 | +import threading |
| 8 | + |
| 9 | +import queues |
| 10 | +import state |
| 11 | + |
| 12 | +from helper_sql import sql_ready, sqlExecute, sqlQuery |
| 13 | +from network import bmproto |
| 14 | + |
| 15 | +logger = logging.getLogger('default') |
| 16 | + |
| 17 | + |
| 18 | +class objectProcessor(threading.Thread): |
| 19 | + """ |
| 20 | + The objectProcessor thread, of which there is only one, receives network |
| 21 | + objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads. |
| 22 | + """ |
| 23 | + def __init__(self): |
| 24 | + threading.Thread.__init__(self, name="objectProcessor") |
| 25 | + random.seed() |
| 26 | + # It may be the case that the last time Bitmessage was running, |
| 27 | + # the user closed it before it finished processing everything in the |
| 28 | + # objectProcessorQueue. Assuming that Bitmessage wasn't closed |
| 29 | + # forcefully, it should have saved the data in the queue into the |
| 30 | + # objectprocessorqueue table. Let's pull it out. |
| 31 | + sql_ready.wait() |
| 32 | + queryreturn = sqlQuery( |
| 33 | + 'SELECT objecttype, data FROM objectprocessorqueue') |
| 34 | + for objectType, data in queryreturn: |
| 35 | + queues.objectProcessorQueue.put((objectType, data)) |
| 36 | + sqlExecute('DELETE FROM objectprocessorqueue') |
| 37 | + logger.debug( |
| 38 | + 'Loaded %s objects from disk into the objectProcessorQueue.', |
| 39 | + len(queryreturn)) |
| 40 | + self._ack_obj = bmproto.BMStringParser() |
| 41 | + self.successfullyDecryptMessageTimings = [] |
| 42 | + |
| 43 | + def run(self): |
| 44 | + """Process the objects from `.queues.objectProcessorQueue`""" |
| 45 | + while True: |
| 46 | + objectType, data = queues.objectProcessorQueue.get() |
| 47 | + |
| 48 | + if state.shutdown: |
| 49 | + state.shutdown = 2 |
| 50 | + break |
0 commit comments