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')
name = reconstructhash.reconstruct_hash(name)
if name in client_api.publicAPI.hideBlocks:
#spawn(_delay_wait_for_share_block_removal)
return Response("will be removed")
else:
client_api.publicAPI.hideBlocks.append(name)
@ -141,7 +140,7 @@ class PrivateEndpoints:
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())
@private_endpoints_bp.route('/gettoraddress')
def get_tor_address():
"""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 threading
import sys
from flask import Response
from flask import abort
from flask import g
from onionrutils import localcommand
from onionrblocks import blockimporter
import onionrexceptions
import logger
'''
"""
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
@ -28,7 +28,7 @@ import logger
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
"""
def accept_upload(request):
@ -40,17 +40,19 @@ def accept_upload(request):
try:
b_hash = blockimporter.import_block_from_data(data)
if b_hash:
spawn(
localcommand.local_command,
f'/daemon-event/upload_event',
post=True,
is_json=True,
postData={'block': b_hash}
).get(timeout=10)
if g.too_many.get_by_string("OnionrCommunicatorDaemon").onlinePeers:
spawn(
localcommand.local_command,
f'/daemon-event/upload_event',
post=True,
is_json=True,
postData={'block': b_hash}
).get(timeout=10)
resp = 'success'
else:
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:
logger.debug('uploaded block is blacklisted')
resp = 'failure'
@ -62,7 +64,8 @@ def accept_upload(request):
abort(400)
elif resp == 'proof':
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:
resp = Response(resp)
return resp