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
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,

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)."""
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
ret_data = ''
peer_length = len(kv.get('onlinePeers'))
if peer_length <= 0:

View File

@ -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."""

View File

@ -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 = ""

View File

@ -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:

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
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')

View File

@ -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

View File

@ -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:

View File

@ -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()