+ remove peers who do not meet the minimum score

* minor bug fixes and documentation improvements
* do not cleanup peers if we have no online peers (probably not
connected anyway)
* do not run peer cleanup until a min
* do not spam block list on shutdown during block sync
* use correct thread decrement in peerCleanup
* added trust int to address table, not used yet
This commit is contained in:
Kevin Froman 2018-08-03 01:28:26 -05:00
parent 032aa780ef
commit 8694ab078e
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
4 changed files with 27 additions and 11 deletions

View File

@ -77,6 +77,7 @@ class OnionrCommunicatorDaemon:
self.header()
# Set timers, function reference, seconds
# requiresPeer True means the timer function won't fire if we have no connected peers
OnionrCommunicatorTimers(self, self.daemonCommands, 5)
OnionrCommunicatorTimers(self, self.detectAPICrash, 5)
peerPoolTimer = OnionrCommunicatorTimers(self, self.getOnlinePeers, 60)
@ -85,11 +86,11 @@ class OnionrCommunicatorDaemon:
OnionrCommunicatorTimers(self, self.clearOfflinePeer, 58)
OnionrCommunicatorTimers(self, self.lookupKeys, 60, requiresPeer=True)
OnionrCommunicatorTimers(self, self.lookupAdders, 60, requiresPeer=True)
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300)
cleanupTimer = OnionrCommunicatorTimers(self, self.peerCleanup, 300, requiresPeer=True)
# set loop to execute instantly to load up peer pool (replaced old pool init wait)
peerPoolTimer.count = (peerPoolTimer.frequency - 1)
cleanupTimer = (cleanupTimer.frequency - 200)
cleanupTimer.count = (cleanupTimer.frequency - 60)
# Main daemon loop, mainly for calling timers, don't do any complex operations here to avoid locking
try:
@ -171,6 +172,8 @@ class OnionrCommunicatorDaemon:
def getBlocks(self):
'''download new blocks in queue'''
for blockHash in self.blockQueue:
if self.shutdown:
break
if blockHash in self.currentDownloading:
logger.debug('ALREADY DOWNLOADING ' + blockHash)
continue
@ -320,7 +323,7 @@ class OnionrCommunicatorDaemon:
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')
self.decrementThreadCount('peerCleanup')
def printOnlinePeers(self):
'''logs online peer list'''

View File

@ -200,7 +200,8 @@ class Core:
powValue text,
failure int,
lastConnect int,
lastConnectAttempt int
lastConnectAttempt int,
trust int
);
''')
conn.commit()

View File

@ -17,7 +17,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
import core
import core, config, logger
class PeerProfiles:
'''
PeerProfiles
@ -72,8 +72,20 @@ def getScoreSortedPeerList(coreInst):
return peerList
def peerCleanup(coreInst):
# TODO, remove peers that have been offline for too long
'''Removes peers who have been offline too long'''
if not type(coreInst is core.Core):
raise TypeError('coreInst must be instance of core.Core')
logger.info('Cleaning peers...')
minScore = int(config.get('peers.minimumScore'))
maxPeers = int(config.get('peers.maxStoredPeers'))
adders = getScoreSortedPeerList(coreInst)
adders.reverse()
for address in adders:
# Remove peers that go below the negative score
if PeerProfiles(address, coreInst).score < minScore:
coreInst.removeAddress(address)
logger.warn('Removed address ' + address + '.')

View File

@ -57,7 +57,7 @@
"blockCacheTotal" : 50000000
},
"peers":{
"minimumScore": 5,
"minimumScore": -4000,
"maxStoredPeers": 100,
"maxConnect": 3
}