From feb8004c95f3dc1c7829437d8eebe3e9b652354a Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 9 Aug 2020 22:13:06 -0500 Subject: [PATCH] fix generating hashes not being removed when done, add endpoint to get generating hashes --- src/httpapi/insertblock.py | 6 +++- src/httpapi/miscclientapi/endpoints.py | 31 +++++++++++++------ src/onionrblocks/insert/main.py | 3 +- .../default-plugins/debuginfo/debugapi.py | 14 ++++++--- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/httpapi/insertblock.py b/src/httpapi/insertblock.py index d0aac3b8..693cee74 100644 --- a/src/httpapi/insertblock.py +++ b/src/httpapi/insertblock.py @@ -4,8 +4,13 @@ Create blocks with the client api server """ import ujson as json import threading +from typing import TYPE_CHECKING from flask import Blueprint, Response, request, g + +if TYPE_CHECKING: + from deadsimplekv import DeadSimpleKV + import onionrblocks from onionrcrypto import hashers from onionrutils import bytesconverter @@ -31,7 +36,6 @@ ib = Blueprint('insertblock', __name__) @ib.route('/insertblock', methods=['POST']) def client_api_insert_block(): - encrypt: bool = False insert_data: JSONSerializable = request.get_json(force=True) message = insert_data['message'] message_hash = bytesconverter.bytes_to_str(hashers.sha3_hash(message)) diff --git a/src/httpapi/miscclientapi/endpoints.py b/src/httpapi/miscclientapi/endpoints.py index a9439a6f..bd67dc76 100644 --- a/src/httpapi/miscclientapi/endpoints.py +++ b/src/httpapi/miscclientapi/endpoints.py @@ -50,7 +50,8 @@ class PrivateEndpoints: def wwwPublic(path): if not config.get("www.private.run", True): abort(403) - return send_from_directory(config.get('www.private.path', 'static-data/www/private/'), path) + return send_from_directory(config.get('www.private.path', + 'static-data/www/private/'), path) @private_endpoints_bp.route('/hitcount') def get_hit_count(): @@ -62,7 +63,7 @@ class PrivateEndpoints: return Response("pong!") @private_endpoints_bp.route('/lastconnect') - def lastConnect(): + def last_connect(): return Response(str(client_api.publicAPI.lastRequest)) @private_endpoints_bp.route('/waitforshare/', methods=['post']) @@ -104,25 +105,26 @@ class PrivateEndpoints: pass @private_endpoints_bp.route('/getuptime') - def showUptime(): + def show_uptime(): return Response(str(client_api.getUptime())) @private_endpoints_bp.route('/getActivePubkey') - def getActivePubkey(): + def get_active_pubkey(): return Response(pub_key) @private_endpoints_bp.route('/getHumanReadable') - def getHumanReadableDefault(): + def get_human_readable_default(): return Response(mnemonickeys.get_human_readable_ID()) @private_endpoints_bp.route('/getHumanReadable/') - def getHumanReadable(name): + def get_human_readable(name): name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name)) return Response(mnemonickeys.get_human_readable_ID(name)) @private_endpoints_bp.route('/getBase32FromHumanReadable/') def get_base32_from_human_readable(words): - return Response(bytesconverter.bytes_to_str(mnemonickeys.get_base32(words))) + return Response( + bytesconverter.bytes_to_str(mnemonickeys.get_base32(words))) @private_endpoints_bp.route('/gettorsocks') def get_tor_socks(): @@ -130,7 +132,8 @@ class PrivateEndpoints: @private_endpoints_bp.route('/setonboarding', methods=['POST']) def set_onboarding(): - return Response(config.onboarding.set_config_from_onboarding(request.get_json())) + return Response( + config.onboarding.set_config_from_onboarding(request.get_json())) @private_endpoints_bp.route('/os') def get_os_system(): @@ -139,7 +142,8 @@ class PrivateEndpoints: @private_endpoints_bp.route('/torready') def is_tor_ready(): """If Tor is starting up, the web UI is not ready to be used.""" - return Response(str(g.too_many.get(NetController).readyState).lower()) + return Response( + str(g.too_many.get(NetController).readyState).lower()) @private_endpoints_bp.route('/gettoraddress') def get_tor_address(): @@ -147,3 +151,12 @@ class PrivateEndpoints: if not config.get('general.security_level', 0) == 0: abort(404) return Response(get_tor()[0]) + + @private_endpoints_bp.route('/getgeneratingblocks') + def get_generating_blocks() -> Response: + return Response( + ','.join( + g.too_many.get_by_string('DeadSimpleKV').get( + 'generating_blocks' + )) + ) diff --git a/src/onionrblocks/insert/main.py b/src/onionrblocks/insert/main.py index 6661603c..c8cdaa71 100644 --- a/src/onionrblocks/insert/main.py +++ b/src/onionrblocks/insert/main.py @@ -262,7 +262,8 @@ def insert_block(data: Union[str, bytes], header: str = 'txt', localcommand.local_command, '/daemon-event/remove_from_insert_queue_wrapper', post=True, - post_data={'block_hash': retData}, + post_data={'block_hash': + bytesconverter.bytes_to_str(crypto.hashers.sha3_hash(data))}, is_json=True ).get(timeout=5) return retData diff --git a/static-data/default-plugins/debuginfo/debugapi.py b/static-data/default-plugins/debuginfo/debugapi.py index fdb5a457..d3b06ce5 100755 --- a/static-data/default-plugins/debuginfo/debugapi.py +++ b/static-data/default-plugins/debuginfo/debugapi.py @@ -25,14 +25,20 @@ flask_blueprint = Blueprint('debugAPI', __name__) @flask_blueprint.route('/debug/dump_shared_state') -def get_shared_state(): +def get_shared_state() -> Response: + """Return somewhat human-readable dump of shared toomanyobjects.""" resp = "" for i in g.too_many.objects.keys: - resp += i + dir(g.too_many.objects.keys[i]) + resp += i + dir(g.too_many.objects.keys[i]) + "\n" return Response(resp) @flask_blueprint.route('/debug/dump_shared_vars') -def get_shared_vars(): +def get_shared_vars() -> Response: + """Return somewhat human-readable dump of pseudo globals (DeadSimpleKV).""" kv: DeadSimpleKV = g.too_many.get(DeadSimpleKV) - return Response(dir(kv._data)) + resp = "" + for i in kv.keys: + resp += i + dir(g.too_many.objects.keys[i]) + "\n" + return Response(resp) +