Only hide blocks uploaded to us if we have outgoing peers (don't send to upload event handler)

This commit is contained in:
Kevin 2020-06-30 18:34:13 -05:00
parent c46e9590c6
commit 7931f514b6
2 changed files with 21 additions and 19 deletions

View File

@ -75,7 +75,6 @@ class PrivateEndpoints:
raise ValueError('block hash needs to be alpha numeric') raise ValueError('block hash needs to be alpha numeric')
name = reconstructhash.reconstruct_hash(name) name = reconstructhash.reconstruct_hash(name)
if name in client_api.publicAPI.hideBlocks: if name in client_api.publicAPI.hideBlocks:
#spawn(_delay_wait_for_share_block_removal)
return Response("will be removed") return Response("will be removed")
else: else:
client_api.publicAPI.hideBlocks.append(name) client_api.publicAPI.hideBlocks.append(name)
@ -141,7 +140,7 @@ class PrivateEndpoints:
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():
"""Return public Tor v3 Onion address for this node""" """Return public Tor v3 Onion address for this node"""

View File

@ -1,21 +1,21 @@
''' """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
Accept block uploads to the public API server
"""
import sys
Accept block uploads to the public API server
'''
from gevent import spawn from gevent import spawn
from gevent import threading from gevent import threading
import sys
from flask import Response from flask import Response
from flask import abort from flask import abort
from flask import g
from onionrutils import localcommand from onionrutils import localcommand
from onionrblocks import blockimporter from onionrblocks import blockimporter
import onionrexceptions import onionrexceptions
import logger import logger
''' """
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
@ -28,7 +28,7 @@ import logger
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
''' """
def accept_upload(request): def accept_upload(request):
@ -40,17 +40,19 @@ def accept_upload(request):
try: try:
b_hash = blockimporter.import_block_from_data(data) b_hash = blockimporter.import_block_from_data(data)
if b_hash: if b_hash:
spawn( if g.too_many.get_by_string("OnionrCommunicatorDaemon").onlinePeers:
localcommand.local_command, spawn(
f'/daemon-event/upload_event', localcommand.local_command,
post=True, f'/daemon-event/upload_event',
is_json=True, post=True,
postData={'block': b_hash} is_json=True,
).get(timeout=10) postData={'block': b_hash}
).get(timeout=10)
resp = 'success' resp = 'success'
else: else:
resp = 'failure' resp = 'failure'
logger.warn(f'Error encountered importing uploaded block {b_hash}') logger.warn(
f'Error encountered importing uploaded block {b_hash}')
except onionrexceptions.BlacklistedBlock: except onionrexceptions.BlacklistedBlock:
logger.debug('uploaded block is blacklisted') logger.debug('uploaded block is blacklisted')
resp = 'failure' resp = 'failure'
@ -62,7 +64,8 @@ def accept_upload(request):
abort(400) abort(400)
elif resp == 'proof': elif resp == 'proof':
resp = Response(resp, 400) resp = Response(resp, 400)
logger.warn(f'Error encountered importing uploaded block, invalid proof {b_hash}') logger.warn(
f'Error importing uploaded block, invalid proof {b_hash}')
else: else:
resp = Response(resp) resp = Response(resp)
return resp return resp