fixed uploads with bytes
This commit is contained in:
parent
742ef564e1
commit
48f111021b
@ -26,16 +26,16 @@ def importBlockFromData(content):
|
|||||||
blacklist = onionrblacklist.OnionrBlackList()
|
blacklist = onionrblacklist.OnionrBlackList()
|
||||||
retData = False
|
retData = False
|
||||||
|
|
||||||
dataHash = crypto.hashers.sha3_hash(content)
|
|
||||||
|
|
||||||
if blacklist.inBlacklist(dataHash):
|
|
||||||
raise onionrexceptions.BlacklistedBlock('%s is a blacklisted block' % (dataHash,))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
content = content.encode()
|
content = content.encode()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
dataHash = crypto.hashers.sha3_hash(content)
|
||||||
|
|
||||||
|
if blacklist.inBlacklist(dataHash):
|
||||||
|
raise onionrexceptions.BlacklistedBlock('%s is a blacklisted block' % (dataHash,))
|
||||||
|
|
||||||
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
metas = blockmetadata.get_block_metadata_from_data(content) # returns tuple(metadata, meta), meta is also in metadata
|
||||||
metadata = metas[0]
|
metadata = metas[0]
|
||||||
if validatemetadata.validate_metadata(metadata, metas[2]): # check if metadata is valid
|
if validatemetadata.validate_metadata(metadata, metas[2]): # check if metadata is valid
|
||||||
@ -49,4 +49,6 @@ def importBlockFromData(content):
|
|||||||
blockmetadb.add_to_block_DB(blockHash, dataSaved=True)
|
blockmetadb.add_to_block_DB(blockHash, dataSaved=True)
|
||||||
blockmetadata.process_block_metadata(blockHash) # caches block metadata values to block database
|
blockmetadata.process_block_metadata(blockHash) # caches block metadata values to block database
|
||||||
retData = True
|
retData = True
|
||||||
|
else:
|
||||||
|
raise onionrexceptions.InvalidProof
|
||||||
return retData
|
return retData
|
@ -44,19 +44,22 @@ def upload_blocks_from_communicator(comm_inst):
|
|||||||
triedPeers.append(peer)
|
triedPeers.append(peer)
|
||||||
url = 'http://' + peer + '/upload'
|
url = 'http://' + peer + '/upload'
|
||||||
try:
|
try:
|
||||||
data = {'block': block.Block(bl).getRaw()}
|
#data = {'block': block.Block(bl).getRaw()}
|
||||||
|
data = block.Block(bl).getRaw()
|
||||||
except onionrexceptions.NoDataAvailable:
|
except onionrexceptions.NoDataAvailable:
|
||||||
finishedUploads.append(bl)
|
finishedUploads.append(bl)
|
||||||
break
|
break
|
||||||
proxyType = proxypicker.pick_proxy(peer)
|
proxyType = proxypicker.pick_proxy(peer)
|
||||||
logger.info("Uploading block %s to %s" % (bl[:8], peer), terminal=True)
|
logger.info("Uploading block %s to %s" % (bl[:8], peer), terminal=True)
|
||||||
resp = basicrequests.do_post_request(url, data=data, proxyType=proxyType)
|
resp = basicrequests.do_post_request(url, data=data, proxyType=proxyType, content_type='application/octet-stream')
|
||||||
if not resp == False:
|
if not resp == False:
|
||||||
if resp == 'success':
|
if resp == 'success':
|
||||||
localcommand.local_command('waitforshare/' + bl, post=True)
|
localcommand.local_command('waitforshare/' + bl, post=True)
|
||||||
finishedUploads.append(bl)
|
finishedUploads.append(bl)
|
||||||
elif resp == 'exists':
|
elif resp == 'exists':
|
||||||
finishedUploads.append(bl)
|
finishedUploads.append(bl)
|
||||||
|
else:
|
||||||
|
logger.warn('Failed to upload %s, reason: %s' % (bl[:8], resp[:150]), terminal=True)
|
||||||
for x in finishedUploads:
|
for x in finishedUploads:
|
||||||
try:
|
try:
|
||||||
comm_inst.blocksToUpload.remove(x)
|
comm_inst.blocksToUpload.remove(x)
|
||||||
|
@ -22,25 +22,25 @@ from flask import Response, abort
|
|||||||
import blockimporter, onionrexceptions, logger
|
import blockimporter, onionrexceptions, logger
|
||||||
def accept_upload(request):
|
def accept_upload(request):
|
||||||
resp = 'failure'
|
resp = 'failure'
|
||||||
try:
|
data = request.get_data()
|
||||||
data = request.form['block']
|
if sys.getsizeof(data) < 100000000:
|
||||||
except KeyError:
|
try:
|
||||||
logger.warn('No block specified for upload')
|
if blockimporter.importBlockFromData(data):
|
||||||
pass
|
resp = 'success'
|
||||||
else:
|
else:
|
||||||
if sys.getsizeof(data) < 100000000:
|
|
||||||
try:
|
|
||||||
if blockimporter.importBlockFromData(data):
|
|
||||||
resp = 'success'
|
|
||||||
else:
|
|
||||||
resp = 'failure'
|
|
||||||
logger.warn('Error encountered importing uploaded block')
|
|
||||||
except onionrexceptions.BlacklistedBlock:
|
|
||||||
logger.debug('uploaded block is blacklisted')
|
|
||||||
resp = 'failure'
|
resp = 'failure'
|
||||||
except onionrexceptions.DataExists:
|
logger.warn('Error encountered importing uploaded block')
|
||||||
resp = 'exists'
|
except onionrexceptions.BlacklistedBlock:
|
||||||
|
logger.debug('uploaded block is blacklisted')
|
||||||
|
resp = 'failure'
|
||||||
|
except onionrexceptions.InvalidProof:
|
||||||
|
resp = 'proof'
|
||||||
|
except onionrexceptions.DataExists:
|
||||||
|
resp = 'exists'
|
||||||
if resp == 'failure':
|
if resp == 'failure':
|
||||||
abort(400)
|
abort(400)
|
||||||
resp = Response(resp)
|
elif resp == 'proof':
|
||||||
|
resp = Response(resp, 400)
|
||||||
|
else:
|
||||||
|
resp = Response(resp)
|
||||||
return resp
|
return resp
|
@ -21,7 +21,7 @@ import requests, streamedrequests
|
|||||||
import logger, onionrexceptions
|
import logger, onionrexceptions
|
||||||
from etc import onionrvalues
|
from etc import onionrvalues
|
||||||
from . import localcommand
|
from . import localcommand
|
||||||
def do_post_request(url, data={}, port=0, proxyType='tor', max_size=10000):
|
def do_post_request(url, data={}, port=0, proxyType='tor', max_size=10000, content_type: str = ''):
|
||||||
'''
|
'''
|
||||||
Do a POST request through a local tor or i2p instance
|
Do a POST request through a local tor or i2p instance
|
||||||
'''
|
'''
|
||||||
@ -34,6 +34,8 @@ def do_post_request(url, data={}, port=0, proxyType='tor', max_size=10000):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
headers = {'User-Agent': 'PyOnionr', 'Connection':'close'}
|
headers = {'User-Agent': 'PyOnionr', 'Connection':'close'}
|
||||||
|
if len(content_type) > 0:
|
||||||
|
headers['Content-Type'] = content_type
|
||||||
try:
|
try:
|
||||||
proxies = {'http': 'socks4a://127.0.0.1:' + str(port), 'https': 'socks4a://127.0.0.1:' + str(port)}
|
proxies = {'http': 'socks4a://127.0.0.1:' + str(port), 'https': 'socks4a://127.0.0.1:' + str(port)}
|
||||||
#r = requests.post(url, data=data, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30))
|
#r = requests.post(url, data=data, headers=headers, proxies=proxies, allow_redirects=False, timeout=(15, 30))
|
||||||
|
Loading…
Reference in New Issue
Block a user