Added mock code for class_objectProcessor, class_singleWorker, inventory, connectionpool & stats
This commit is contained in:
parent
971c79b3f5
commit
ed1c8ca100
50
src/mock/class_objectProcessor.py
Normal file
50
src/mock/class_objectProcessor.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
"""
|
||||
The objectProcessor thread, of which there is only one,
|
||||
processes the network objects
|
||||
"""
|
||||
import logging
|
||||
import random
|
||||
import threading
|
||||
|
||||
import queues
|
||||
import state
|
||||
|
||||
from helper_sql import sql_ready, sqlExecute, sqlQuery
|
||||
from network import bmproto
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
||||
class objectProcessor(threading.Thread):
|
||||
"""
|
||||
The objectProcessor thread, of which there is only one, receives network
|
||||
objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads.
|
||||
"""
|
||||
def __init__(self):
|
||||
threading.Thread.__init__(self, name="objectProcessor")
|
||||
random.seed()
|
||||
# It may be the case that the last time Bitmessage was running,
|
||||
# the user closed it before it finished processing everything in the
|
||||
# objectProcessorQueue. Assuming that Bitmessage wasn't closed
|
||||
# forcefully, it should have saved the data in the queue into the
|
||||
# objectprocessorqueue table. Let's pull it out.
|
||||
sql_ready.wait()
|
||||
queryreturn = sqlQuery(
|
||||
'SELECT objecttype, data FROM objectprocessorqueue')
|
||||
for objectType, data in queryreturn:
|
||||
queues.objectProcessorQueue.put((objectType, data))
|
||||
sqlExecute('DELETE FROM objectprocessorqueue')
|
||||
logger.debug(
|
||||
'Loaded %s objects from disk into the objectProcessorQueue.',
|
||||
len(queryreturn))
|
||||
self._ack_obj = bmproto.BMStringParser()
|
||||
self.successfullyDecryptMessageTimings = []
|
||||
|
||||
def run(self):
|
||||
"""Process the objects from `.queues.objectProcessorQueue`"""
|
||||
while True:
|
||||
objectType, data = queues.objectProcessorQueue.get()
|
||||
|
||||
if state.shutdown:
|
||||
state.shutdown = 2
|
||||
break
|
45
src/mock/class_singleWorker.py
Normal file
45
src/mock/class_singleWorker.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
"""
|
||||
Thread for performing PoW
|
||||
"""
|
||||
|
||||
from __future__ import division
|
||||
|
||||
import proofofwork
|
||||
import queues
|
||||
import state
|
||||
|
||||
from network import StoppableThread
|
||||
from six.moves import queue
|
||||
|
||||
|
||||
class MockSingleWorker(StoppableThread):
|
||||
"""Thread for performing PoW"""
|
||||
|
||||
def __init__(self):
|
||||
super(MockSingleWorker, self).__init__(name="singleWorker")
|
||||
proofofwork.init()
|
||||
|
||||
def stopThread(self):
|
||||
"""Signal through the queue that the thread should be stopped"""
|
||||
|
||||
try:
|
||||
queues.workerQueue.put(("stopThread", "data"))
|
||||
except queue.Full:
|
||||
self.logger.error('workerQueue is Full')
|
||||
super(MockSingleWorker, self).stopThread()
|
||||
|
||||
def run(self):
|
||||
|
||||
if state.shutdown > 0:
|
||||
return
|
||||
|
||||
while state.shutdown == 0:
|
||||
self.busy = 0
|
||||
command, data = queues.workerQueue.get()
|
||||
self.busy = 1
|
||||
if command == 'stopThread':
|
||||
self.busy = 0
|
||||
return
|
||||
|
||||
queues.workerQueue.task_done()
|
||||
self.logger.info("Quitting...")
|
14
src/mock/inventory.py
Normal file
14
src/mock/inventory.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
"""The Inventory singleton"""
|
||||
|
||||
# TODO make this dynamic, and watch out for frozen, like with messagetypes
|
||||
from singleton import Singleton
|
||||
|
||||
|
||||
@Singleton
|
||||
class MockInventory():
|
||||
"""
|
||||
Inventory singleton class which uses storage backends
|
||||
to manage the inventory.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.numberOfInventoryLookupsPerformed = 0
|
25
src/mock/network/connectionpool.py
Normal file
25
src/mock/network/connectionpool.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""
|
||||
`BMConnectionPool` class definition
|
||||
"""
|
||||
import logging
|
||||
|
||||
import asyncore_pollchoose as asyncore
|
||||
from bmconfigparser import BMConfigParser
|
||||
from singleton import Singleton
|
||||
|
||||
logger = logging.getLogger('default')
|
||||
|
||||
|
||||
@Singleton
|
||||
class MockBMConnectionPool(object):
|
||||
"""Pool of all existing connections"""
|
||||
|
||||
def __init__(self):
|
||||
asyncore.set_rates(
|
||||
BMConfigParser().safeGetInt(
|
||||
"bitmessagesettings", "maxdownloadrate"),
|
||||
BMConfigParser().safeGetInt(
|
||||
"bitmessagesettings", "maxuploadrate")
|
||||
)
|
||||
self.outboundConnections = {}
|
||||
self.inboundConnections = {}
|
13
src/mock/network/stats.py
Normal file
13
src/mock/network/stats.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
"""
|
||||
Network statistics
|
||||
"""
|
||||
|
||||
|
||||
def MockUploadSpeed():
|
||||
"""Getting upload speed"""
|
||||
return 0
|
||||
|
||||
|
||||
def MockDownloadSpeed():
|
||||
"""Getting download speed"""
|
||||
return 0
|
Reference in New Issue
Block a user