refactored lookup timer calls in communicator

This commit is contained in:
Kevin Froman 2019-08-11 15:44:16 -05:00
parent 00e2445475
commit 0e9da24d79
3 changed files with 4 additions and 12 deletions

View File

@ -102,7 +102,7 @@ class OnionrCommunicatorDaemon:
OnionrCommunicatorTimers(self, self.runCheck, 2, maxThreads=1) OnionrCommunicatorTimers(self, self.runCheck, 2, maxThreads=1)
# Timers to periodically lookup new blocks and download them # Timers to periodically lookup new blocks and download them
OnionrCommunicatorTimers(self, self.lookupBlocks, config.get('timers.lookupBlocks', 25), requiresPeer=True, maxThreads=1) OnionrCommunicatorTimers(self, lookupblocks.lookup_blocks_from_communicator, config.get('timers.lookupBlocks', 25), myArgs=[self], requiresPeer=True, maxThreads=1)
OnionrCommunicatorTimers(self, self.getBlocks, config.get('timers.getBlocks', 30), requiresPeer=True, maxThreads=2) OnionrCommunicatorTimers(self, self.getBlocks, config.get('timers.getBlocks', 30), requiresPeer=True, maxThreads=2)
# Timer to reset the longest offline peer so contact can be attempted again # Timer to reset the longest offline peer so contact can be attempted again
@ -112,7 +112,7 @@ class OnionrCommunicatorDaemon:
blockCleanupTimer = OnionrCommunicatorTimers(self, housekeeping.clean_old_blocks, 65, myArgs=[self]) blockCleanupTimer = OnionrCommunicatorTimers(self, housekeeping.clean_old_blocks, 65, myArgs=[self])
# Timer to discover new peers # Timer to discover new peers
OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True) OnionrCommunicatorTimers(self, lookupadders.lookup_new_peer_transports_with_communicator, 60, requiresPeer=True, myArgs=[self], maxThreads=2)
# Timer for adjusting which peers we actively communicate to at any given time, to avoid over-using peers # Timer for adjusting which peers we actively communicate to at any given time, to avoid over-using peers
OnionrCommunicatorTimers(self, cooldownpeer.cooldown_peer, 30, myArgs=[self], requiresPeer=True) OnionrCommunicatorTimers(self, cooldownpeer.cooldown_peer, 30, myArgs=[self], requiresPeer=True)
@ -190,14 +190,6 @@ class OnionrCommunicatorDaemon:
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
def lookupAdders(self):
'''Lookup new peer addresses'''
lookupadders.lookup_new_peer_transports_with_communicator(self)
def lookupBlocks(self):
'''Lookup new blocks & add them to download queue'''
lookupblocks.lookup_blocks_from_communicator(self)
def getBlocks(self): def getBlocks(self):
'''download new blocks in queue''' '''download new blocks in queue'''
downloadblocks.download_blocks_from_communicator(self) downloadblocks.download_blocks_from_communicator(self)

View File

@ -49,4 +49,4 @@ def lookup_new_peer_transports_with_communicator(comm_inst):
for x in invalid: for x in invalid:
newPeers.remove(x) newPeers.remove(x)
comm_inst.newPeers.extend(newPeers) comm_inst.newPeers.extend(newPeers)
comm_inst.decrementThreadCount('lookupAdders') comm_inst.decrementThreadCount('lookup_new_peer_transports_with_communicator')

View File

@ -89,5 +89,5 @@ def lookup_blocks_from_communicator(comm_inst):
if new_block_count > 1: if new_block_count > 1:
block_string = "s" block_string = "s"
logger.info('Discovered %s new block%s' % (new_block_count, block_string), terminal=True) logger.info('Discovered %s new block%s' % (new_block_count, block_string), terminal=True)
comm_inst.decrementThreadCount('lookupBlocks') comm_inst.decrementThreadCount('lookup_blocks_from_communicator')
return return