From 503bf65cbef10366ac8c2190db38e11d1f2da479 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 10 Oct 2020 02:51:04 +0000 Subject: [PATCH] fix error on deletion or upload of plaintext blocks to node that does not support it --- src/onionrblocks/onionrblockapi.py | 23 ----------------------- src/onionrutils/validatemetadata.py | 6 ++++++ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/onionrblocks/onionrblockapi.py b/src/onionrblocks/onionrblockapi.py index b4390ca9..85f0384c 100755 --- a/src/onionrblocks/onionrblockapi.py +++ b/src/onionrblocks/onionrblockapi.py @@ -202,33 +202,10 @@ class Block: except Exception as e: logger.warn('Failed to parse block %s' % self.getHash(), error = e, timestamp = False) - # if block can't be parsed, it's a waste of precious space. Throw it away. - if not self.delete(): - logger.warn('Failed to delete invalid block %s.' % self.getHash(), error = e) - else: - logger.debug('Deleted invalid block %s.' % self.getHash(), timestamp = False) self.valid = False return False - def delete(self): - """ - Deletes the block's file and records, if they exist - - Outputs: - - (bool): whether or not the operation was successful - """ - - if self.exists(): - try: - os.remove(self.getBlockFile()) - except TypeError: - pass - b_hash = self.getHash() - onionrstorage.deleteBlock(b_hash) - removeblock.remove_block(b_hash) - return True - return False def save(self, sign = False, recreate = True): """ diff --git a/src/onionrutils/validatemetadata.py b/src/onionrutils/validatemetadata.py index 3b4f31cf..11970bdc 100644 --- a/src/onionrutils/validatemetadata.py +++ b/src/onionrutils/validatemetadata.py @@ -97,6 +97,12 @@ def validate_metadata(metadata, block_data) -> bool: # make sure we do not have another block with the same data content (prevent data duplication and replay attacks) # Make sure time is set (validity was checked above if it is) + if not config.get('general.store_plaintext_blocks', True): + try: + if not metadata['encryptType']: + raise onionrexceptions.DataExists + except KeyError: + raise onionrexceptions.DataExists try: metadata['time'] except KeyError: