work on peer cleanup

master
Kevin Froman 2018-08-02 02:28:26 -05:00
parent d22701199c
commit 8bb5014d41
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 14 additions and 5 deletions

View File

@ -85,7 +85,7 @@ class OnionrCommunicatorDaemon:
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58) OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True) OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True) OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True)
cleanupTimer = OnionrCommunicatorTimers(self, onionrpeers.peerCleanup, 300) cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300)
# set loop to execute instantly to load up peer pool (replaced old pool init wait) # set loop to execute instantly to load up peer pool (replaced old pool init wait)
peerPoolTimer.count = (peerPoolTimer.frequency - 1) peerPoolTimer.count = (peerPoolTimer.frequency - 1)
@ -315,6 +315,11 @@ class OnionrCommunicatorDaemon:
logger.debug('Failed to connect to ' + address) logger.debug('Failed to connect to ' + address)
return retData return retData
def peerCleanup(self):
'''This just calls onionrpeers.cleanupPeers, which removes dead or bad peers (offline too long, too slow)'''
onionrpeers.peerCleanup(self._core)
self.decrementThreadCount('getOnlinePeers')
def printOnlinePeers(self): def printOnlinePeers(self):
'''logs online peer list''' '''logs online peer list'''
if len(self.onlinePeers) == 0: if len(self.onlinePeers) == 0:

View File

@ -199,7 +199,8 @@ class Core:
DBHash text, DBHash text,
powValue text, powValue text,
failure int, failure int,
lastConnect int lastConnect int,
lastConnectAttempt int
); );
''') ''')
conn.commit() conn.commit()
@ -573,7 +574,7 @@ class Core:
c = conn.cursor() c = conn.cursor()
command = (data, address) command = (data, address)
# TODO: validate key on whitelist # TODO: validate key on whitelist
if key not in ('address', 'type', 'knownPeer', 'speed', 'success', 'DBHash', 'failure', 'lastConnect'): if key not in ('address', 'type', 'knownPeer', 'speed', 'success', 'DBHash', 'failure', 'lastConnect', 'lastConnectAttempt'):
raise Exception("Got invalid database key when setting address info") raise Exception("Got invalid database key when setting address info")
else: else:
c.execute('UPDATE adders SET ' + key + ' = ? WHERE address=?', command) c.execute('UPDATE adders SET ' + key + ' = ? WHERE address=?', command)

View File

@ -71,6 +71,9 @@ def getScoreSortedPeerList(coreInst):
peerList = sorted(peerScores, key=peerScores.get, reverse=True) peerList = sorted(peerScores, key=peerScores.get, reverse=True)
return peerList return peerList
def peerCleanup(): def peerCleanup(coreInst):
# TODO, remove peers that have been offline for too long # TODO, remove peers that have been offline for too long
return if not type(coreInst is core.Core):
raise TypeError('coreInst must be instance of core.Core')