From 7db8193bf6d014f1c4a3678f151a896d9b92f810 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 19 Jan 2020 21:02:04 -0600 Subject: [PATCH] remove POW for annoncements --- src/communicatorutils/announcenode.py | 64 ++++++--------------- src/etc/onionrvalues.py | 4 ++ src/httpapi/miscpublicapi/announce.py | 80 +++++++++++---------------- static-data/www/board/board.js | 3 +- static-data/www/private/index.html | 5 ++ static-data/www/shared/main/stats.js | 8 ++- 6 files changed, 67 insertions(+), 97 deletions(-) diff --git a/src/communicatorutils/announcenode.py b/src/communicatorutils/announcenode.py index 1d92a3fa..a068b88c 100755 --- a/src/communicatorutils/announcenode.py +++ b/src/communicatorutils/announcenode.py @@ -52,56 +52,26 @@ def announce_node(daemon): except onionrexceptions.OnlinePeerNeeded: peer = "" - for _ in range(1): - try: - ourID = gettransports.get()[0] - if not peer: - raise onionrexceptions.OnlinePeerNeeded - except (IndexError, onionrexceptions.OnlinePeerNeeded): - break - + try: + ourID = gettransports.get()[0] + if not peer: + raise onionrexceptions.OnlinePeerNeeded + except (IndexError, onionrexceptions.OnlinePeerNeeded): + pass + else: url = 'http://' + peer + '/announce' data = {'node': ourID} - combinedNodes = ourID + peer - if ourID != 1: - existingRand = bytesconverter.bytes_to_str( - keydb.transportinfo.get_address_info(peer, 'powValue')) - # Reset existingRand if it no longer meets the minimum POW - if isinstance(existingRand, type(None)) or \ - not existingRand.endswith( - '0' * onionrvalues.ANNOUNCE_POW): - existingRand = '' + logger.info('Announcing node to ' + url) + if basicrequests.do_post_request( + url, + data, + port=daemon.shared_state.get(NetController).socksPort)\ + == 'Success': + logger.info('Successfully introduced node to ' + peer, + terminal=True) + ret_data = True + keydb.transportinfo.set_address_info(peer, 'introduced', 1) - if peer in daemon.announceCache: - data['random'] = daemon.announceCache[peer] - elif len(existingRand) > 0: - data['random'] = existingRand - else: - daemon.announceProgress[peer] = True - proof = onionrproofs.DataPOW( - combinedNodes, minDifficulty=onionrvalues.ANNOUNCE_POW) - del daemon.announceProgress[peer] - try: - data['random'] = base64.b64encode(proof.waitForResult()[1]) - except TypeError: - # Happens when we failed to produce a proof - logger.error(f"Failed to produce a pow for {peer} annce") - announce_fail = True - else: - daemon.announceCache[peer] = data['random'] - if not announce_fail: - logger.info('Announcing node to ' + url) - if basicrequests.do_post_request( - url, - data, - port=daemon.shared_state.get(NetController).socksPort)\ - == 'Success': - logger.info('Successfully introduced node to ' + peer, - terminal=True) - ret_data = True - keydb.transportinfo.set_address_info(peer, 'introduced', 1) - keydb.transportinfo.set_address_info(peer, 'powValue', - data['random']) daemon.decrementThreadCount('announce_node') return ret_data diff --git a/src/etc/onionrvalues.py b/src/etc/onionrvalues.py index c4c30b65..294de91f 100755 --- a/src/etc/onionrvalues.py +++ b/src/etc/onionrvalues.py @@ -44,6 +44,10 @@ DATABASE_LOCK_TIMEOUT = 60 # Block creation anonymization requirements MIN_BLOCK_UPLOAD_PEER_PERCENT = 0.1 +WSGI_SERVER_REQUEST_TIMEOUT_SECS = 120 + +MAX_NEW_PEER_QUEUE = 1000 + # Begin OnionrValues migrated values """Make announce take a few seconds (on average) to compute to discourage excessive node announcements""" ANNOUNCE_POW = 6 diff --git a/src/httpapi/miscpublicapi/announce.py b/src/httpapi/miscpublicapi/announce.py index 7a4fcad7..439aeef0 100755 --- a/src/httpapi/miscpublicapi/announce.py +++ b/src/httpapi/miscpublicapi/announce.py @@ -1,9 +1,16 @@ -''' - Onionr - Private P2P Communication +"""Onionr - Private P2P Communication. - Handle announcements to the public API server -''' -''' +Handle announcements to the public API server +""" +from flask import Response, g +import deadsimplekv + +import logger +from etc import onionrvalues +from onionrutils import stringvalidators, bytesconverter +import filepaths +from communicator import OnionrCommunicatorDaemon +""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or @@ -16,60 +23,39 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' -import base64 -from flask import Response, g -import deadsimplekv -import logger -from etc import onionrvalues -from onionrutils import stringvalidators, bytesconverter -from utils import gettransports -import onionrcrypto as crypto, filepaths -from communicator import OnionrCommunicatorDaemon +""" + + def handle_announce(request): - ''' - accept announcement posts, validating POW + """accept announcement posts, validating POW clientAPI should be an instance of the clientAPI server running, request is a instance of a flask request - ''' + """ resp = 'failure' - powHash = '' - randomData = '' newNode = '' try: newNode = request.form['node'].encode() except KeyError: logger.warn('No node specified for upload') - pass else: - try: - randomData = request.form['random'] - randomData = base64.b64decode(randomData) - except KeyError: - logger.warn('No random data specified for upload') + newNode = bytesconverter.bytes_to_str(newNode) + announce_queue = deadsimplekv.DeadSimpleKV(filepaths.announce_cache) + announce_queue_list = announce_queue.get('new_peers') + if announce_queue_list is None: + announce_queue_list = [] else: - nodes = newNode + bytesconverter.str_to_bytes(gettransports.get()[0]) - nodes = crypto.hashers.blake2b_hash(nodes) - powHash = crypto.hashers.blake2b_hash(randomData + nodes) - try: - powHash = powHash.decode() - except AttributeError: - pass - if powHash.startswith('0' * onionrvalues.ANNOUNCE_POW): - newNode = bytesconverter.bytes_to_str(newNode) - announce_queue = deadsimplekv.DeadSimpleKV(filepaths.announce_cache) - announce_queue_list = announce_queue.get('new_peers') - if announce_queue_list is None: - announce_queue_list = [] + if len(announce_queue_list) >= onionrvalues.MAX_NEW_PEER_QUEUE: + newNode = '' + + if stringvalidators.validate_transport(newNode) and \ + newNode not in announce_queue_list: + g.shared_state.get( + OnionrCommunicatorDaemon).newPeers.append(newNode) + announce_queue.put('new_peers', + announce_queue_list.append(newNode)) + announce_queue.flush() + resp = 'Success' - if stringvalidators.validate_transport(newNode) and not newNode in announce_queue_list: - #clientAPI.onionrInst.communicatorInst.newPeers.append(newNode) - g.shared_state.get(OnionrCommunicatorDaemon).newPeers.append(newNode) - announce_queue.put('new_peers', announce_queue_list.append(newNode)) - announce_queue.flush() - resp = 'Success' - else: - logger.warn(newNode.decode() + ' failed to meet POW: ' + powHash) resp = Response(resp) if resp == 'failure': return resp, 406 diff --git a/static-data/www/board/board.js b/static-data/www/board/board.js index 821a549b..03f868c0 100755 --- a/static-data/www/board/board.js +++ b/static-data/www/board/board.js @@ -120,7 +120,6 @@ function appendMessages(msg, blockHash, beforeHash, channel) { } } - } } @@ -228,7 +227,7 @@ newPostForm.onsubmit = function(){ "token": webpass } }) - .then((resp) => resp.text()) // Transform the data into text + .then((resp) => resp.text()) .then(function(data) { newPostForm.style.display = 'block' if (data == 'failure due to duplicate insert'){ diff --git a/static-data/www/private/index.html b/static-data/www/private/index.html index 32cc53d2..7938c233 100755 --- a/static-data/www/private/index.html +++ b/static-data/www/private/index.html @@ -176,6 +176,11 @@
Session Connections
+
+
+ Tor Info +
+
️ Last Received: None since start diff --git a/static-data/www/shared/main/stats.js b/static-data/www/shared/main/stats.js index 0f535508..e264613f 100755 --- a/static-data/www/shared/main/stats.js +++ b/static-data/www/shared/main/stats.js @@ -71,7 +71,13 @@ if (sec_description_str !== 'normal'){ function getStats(){ stats = JSON.parse(httpGet('getstats', webpass)) uptimeDisplay.innerText = seconds2time(stats['uptime']) - connectedDisplay.innerText = stats['connectedNodes'] + connectedNodes = stats['connectedNodes'].split('\n') + connectedDisplay.innerText = '' + for (x = 0; x < connectedNodes.length; x++){ + if (! connectedDisplay.innerText.includes(connectedNodes[x])){ + connectedDisplay.innerText += '🧅 ' + connectedNodes[x] + '\n' + } + } storedBlockDisplay.innerText = stats['blockCount'] queuedBlockDisplay.innerText = stats['blockQueueCount'] securityLevel.innerText = sec_description_str