diff --git a/onionr/communicatorutils/announcenode.py b/onionr/communicatorutils/announcenode.py index cfec4503..84ca248c 100755 --- a/onionr/communicatorutils/announcenode.py +++ b/onionr/communicatorutils/announcenode.py @@ -78,7 +78,7 @@ def announce_node(daemon): daemon.announceCache[peer] = data['random'] if not announceFail: logger.info('Announcing node to ' + url) - if basicrequests.do_post_request(url, data, port=daemon.shared_state.get(NetController)) == 'Success': + if basicrequests.do_post_request(url, data, port=daemon.shared_state.get(NetController).socksPort) == 'Success': logger.info('Successfully introduced node to ' + peer, terminal=True) retData = True keydb.transportinfo.set_address_info(peer, 'introduced', 1) diff --git a/onionr/communicatorutils/connectnewpeers.py b/onionr/communicatorutils/connectnewpeers.py index 1de5140f..63bd37f6 100755 --- a/onionr/communicatorutils/connectnewpeers.py +++ b/onionr/communicatorutils/connectnewpeers.py @@ -52,7 +52,7 @@ def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False): if len(peerList) == 0 or useBootstrap: # Avoid duplicating bootstrap addresses in peerList bootstrappeers.add_bootstrap_list_to_peer_list(comm_inst, peerList) - + print(peerList) for address in peerList: if not config.get('tor.v3onions') and len(address) == 62: continue diff --git a/onionr/httpapi/miscpublicapi/announce.py b/onionr/httpapi/miscpublicapi/announce.py index 8e477630..53fb96e8 100755 --- a/onionr/httpapi/miscpublicapi/announce.py +++ b/onionr/httpapi/miscpublicapi/announce.py @@ -18,13 +18,14 @@ along with this program. If not, see . ''' import base64 -from flask import Response +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 @@ -57,9 +58,14 @@ def handle_announce(request): if powHash.startswith('0' * onionrvalues.OnionrValues().announce_pow): newNode = bytesconverter.bytes_to_str(newNode) announce_queue = deadsimplekv.DeadSimpleKV(filepaths.announce_cache) - if stringvalidators.validate_transport(newNode) and not newNode in announce_queue.get('new_peers'): - clientAPI.onionrInst.communicatorInst.newPeers.append(newNode) - announce_queue.put('new_peers', announce_queue.get('new_peers').append(newNode)) + announce_queue_list = announce_queue.get('new_peers') + if announce_queue_list is None: + announce_queue_list = [] + + 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: diff --git a/onionr/httpapi/miscpublicapi/endpoints.py b/onionr/httpapi/miscpublicapi/endpoints.py index 7318948d..62d49397 100644 --- a/onionr/httpapi/miscpublicapi/endpoints.py +++ b/onionr/httpapi/miscpublicapi/endpoints.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -from flask import Response, Blueprint, request, send_from_directory, abort +from flask import Response, Blueprint, request, send_from_directory, abort, g from . import getblocks, upload, announce from coredb import keydb import config @@ -69,6 +69,7 @@ class PublicEndpoints: @public_endpoints_bp.route('/announce', methods=['post']) def accept_announce(): '''Accept announcements with pow token to prevent spam''' + g.shared_state = public_api._too_many resp = announce.handle_announce(request) return resp