work on peer cleanup
parent
d22701199c
commit
8bb5014d41
|
@ -85,7 +85,7 @@ class OnionrCommunicatorDaemon:
|
|||
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
|
||||
OnionrCommunicatorTimers(self, self.lookupKeys, 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)
|
||||
peerPoolTimer.count = (peerPoolTimer.frequency - 1)
|
||||
|
@ -315,6 +315,11 @@ class OnionrCommunicatorDaemon:
|
|||
logger.debug('Failed to connect to ' + address)
|
||||
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):
|
||||
'''logs online peer list'''
|
||||
if len(self.onlinePeers) == 0:
|
||||
|
|
|
@ -199,7 +199,8 @@ class Core:
|
|||
DBHash text,
|
||||
powValue text,
|
||||
failure int,
|
||||
lastConnect int
|
||||
lastConnect int,
|
||||
lastConnectAttempt int
|
||||
);
|
||||
''')
|
||||
conn.commit()
|
||||
|
@ -573,7 +574,7 @@ class Core:
|
|||
c = conn.cursor()
|
||||
command = (data, address)
|
||||
# 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")
|
||||
else:
|
||||
c.execute('UPDATE adders SET ' + key + ' = ? WHERE address=?', command)
|
||||
|
|
|
@ -71,6 +71,9 @@ def getScoreSortedPeerList(coreInst):
|
|||
peerList = sorted(peerScores, key=peerScores.get, reverse=True)
|
||||
return peerList
|
||||
|
||||
def peerCleanup():
|
||||
def peerCleanup(coreInst):
|
||||
# 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')
|
||||
|
||||
|
Loading…
Reference in New Issue