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)

View File

@ -1,21 +1,21 @@
''' """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
Accept block uploads to the public API server Accept block uploads to the public API server
''' """
import sys
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,6 +40,7 @@ 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:
if g.too_many.get_by_string("OnionrCommunicatorDaemon").onlinePeers:
spawn( spawn(
localcommand.local_command, localcommand.local_command,
f'/daemon-event/upload_event', f'/daemon-event/upload_event',
@ -50,7 +51,8 @@ def accept_upload(request):
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