From acd5494979f57ff88a4f853d67d55e0299c2e470 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Wed, 25 Apr 2018 18:21:43 -0500 Subject: [PATCH] fixed wrong var used for peer causing crash --- onionr/communicator.py | 4 ++-- onionr/core.py | 5 +++++ onionr/onionr.py | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/onionr/communicator.py b/onionr/communicator.py index 79719ceb..214b6a1f 100755 --- a/onionr/communicator.py +++ b/onionr/communicator.py @@ -83,7 +83,7 @@ class OnionrCommunicate: if highFailureTimer == highFailureRate: highFailureTimer = 0 for i in self.peerData: - if self.peerData[i]['failCount'] == self.highFailureAmount: + if self.peerData[i]['failCount'] >= self.highFailureAmount: self.peerData[i]['failCount'] -= 1 if pexTimer == pexCount: self.getNewPeers() @@ -204,7 +204,7 @@ class OnionrCommunicate: blocks += self.performGet('getBlockHashes', i) except TypeError: logger.warn('Failed to get data hash from ' + i) - self.peerData[peer]['failCount'] -= 1 + self.peerData[i]['failCount'] -= 1 if self._utils.validateHash(currentDB): self._core.setAddressInfo(i, "DBHash", currentDB) if len(blocks.strip()) != 0: diff --git a/onionr/core.py b/onionr/core.py index cd3e4b6c..289f6c00 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -595,6 +595,11 @@ class Core: ''' retData = '' metadata = '-' + header + '-' + metadata = metadata.encode() + try: + data.decode() + except AttributeError: + data = data.encode() if len(data) == 0: logger.error('Will not insert empty block') else: diff --git a/onionr/onionr.py b/onionr/onionr.py index 179a9bbc..7fdc5be8 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -572,13 +572,13 @@ class Onionr: newFile = sys.argv[2] logger.info('Attempting to add file...') try: - with open(newFile, 'r') as new: + with open(newFile, 'rb') as new: new = new.read() except FileNotFoundError: logger.warn('That file does not exist. Improper path?') else: logger.debug(new) - self.onionrCore.insertBlock(new, header='bin') + logger.info(self.onionrCore.insertBlock(new, header='bin')) Onionr()