diff --git a/docs/dev/http-api.md b/docs/dev/http-api.md index 74745e1a..e44d2b7a 100755 --- a/docs/dev/http-api.md +++ b/docs/dev/http-api.md @@ -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 diff --git a/src/httpapi/miscclientapi/endpoints.py b/src/httpapi/miscclientapi/endpoints.py index 6f8de33c..4f49f094 100644 --- a/src/httpapi/miscclientapi/endpoints.py +++ b/src/httpapi/miscclientapi/endpoints.py @@ -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 diff --git a/src/onionrblocks/insert.py b/src/onionrblocks/insert.py index a444eeb2..8378538c 100644 --- a/src/onionrblocks/insert.py +++ b/src/onionrblocks/insert.py @@ -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