add check and daemon api endpoint to fix #41

master
Kevin Froman 2019-11-27 13:39:48 -06:00
parent d1f9911fd4
commit 00baf30141
3 changed files with 32 additions and 11 deletions

View File

@ -37,6 +37,9 @@ Please note: endpoints that simply provide static web app files are not document
* /getblockheader/hash * /getblockheader/hash
- Methods: GET - Methods: GET
- Returns the header (metadata section) of a block. - Returns the header (metadata section) of a block.
* /gethidden/
- Methods: GET
- Returns line separated list of hidden blocks
* /hitcount * /hitcount
- Methods: GET - Methods: GET
- Return the amount of requests the public api server has received this session - Return the amount of requests the public api server has received this session

View File

@ -103,6 +103,10 @@ class PrivateEndpoints:
subprocess.Popen([SCRIPT_NAME, 'restart']) subprocess.Popen([SCRIPT_NAME, 'restart'])
return Response("bye") return Response("bye")
@private_endpoints_bp.route('/gethidden')
def get_hidden_blocks():
return Response('\n'.join(client_api.publicAPI.hideBlocks))
@private_endpoints_bp.route('/getstats') @private_endpoints_bp.route('/getstats')
def getStats(): def getStats():
# returns node stats # returns node stats

View File

@ -34,6 +34,20 @@ from onionrproofs import subprocesspow
import logger import logger
from onionrtypes import UserIDSecretKey from onionrtypes import UserIDSecretKey
def _check_upload_queue():
"""Returns the current upload queue len
raises OverflowError if max
"""
max_upload_queue: int = 5000
queue = localcommand.local_command('/gethidden', maxWait=10)
up_queue = len(queue.splitlines())
if up_queue >= max_upload_queue:
raise OverflowError
return up_queue
def insert_block(data: Union[str, bytes], header: str = 'txt', def insert_block(data: Union[str, bytes], header: str = 'txt',
sign: bool = False, encryptType: str = '', symKey: str = '', sign: bool = False, encryptType: str = '', symKey: str = '',
asymPeer: str = '', meta: dict = {}, asymPeer: str = '', meta: dict = {},
@ -46,6 +60,9 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
our_private_key = crypto.priv_key our_private_key = crypto.priv_key
our_pub_key = crypto.pub_key our_pub_key = crypto.pub_key
is_offline = True
if not _check_upload_queue() is False: is_offline = False
if signing_key != '': if signing_key != '':
# if it was specified to use an alternative private key # if it was specified to use an alternative private key
our_private_key = signing_key our_private_key = signing_key
@ -76,9 +93,6 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
with open(filepaths.data_nonce_file, 'a') as nonceFile: with open(filepaths.data_nonce_file, 'a') as nonceFile:
nonceFile.write(dataNonce + '\n') nonceFile.write(dataNonce + '\n')
#if type(data) is bytes:
# data = data.decode()
#data = str(data)
plaintext = data plaintext = data
plaintextMeta = {} plaintextMeta = {}
plaintextPeer = asymPeer plaintextPeer = asymPeer
@ -173,7 +187,7 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
retData = False retData = False
else: else:
# Tell the api server through localCommand to wait for the daemon to upload this block to make statistical analysis more difficult # Tell the api server through localCommand to wait for the daemon to upload this block to make statistical analysis more difficult
if localcommand.local_command('/ping', maxWait=10) == 'pong!': if not is_offline or localcommand.local_command('/ping', maxWait=10) == 'pong!':
if config.get('general.security_level', 1) == 0: if config.get('general.security_level', 1) == 0:
localcommand.local_command('/waitforshare/' + retData, post=True, maxWait=5) localcommand.local_command('/waitforshare/' + retData, post=True, maxWait=5)
coredb.daemonqueue.daemon_queue_add('uploadBlock', retData) coredb.daemonqueue.daemon_queue_add('uploadBlock', retData)