* punish peers that share invalid blocks

* fixed profile crash
This commit is contained in:
Kevin Froman 2018-08-03 15:01:13 -05:00
parent 8694ab078e
commit 0a2fe2a0b1
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 6 additions and 1 deletions

View File

@ -179,7 +179,8 @@ class OnionrCommunicatorDaemon:
continue
self.currentDownloading.append(blockHash)
logger.info("Attempting to download %s..." % blockHash)
content = self.peerAction(self.pickOnlinePeer(), 'getData', data=blockHash) # block content from random peer (includes metadata)
peerUsed = self.pickOnlinePeer()
content = self.peerAction(peerUsed, 'getData', data=blockHash) # block content from random peer (includes metadata)
if content != False:
try:
content = content.encode()
@ -213,6 +214,8 @@ class OnionrCommunicatorDaemon:
tempHash = tempHash.decode()
except AttributeError:
pass
# Punish peer for sharing invalid block (not always malicious, but is bad regardless)
onionrpeers.PeerProfiles(peerUsed, self._core).addScore(-50)
logger.warn('Block hash validation failed for ' + blockHash + ' got ' + tempHash)
self.blockQueue.remove(blockHash) # remove from block queue both if success or false
self.currentDownloading.remove(blockHash)
@ -424,6 +427,7 @@ class OnionrCommunicatorDaemon:
triedPeers.append(peer)
url = 'http://' + peer + '/public/upload/'
data = {'block': block.Block(self.blockToUpload).getRaw()}
proxyType = ''
if peer.endswith('.onion'):
proxyType = 'tor'
elif peer.endswith('.i2p'):

View File

@ -77,6 +77,7 @@ def peerCleanup(coreInst):
raise TypeError('coreInst must be instance of core.Core')
logger.info('Cleaning peers...')
config.reload()
minScore = int(config.get('peers.minimumScore'))
maxPeers = int(config.get('peers.maxStoredPeers'))