diff --git a/src/communicator/__init__.py b/src/communicator/__init__.py index d712b318..99a0b329 100755 --- a/src/communicator/__init__.py +++ b/src/communicator/__init__.py @@ -113,7 +113,7 @@ class OnionrCommunicatorDaemon: # Timer to discover new peers OnionrCommunicatorTimers( self, lookupadders.lookup_new_peer_transports_with_communicator, - 60, requires_peer=True, my_args=[self], max_threads=2) + 60, requires_peer=True, my_args=[shared_state], max_threads=2) # Timer for adjusting which peers # we actively communicate to at any given time, diff --git a/src/communicator/onlinepeers/pickonlinepeers.py b/src/communicator/onlinepeers/pickonlinepeers.py index 4a3d6216..dc11bceb 100644 --- a/src/communicator/onlinepeers/pickonlinepeers.py +++ b/src/communicator/onlinepeers/pickonlinepeers.py @@ -26,9 +26,8 @@ if TYPE_CHECKING: """ -def pick_online_peer(comm_inst): +def pick_online_peer(kv: 'DeadSimpleKV'): """Randomly picks peer from pool without bias (using secrets module).""" - kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV") ret_data = '' peer_length = len(kv.get('onlinePeers')) if peer_length <= 0: diff --git a/src/communicator/peeraction.py b/src/communicator/peeraction.py index 0693efab..f09814f6 100644 --- a/src/communicator/peeraction.py +++ b/src/communicator/peeraction.py @@ -11,6 +11,7 @@ from coredb import keydb from . import onlinepeers from onionrtypes import OnionAddressString from onionrpeers.peerprofiles import PeerProfiles +from etc.waitforsetvar import wait_for_set_var """ 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 @@ -33,10 +34,10 @@ def get_peer_profile(kv, address: OnionAddressString) -> 'PeerProfiles': if profile.address == address: return profile p = PeerProfiles(address) + profile_inst_list.append(p) return p - def peer_action(shared_state, peer, action, returnHeaders=False, max_resp_size=5242880): """Perform a get request to a peer.""" diff --git a/src/communicatorutils/announcenode.py b/src/communicatorutils/announcenode.py index e4580f6d..2a4affd3 100755 --- a/src/communicatorutils/announcenode.py +++ b/src/communicatorutils/announcenode.py @@ -49,7 +49,7 @@ def announce_node(daemon): break else: try: - peer = onlinepeers.pick_online_peer(daemon) + peer = onlinepeers.pick_online_peer(kv) except onionrexceptions.OnlinePeerNeeded: peer = "" diff --git a/src/communicatorutils/downloadblocks/__init__.py b/src/communicatorutils/downloadblocks/__init__.py index 0a1b8fb3..fc7aceef 100755 --- a/src/communicatorutils/downloadblocks/__init__.py +++ b/src/communicatorutils/downloadblocks/__init__.py @@ -78,7 +78,7 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"): kv.get('currentDownloading').append(blockHash) if len(blockPeers) == 0: try: - peerUsed = onlinepeers.pick_online_peer(comm_inst) + peerUsed = onlinepeers.pick_online_peer(kv) except onionrexceptions.OnlinePeerNeeded: continue else: diff --git a/src/communicatorutils/lookupadders.py b/src/communicatorutils/lookupadders.py index ed8f8098..738cce08 100755 --- a/src/communicatorutils/lookupadders.py +++ b/src/communicatorutils/lookupadders.py @@ -41,8 +41,8 @@ def lookup_new_peer_transports_with_communicator(shared_state): # Don't get new peers if we have too many queued up break try: - peer = onlinepeers.pick_online_peer() - newAdders = peeraction.peer_action(comm_inst, peer, action='pex') + peer = onlinepeers.pick_online_peer(kv) + newAdders = peeraction.peer_action(shared_state, peer, action='pex') except onionrexceptions.OnlinePeerNeeded: continue try: @@ -64,5 +64,3 @@ def lookup_new_peer_transports_with_communicator(shared_state): except ValueError: pass kv.get('newPeers').extend(newPeers) - comm_inst.decrementThreadCount( - 'lookup_new_peer_transports_with_communicator') diff --git a/src/communicatorutils/lookupblocks.py b/src/communicatorutils/lookupblocks.py index 377695b8..f3b9e942 100755 --- a/src/communicatorutils/lookupblocks.py +++ b/src/communicatorutils/lookupblocks.py @@ -65,7 +65,7 @@ def lookup_blocks_from_communicator(comm_inst): break try: # select random online peer - peer = onlinepeers.pick_online_peer(comm_inst) + peer = onlinepeers.pick_online_peer(kv) except onionrexceptions.OnlinePeerNeeded: time.sleep(1) continue diff --git a/src/communicatorutils/uploadblocks/__init__.py b/src/communicatorutils/uploadblocks/__init__.py index b49b2f16..084595af 100755 --- a/src/communicatorutils/uploadblocks/__init__.py +++ b/src/communicatorutils/uploadblocks/__init__.py @@ -67,7 +67,7 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'): session = session_manager.add_session(bl) for _ in range(min(len(kv.get('onlinePeers')), 6)): try: - peer = onlinepeers.pick_online_peer(comm_inst) + peer = onlinepeers.pick_online_peer(kv) except onionrexceptions.OnlinePeerNeeded: continue try: diff --git a/src/onionrcommands/daemonlaunch/__init__.py b/src/onionrcommands/daemonlaunch/__init__.py index d605502e..4f2e0d43 100755 --- a/src/onionrcommands/daemonlaunch/__init__.py +++ b/src/onionrcommands/daemonlaunch/__init__.py @@ -140,7 +140,6 @@ def daemon(): # Initialize the quasi-global variables setup_kv(shared_state.get(DeadSimpleKV)) - spawn_client_threads(shared_state) shared_state.get(daemoneventsapi.DaemonEventsBP) Thread(target=shared_state.get(apiservers.ClientAPI).start, @@ -193,6 +192,10 @@ def daemon(): Thread(target=statistics_reporter, args=[shared_state], daemon=True).start() + shared_state.get(DeadSimpleKV).put( + 'proxyPort', net.socksPort) + spawn_client_threads(shared_state) + communicator.startCommunicator(shared_state) clean_ephemeral_services()