fix generating hashes not being removed when done, add endpoint to get generating hashes

This commit is contained in:
Kevin Froman 2020-08-09 22:13:06 -05:00
parent a01b645a79
commit feb8004c95
4 changed files with 39 additions and 15 deletions

View File

@ -4,8 +4,13 @@ Create blocks with the client api server
""" """
import ujson as json import ujson as json
import threading import threading
from typing import TYPE_CHECKING
from flask import Blueprint, Response, request, g from flask import Blueprint, Response, request, g
if TYPE_CHECKING:
from deadsimplekv import DeadSimpleKV
import onionrblocks import onionrblocks
from onionrcrypto import hashers from onionrcrypto import hashers
from onionrutils import bytesconverter from onionrutils import bytesconverter
@ -31,7 +36,6 @@ ib = Blueprint('insertblock', __name__)
@ib.route('/insertblock', methods=['POST']) @ib.route('/insertblock', methods=['POST'])
def client_api_insert_block(): def client_api_insert_block():
encrypt: bool = False
insert_data: JSONSerializable = request.get_json(force=True) insert_data: JSONSerializable = request.get_json(force=True)
message = insert_data['message'] message = insert_data['message']
message_hash = bytesconverter.bytes_to_str(hashers.sha3_hash(message)) message_hash = bytesconverter.bytes_to_str(hashers.sha3_hash(message))

View File

@ -50,7 +50,8 @@ class PrivateEndpoints:
def wwwPublic(path): def wwwPublic(path):
if not config.get("www.private.run", True): if not config.get("www.private.run", True):
abort(403) 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') @private_endpoints_bp.route('/hitcount')
def get_hit_count(): def get_hit_count():
@ -62,7 +63,7 @@ class PrivateEndpoints:
return Response("pong!") return Response("pong!")
@private_endpoints_bp.route('/lastconnect') @private_endpoints_bp.route('/lastconnect')
def lastConnect(): def last_connect():
return Response(str(client_api.publicAPI.lastRequest)) return Response(str(client_api.publicAPI.lastRequest))
@private_endpoints_bp.route('/waitforshare/<name>', methods=['post']) @private_endpoints_bp.route('/waitforshare/<name>', methods=['post'])
@ -104,25 +105,26 @@ class PrivateEndpoints:
pass pass
@private_endpoints_bp.route('/getuptime') @private_endpoints_bp.route('/getuptime')
def showUptime(): def show_uptime():
return Response(str(client_api.getUptime())) return Response(str(client_api.getUptime()))
@private_endpoints_bp.route('/getActivePubkey') @private_endpoints_bp.route('/getActivePubkey')
def getActivePubkey(): def get_active_pubkey():
return Response(pub_key) return Response(pub_key)
@private_endpoints_bp.route('/getHumanReadable') @private_endpoints_bp.route('/getHumanReadable')
def getHumanReadableDefault(): def get_human_readable_default():
return Response(mnemonickeys.get_human_readable_ID()) return Response(mnemonickeys.get_human_readable_ID())
@private_endpoints_bp.route('/getHumanReadable/<name>') @private_endpoints_bp.route('/getHumanReadable/<name>')
def getHumanReadable(name): def get_human_readable(name):
name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name)) name = unpaddedbase32.repad(bytesconverter.str_to_bytes(name))
return Response(mnemonickeys.get_human_readable_ID(name)) return Response(mnemonickeys.get_human_readable_ID(name))
@private_endpoints_bp.route('/getBase32FromHumanReadable/<words>') @private_endpoints_bp.route('/getBase32FromHumanReadable/<words>')
def get_base32_from_human_readable(words): 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') @private_endpoints_bp.route('/gettorsocks')
def get_tor_socks(): def get_tor_socks():
@ -130,7 +132,8 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/setonboarding', methods=['POST']) @private_endpoints_bp.route('/setonboarding', methods=['POST'])
def set_onboarding(): 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') @private_endpoints_bp.route('/os')
def get_os_system(): def get_os_system():
@ -139,7 +142,8 @@ class PrivateEndpoints:
@private_endpoints_bp.route('/torready') @private_endpoints_bp.route('/torready')
def is_tor_ready(): def is_tor_ready():
"""If Tor is starting up, the web UI is not ready to be used.""" """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') @private_endpoints_bp.route('/gettoraddress')
def get_tor_address(): def get_tor_address():
@ -147,3 +151,12 @@ class PrivateEndpoints:
if not config.get('general.security_level', 0) == 0: if not config.get('general.security_level', 0) == 0:
abort(404) abort(404)
return Response(get_tor()[0]) 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'
))
)

View File

@ -262,7 +262,8 @@ def insert_block(data: Union[str, bytes], header: str = 'txt',
localcommand.local_command, localcommand.local_command,
'/daemon-event/remove_from_insert_queue_wrapper', '/daemon-event/remove_from_insert_queue_wrapper',
post=True, post=True,
post_data={'block_hash': retData}, post_data={'block_hash':
bytesconverter.bytes_to_str(crypto.hashers.sha3_hash(data))},
is_json=True is_json=True
).get(timeout=5) ).get(timeout=5)
return retData return retData

View File

@ -25,14 +25,20 @@ flask_blueprint = Blueprint('debugAPI', __name__)
@flask_blueprint.route('/debug/dump_shared_state') @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 = "" resp = ""
for i in g.too_many.objects.keys: 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) return Response(resp)
@flask_blueprint.route('/debug/dump_shared_vars') @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) 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)