diff --git a/src/communicatorutils/uploadblocks/__init__.py b/src/communicatorutils/uploadblocks/__init__.py index f9188105..280e29d9 100755 --- a/src/communicatorutils/uploadblocks/__init__.py +++ b/src/communicatorutils/uploadblocks/__init__.py @@ -90,6 +90,11 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'): url = f'http://{peer}/upload' try: data = block.Block(bl).getRaw() + if not data: + logger.warn( + f"Couldn't data for block in upload list {bl}", + terminal=True) + raise onionrexceptions.NoDataAvailable except onionrexceptions.NoDataAvailable: finishedUploads.append(bl) break diff --git a/src/httpapi/miscpublicapi/upload.py b/src/httpapi/miscpublicapi/upload.py index da2609ad..faad4fe8 100755 --- a/src/httpapi/miscpublicapi/upload.py +++ b/src/httpapi/miscpublicapi/upload.py @@ -35,8 +35,11 @@ def accept_upload(request): """Accept uploaded blocks to our public Onionr protocol API server""" resp = 'failure' data = request.get_data() - b_hash = '' - if sys.getsizeof(data) < 100000000: + data_size = sys.getsizeof(data) + print(data) + if data_size < 30: + resp = 'size' + elif data_size < 100000000: try: b_hash = blockimporter.import_block_from_data(data) if b_hash: @@ -70,6 +73,10 @@ def accept_upload(request): resp = 'failure' if resp == 'failure': abort(400) + elif resp == 'size': + resp = Response(resp, 400) + logger.warn( + f'Error importing uploaded block, invalid size {b_hash}') elif resp == 'proof': resp = Response(resp, 400) logger.warn( diff --git a/src/onionrutils/blockmetadata/fromdata.py b/src/onionrutils/blockmetadata/fromdata.py index 4b5b0cc8..6c98b282 100644 --- a/src/onionrutils/blockmetadata/fromdata.py +++ b/src/onionrutils/blockmetadata/fromdata.py @@ -6,6 +6,7 @@ from json import JSONDecodeError import ujson as json from onionrutils import bytesconverter +import logger """ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -40,6 +41,9 @@ def get_block_metadata_from_data(block_data): metadata = json.loads(bytesconverter.bytes_to_str(block_data[:block_data.find(b'\n')])) except JSONDecodeError: pass + except ValueError: + logger.warn("Could not get metadata from:", terminal=True) + logger.warn(block_data, terminal=True) else: data = block_data[block_data.find(b'\n'):]