+ blocks can now be blacklisted

* Peers sync a little better
master
Kevin Froman 2018-08-11 00:23:59 -05:00
parent 12d39393b4
commit 5f21d15cdd
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
4 changed files with 18 additions and 10 deletions

View File

@ -173,7 +173,7 @@ class OnionrCommunicatorDaemon:
# if newline seperated string is valid hash
if not i in existingBlocks:
# if block does not exist on disk and is not already in block queue
if i not in self.blockQueue:
if i not in self.blockQueue and not self._core._blacklist.inBlacklist(i):
self.blockQueue.append(i)
self.decrementThreadCount('lookupBlocks')
return
@ -289,6 +289,7 @@ class OnionrCommunicatorDaemon:
for i in self._core.bootstrapList:
if i not in peerList and i not in self.offlinePeers and i != self._core.hsAddress:
peerList.append(i)
self._core.addAddress(i)
def connectNewPeer(self, peer='', useBootstrap=False):
'''Adds a new random online peer to self.onlinePeers'''

View File

@ -172,7 +172,7 @@ class Core:
def removeBlock(self, block):
'''
remove a block from this node
remove a block from this node (does not automatically blacklist)
'''
if self._utils.validateHash(block):
conn = sqlite3.connect(self.blockDB)

View File

@ -232,6 +232,7 @@ class Onionr:
'listconn': 'list connected peers',
'kex': 'exchange keys with peers (done automatically)',
'pex': 'exchange addresses with peers (done automatically)',
'blacklist-block': 'deletes a block by hash and permanently removes it from your node',
'introduce': 'Introduce your node to the public Onionr network',
}
@ -264,15 +265,22 @@ class Onionr:
try:
ban = sys.argv[2]
except IndexError:
while True:
ban = logger.readline('Enter a block hash:')
if self.onionrUtils.validateHash(ban):
if not self.onionrCore._blacklist.inBlacklist(ban):
try:
self.onionrCore._blacklist.addToDB(ban)
self.onionrCore.removeBlock(ban)
except Exception as error:
logger.error('Could not blacklist block', error=error)
else:
logger.info('Block blacklisted')
else:
logger.warn('That block is already blacklisted')
else:
logger.error('Invalid block hash')
return
def listConn(self):
self.onionrCore.daemonQueueAdd('connectedPeers')

View File

@ -25,7 +25,6 @@ class OnionrBlackList:
if not os.path.exists(self.blacklistDB):
self.generateDB()
return
def inBlacklist(self, data):