work on fixing weird upload issues
parent
fbcb95be9e
commit
57225f57f0
|
@ -90,6 +90,11 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
|
||||||
url = f'http://{peer}/upload'
|
url = f'http://{peer}/upload'
|
||||||
try:
|
try:
|
||||||
data = block.Block(bl).getRaw()
|
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:
|
except onionrexceptions.NoDataAvailable:
|
||||||
finishedUploads.append(bl)
|
finishedUploads.append(bl)
|
||||||
break
|
break
|
||||||
|
|
|
@ -35,8 +35,11 @@ def accept_upload(request):
|
||||||
"""Accept uploaded blocks to our public Onionr protocol API server"""
|
"""Accept uploaded blocks to our public Onionr protocol API server"""
|
||||||
resp = 'failure'
|
resp = 'failure'
|
||||||
data = request.get_data()
|
data = request.get_data()
|
||||||
b_hash = ''
|
data_size = sys.getsizeof(data)
|
||||||
if sys.getsizeof(data) < 100000000:
|
print(data)
|
||||||
|
if data_size < 30:
|
||||||
|
resp = 'size'
|
||||||
|
elif data_size < 100000000:
|
||||||
try:
|
try:
|
||||||
b_hash = blockimporter.import_block_from_data(data)
|
b_hash = blockimporter.import_block_from_data(data)
|
||||||
if b_hash:
|
if b_hash:
|
||||||
|
@ -70,6 +73,10 @@ def accept_upload(request):
|
||||||
resp = 'failure'
|
resp = 'failure'
|
||||||
if resp == 'failure':
|
if resp == 'failure':
|
||||||
abort(400)
|
abort(400)
|
||||||
|
elif resp == 'size':
|
||||||
|
resp = Response(resp, 400)
|
||||||
|
logger.warn(
|
||||||
|
f'Error importing uploaded block, invalid size {b_hash}')
|
||||||
elif resp == 'proof':
|
elif resp == 'proof':
|
||||||
resp = Response(resp, 400)
|
resp = Response(resp, 400)
|
||||||
logger.warn(
|
logger.warn(
|
||||||
|
|
|
@ -6,6 +6,7 @@ from json import JSONDecodeError
|
||||||
import ujson as json
|
import ujson as json
|
||||||
|
|
||||||
from onionrutils import bytesconverter
|
from onionrutils import bytesconverter
|
||||||
|
import logger
|
||||||
"""
|
"""
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
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')]))
|
metadata = json.loads(bytesconverter.bytes_to_str(block_data[:block_data.find(b'\n')]))
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
|
except ValueError:
|
||||||
|
logger.warn("Could not get metadata from:", terminal=True)
|
||||||
|
logger.warn(block_data, terminal=True)
|
||||||
else:
|
else:
|
||||||
data = block_data[block_data.find(b'\n'):]
|
data = block_data[block_data.find(b'\n'):]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue