Fixed some broken things from communicator decoupling

master
Kevin Froman 2020-08-08 12:38:14 -05:00
parent bff2595ac9
commit 96af4e8db0
9 changed files with 14 additions and 13 deletions

View File

@ -113,7 +113,7 @@ class OnionrCommunicatorDaemon:
# Timer to discover new peers # Timer to discover new peers
OnionrCommunicatorTimers( OnionrCommunicatorTimers(
self, lookupadders.lookup_new_peer_transports_with_communicator, 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 # Timer for adjusting which peers
# we actively communicate to at any given time, # we actively communicate to at any given time,

View File

@ -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).""" """Randomly picks peer from pool without bias (using secrets module)."""
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
ret_data = '' ret_data = ''
peer_length = len(kv.get('onlinePeers')) peer_length = len(kv.get('onlinePeers'))
if peer_length <= 0: if peer_length <= 0:

View File

@ -11,6 +11,7 @@ from coredb import keydb
from . import onlinepeers from . import onlinepeers
from onionrtypes import OnionAddressString from onionrtypes import OnionAddressString
from onionrpeers.peerprofiles import PeerProfiles 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 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
@ -33,10 +34,10 @@ def get_peer_profile(kv, address: OnionAddressString) -> 'PeerProfiles':
if profile.address == address: if profile.address == address:
return profile return profile
p = PeerProfiles(address) p = PeerProfiles(address)
profile_inst_list.append(p)
return p return p
def peer_action(shared_state, peer, action, def peer_action(shared_state, peer, action,
returnHeaders=False, max_resp_size=5242880): returnHeaders=False, max_resp_size=5242880):
"""Perform a get request to a peer.""" """Perform a get request to a peer."""

View File

@ -49,7 +49,7 @@ def announce_node(daemon):
break break
else: else:
try: try:
peer = onlinepeers.pick_online_peer(daemon) peer = onlinepeers.pick_online_peer(kv)
except onionrexceptions.OnlinePeerNeeded: except onionrexceptions.OnlinePeerNeeded:
peer = "" peer = ""

View File

@ -78,7 +78,7 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
kv.get('currentDownloading').append(blockHash) kv.get('currentDownloading').append(blockHash)
if len(blockPeers) == 0: if len(blockPeers) == 0:
try: try:
peerUsed = onlinepeers.pick_online_peer(comm_inst) peerUsed = onlinepeers.pick_online_peer(kv)
except onionrexceptions.OnlinePeerNeeded: except onionrexceptions.OnlinePeerNeeded:
continue continue
else: else:

View File

@ -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 # Don't get new peers if we have too many queued up
break break
try: try:
peer = onlinepeers.pick_online_peer() peer = onlinepeers.pick_online_peer(kv)
newAdders = peeraction.peer_action(comm_inst, peer, action='pex') newAdders = peeraction.peer_action(shared_state, peer, action='pex')
except onionrexceptions.OnlinePeerNeeded: except onionrexceptions.OnlinePeerNeeded:
continue continue
try: try:
@ -64,5 +64,3 @@ def lookup_new_peer_transports_with_communicator(shared_state):
except ValueError: except ValueError:
pass pass
kv.get('newPeers').extend(newPeers) kv.get('newPeers').extend(newPeers)
comm_inst.decrementThreadCount(
'lookup_new_peer_transports_with_communicator')

View File

@ -65,7 +65,7 @@ def lookup_blocks_from_communicator(comm_inst):
break break
try: try:
# select random online peer # select random online peer
peer = onlinepeers.pick_online_peer(comm_inst) peer = onlinepeers.pick_online_peer(kv)
except onionrexceptions.OnlinePeerNeeded: except onionrexceptions.OnlinePeerNeeded:
time.sleep(1) time.sleep(1)
continue continue

View File

@ -67,7 +67,7 @@ def upload_blocks_from_communicator(comm_inst: 'OnionrCommunicatorDaemon'):
session = session_manager.add_session(bl) session = session_manager.add_session(bl)
for _ in range(min(len(kv.get('onlinePeers')), 6)): for _ in range(min(len(kv.get('onlinePeers')), 6)):
try: try:
peer = onlinepeers.pick_online_peer(comm_inst) peer = onlinepeers.pick_online_peer(kv)
except onionrexceptions.OnlinePeerNeeded: except onionrexceptions.OnlinePeerNeeded:
continue continue
try: try:

View File

@ -140,7 +140,6 @@ def daemon():
# Initialize the quasi-global variables # Initialize the quasi-global variables
setup_kv(shared_state.get(DeadSimpleKV)) setup_kv(shared_state.get(DeadSimpleKV))
spawn_client_threads(shared_state)
shared_state.get(daemoneventsapi.DaemonEventsBP) shared_state.get(daemoneventsapi.DaemonEventsBP)
Thread(target=shared_state.get(apiservers.ClientAPI).start, Thread(target=shared_state.get(apiservers.ClientAPI).start,
@ -193,6 +192,10 @@ def daemon():
Thread(target=statistics_reporter, args=[shared_state], daemon=True).start() 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) communicator.startCommunicator(shared_state)
clean_ephemeral_services() clean_ephemeral_services()