From 5f21d15cdd44283adf37459bf46b26ff6a3eb519 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 11 Aug 2018 00:23:59 -0500 Subject: [PATCH] + blocks can now be blacklisted * Peers sync a little better --- onionr/communicator2.py | 3 ++- onionr/core.py | 2 +- onionr/onionr.py | 22 +++++++++++++++------- onionr/onionrblacklist.py | 1 - 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index b3af1d0f..53edda76 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -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''' diff --git a/onionr/core.py b/onionr/core.py index 76f55652..440f31e0 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -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) diff --git a/onionr/onionr.py b/onionr/onionr.py index c6357089..1736c3f9 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -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): - self.onionrCore._blacklist.addToDB(ban) - + 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') diff --git a/onionr/onionrblacklist.py b/onionr/onionrblacklist.py index 52d0957b..056aafb6 100644 --- a/onionr/onionrblacklist.py +++ b/onionr/onionrblacklist.py @@ -25,7 +25,6 @@ class OnionrBlackList: if not os.path.exists(self.blacklistDB): self.generateDB() - return def inBlacklist(self, data):