From 742ef564e1bf0d5b37a0e6a5d10ee0d9799ef55b Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 12 Sep 2019 01:28:20 -0500 Subject: [PATCH] fix some bytes for uploading --- onionr/communicatorutils/downloadblocks/__init__.py | 2 +- onionr/communicatorutils/lookupadders.py | 5 ++++- onionr/onionrblockapi.py | 4 ++-- onionr/onionrcrypto/cryptoutils/verifypow.py | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/onionr/communicatorutils/downloadblocks/__init__.py b/onionr/communicatorutils/downloadblocks/__init__.py index 02ce564c..7abf4c9e 100755 --- a/onionr/communicatorutils/downloadblocks/__init__.py +++ b/onionr/communicatorutils/downloadblocks/__init__.py @@ -77,7 +77,7 @@ def download_blocks_from_communicator(comm_inst): except AttributeError: pass if realHash == blockHash: - content = content.decode() # decode here because sha3Hash needs bytes above + #content = content.decode() # decode here because sha3Hash needs bytes above metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata metadata = metas[0] if validatemetadata.validate_metadata(metadata, metas[2]): # check if metadata is valid, and verify nonce diff --git a/onionr/communicatorutils/lookupadders.py b/onionr/communicatorutils/lookupadders.py index 9eed48bd..55060ea6 100755 --- a/onionr/communicatorutils/lookupadders.py +++ b/onionr/communicatorutils/lookupadders.py @@ -47,6 +47,9 @@ def lookup_new_peer_transports_with_communicator(comm_inst): # avoid adding if its our address invalid.append(x) for x in invalid: - newPeers.remove(x) + try: + newPeers.remove(x) + except ValueError: + pass comm_inst.newPeers.extend(newPeers) comm_inst.decrementThreadCount('lookup_new_peer_transports_with_communicator') \ No newline at end of file diff --git a/onionr/onionrblockapi.py b/onionr/onionrblockapi.py index 14ebbd52..f15347f0 100755 --- a/onionr/onionrblockapi.py +++ b/onionr/onionrblockapi.py @@ -72,8 +72,8 @@ class Block: try: try: self.bcontent = encryption.pub_key_decrypt(self.bcontent, encodedData=encodedData) - except binascii.Error: - self.bcontent = encryption.pub_key_decrypt(self.bcontent, encodedData=not encodedData) + except (binascii.Error, ValueError) as e: + self.bcontent = encryption.pub_key_decrypt(self.bcontent, encodedData=False) bmeta = encryption.pub_key_decrypt(self.bmetadata, encodedData=encodedData) try: bmeta = bmeta.decode() diff --git a/onionr/onionrcrypto/cryptoutils/verifypow.py b/onionr/onionrcrypto/cryptoutils/verifypow.py index 197281c2..b7c9e6c3 100644 --- a/onionr/onionrcrypto/cryptoutils/verifypow.py +++ b/onionr/onionrcrypto/cryptoutils/verifypow.py @@ -1,5 +1,6 @@ from .. import hashers import config, onionrproofs, logger +import onionrexceptions def verify_POW(blockContent): ''' Verifies the proof of work associated with a block @@ -31,6 +32,7 @@ def verify_POW(blockContent): retData = True else: logger.debug("Invalid token, bad proof") + raise onionrexceptions.InvalidProof('Proof for %s needs to be %s' % (blockHash, puzzle)) return retData