remove POW for annoncements
This commit is contained in:
parent
1c6893e297
commit
7db8193bf6
6 changed files with 67 additions and 97 deletions
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue