improved communicator threading

master
Kevin Froman 2018-05-04 21:07:43 -05:00
parent 72f104e447
commit d8b5127845
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 19 additions and 13 deletions

View File

@ -41,7 +41,8 @@ class OnionrCommunicate:
self.highFailureAmount = 7 self.highFailureAmount = 7
self.communicatorThreads = [] self.communicatorThreads = 0
self.maxThreads = 75
self.blocksProcessing = [] # list of blocks currently processing, to avoid trying a block twice at once in 2 seperate threads self.blocksProcessing = [] # list of blocks currently processing, to avoid trying a block twice at once in 2 seperate threads
self.peerStatus = {} # network actions (active requests) for peers used mainly to prevent conflicting actions in threads self.peerStatus = {} # network actions (active requests) for peers used mainly to prevent conflicting actions in threads
@ -63,7 +64,7 @@ class OnionrCommunicate:
highFailureRate = 10 highFailureRate = 10
heartBeatTimer = 0 heartBeatTimer = 0
heartBeatRate = 0 heartBeatRate = 0
pexTimer = 25 # How often we should check for new peers pexTimer = 120 # How often we should check for new peers
pexCount = 0 pexCount = 0
logger.debug('Communicator debugging enabled.') logger.debug('Communicator debugging enabled.')
torID = open('data/hs/hostname').read() torID = open('data/hs/hostname').read()
@ -108,6 +109,7 @@ class OnionrCommunicate:
pbT2 = threading.Thread(target=self.processBlocks, name='pbT2') pbT2 = threading.Thread(target=self.processBlocks, name='pbT2')
pbT3 = threading.Thread(target=self.processBlocks, name='pbT3') pbT3 = threading.Thread(target=self.processBlocks, name='pbT3')
pbT4 = threading.Thread(target=self.processBlocks, name='pbT4') pbT4 = threading.Thread(target=self.processBlocks, name='pbT4')
if (self.maxThreads - 8) >= threading.active_count():
lT1.start() lT1.start()
lT2.start() lT2.start()
lT3.start() lT3.start()
@ -116,6 +118,9 @@ class OnionrCommunicate:
pbT2.start() pbT2.start()
pbT3.start() pbT3.start()
pbT4.start() pbT4.start()
else:
logger.debug(threading.active_count())
logger.debug('Too many threads.')
blockProcessTimer = 0 blockProcessTimer = 0
if command != False: if command != False:
if command[0] == 'shutdown': if command[0] == 'shutdown':
@ -385,7 +390,7 @@ class OnionrCommunicate:
Get new peers and ed25519 keys Get new peers and ed25519 keys
''' '''
peersCheck = 5 # Amount of peers to ask for new peers + keys peersCheck = 2 # Amount of peers to ask for new peers + keys
peersChecked = 0 peersChecked = 0
peerList = list(self._core.listAdders()) # random ordered list of peers peerList = list(self._core.listAdders()) # random ordered list of peers
newKeys = [] newKeys = []
@ -512,7 +517,7 @@ class OnionrCommunicate:
for i in self._core.getBlockList(unsaved=True).split("\n"): for i in self._core.getBlockList(unsaved=True).split("\n"):
if i != "": if i != "":
if i in self.blocksProcessing or i in self.ignoredHashes: if i in self.blocksProcessing or i in self.ignoredHashes:
logger.debug('already processing ' + i) #logger.debug('already processing ' + i)
continue continue
else: else:
self.blocksProcessing.append(i) self.blocksProcessing.append(i)

View File

@ -357,7 +357,8 @@ class OnionrUtils:
try: try:
message = self._core._crypto.pubKeyDecrypt(message, encodedData=True, anonymous=True) message = self._core._crypto.pubKeyDecrypt(message, encodedData=True, anonymous=True)
except nacl.exceptions.CryptoError as e: except nacl.exceptions.CryptoError as e:
logger.error('Unable to decrypt ' + i, error=e) pass
#logger.error('Unable to decrypt ' + i, error=e)
else: else:
try: try:
message = json.loads(message.decode()) message = json.loads(message.decode())