add check and daemon api endpoint to fix #41

This commit is contained in:
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
- Methods: GET
- Returns the header (metadata section) of a block.
* /gethidden/
- Methods: GET
- Returns line separated list of hidden blocks
* /hitcount
- Methods: GET
- 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'])
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')
def getStats():
# returns node stats

View File

@ -34,11 +34,25 @@ from onionrproofs import subprocesspow
import logger
from onionrtypes import UserIDSecretKey
def insert_block(data: Union[str, bytes], header: str ='txt',
sign: bool =False, encryptType:str ='', symKey:str ='',
asymPeer:str ='', meta:dict = {},
expire:Union[int, None] =None, disableForward:bool =False,
signing_key:UserIDSecretKey ='')->Union[str,bool]:
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',
sign: bool = False, encryptType: str = '', symKey: str = '',
asymPeer: str = '', meta: dict = {},
expire: Union[int, None] = None, disableForward: bool = False,
signing_key: UserIDSecretKey = '') -> Union[str, bool]:
"""
Inserts a block into the network
encryptType must be specified to encrypt a block
@ -46,6 +60,9 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
our_private_key = crypto.priv_key
our_pub_key = crypto.pub_key
is_offline = True
if not _check_upload_queue() is False: is_offline = False
if signing_key != '':
# if it was specified to use an alternative private 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:
nonceFile.write(dataNonce + '\n')
#if type(data) is bytes:
# data = data.decode()
#data = str(data)
plaintext = data
plaintextMeta = {}
plaintextPeer = asymPeer
@ -150,7 +164,7 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
# compile metadata
metadata['meta'] = jsonMeta
if len(signature) > 0: # I don't like not pattern
if len(signature) > 0: # I don't like not pattern
metadata['sig'] = signature
metadata['signer'] = signer
metadata['time'] = createTime
@ -173,7 +187,7 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
retData = False
else:
# 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:
localcommand.local_command('/waitforshare/' + retData, post=True, maxWait=5)
coredb.daemonqueue.daemon_queue_add('uploadBlock', retData)
@ -194,5 +208,5 @@ def insert_block(data: Union[str, bytes], header: str ='txt',
events.event('insertdeniable', {'content': plaintext, 'meta': plaintextMeta, 'hash': retData, 'peer': bytesconverter.bytes_to_str(asymPeer)}, threaded = True)
else:
events.event('insertblock', {'content': plaintext, 'meta': plaintextMeta, 'hash': retData, 'peer': bytesconverter.bytes_to_str(asymPeer)}, threaded = True)
coredb.daemonqueue.daemon_queue_add('remove_from_insert_list', data=dataNonce)
coredb.daemonqueue.daemon_queue_add('remove_from_insert_list', data= dataNonce)
return retData