Moved offllinePeers to KV to further reduce coupling
parent
10c1cd7803
commit
dde10b7005
|
@ -64,6 +64,7 @@ class OnionrCommunicatorDaemon:
|
|||
self.kv.put('blockQueue', {})
|
||||
self.kv.put('shutdown', False)
|
||||
self.kv.put('onlinePeers', [])
|
||||
self.kv.put('offlinePeers', [])
|
||||
self.kv.put('currentDownloading', [])
|
||||
self.kv.put('announceCache', {})
|
||||
self.kv.put('newPeers', [])
|
||||
|
@ -87,7 +88,6 @@ class OnionrCommunicatorDaemon:
|
|||
self.delay = 1
|
||||
|
||||
# lists of connected peers and peers we know we can't reach currently
|
||||
self.offlinePeers = []
|
||||
self.cooldownPeer = {}
|
||||
self.connectTimes = {}
|
||||
# list of peer's profiles (onionrpeers.PeerProfile instances)
|
||||
|
|
|
@ -2,6 +2,11 @@
|
|||
|
||||
add bootstrap peers to the communicator peer list
|
||||
"""
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from deadsimplekv import DeadSimpleKV
|
||||
|
||||
from utils import readstatic, gettransports
|
||||
from coredb import keydb
|
||||
"""
|
||||
|
@ -24,8 +29,9 @@ bootstrap_peers = readstatic.read_static('bootstrap-nodes.txt').split(',')
|
|||
|
||||
def add_bootstrap_list_to_peer_list(comm_inst, peerList, db_only=False):
|
||||
"""Add the bootstrap list to the peer list (no duplicates)."""
|
||||
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
|
||||
for i in bootstrap_peers:
|
||||
if i not in peerList and i not in comm_inst.offlinePeers \
|
||||
if i not in peerList and i not in kv.get('offlinePeers') \
|
||||
and i not in gettransports.get() and len(str(i).strip()) > 0:
|
||||
if not db_only:
|
||||
peerList.append(i)
|
||||
|
|
|
@ -68,7 +68,7 @@ def daemon_event_handlers(shared_state: 'TooMany'):
|
|||
|
||||
def restart_tor():
|
||||
restarttor.restart(comm_inst)
|
||||
comm_inst.offlinePeers = []
|
||||
kv.put('offlinePeers', [])
|
||||
|
||||
def test_runtime():
|
||||
Thread(target=comm_inst.shared_state.get_by_string(
|
||||
|
|
|
@ -26,7 +26,7 @@ if TYPE_CHECKING:
|
|||
def clear_offline_peer(comm_inst: 'OnionrCommunicatorDaemon'):
|
||||
"""Remove the longest offline peer to retry later."""
|
||||
try:
|
||||
removed = comm_inst.offlinePeers.pop(0)
|
||||
removed = comm_inst..pop(0)
|
||||
except IndexError:
|
||||
pass
|
||||
else:
|
||||
|
|
|
@ -32,8 +32,8 @@ from coredb import keydb
|
|||
def connect_new_peer_to_communicator(comm_inst, peer='', useBootstrap=False):
|
||||
config = comm_inst.config
|
||||
retData = False
|
||||
tried = comm_inst.offlinePeers
|
||||
kv: "DeadSimpleKV" = comm_inst.shared_state.get_by_string("DeadSimpleKV")
|
||||
tried = kv.get('offlinePeers')
|
||||
transports = gettransports.get()
|
||||
if peer != '':
|
||||
if stringvalidators.validate_transport(peer):
|
||||
|
|
|
@ -54,7 +54,7 @@ def net_check(comm_inst):
|
|||
'This is usually temporary, but bugs and censorship can cause this to persist, in which case you should report it to beardog [at] mailbox.org', # noqa
|
||||
terminal=True)
|
||||
restarttor.restart(comm_inst)
|
||||
comm_inst.offlinePeers = []
|
||||
kv.put('offlinePeers', [])
|
||||
comm_inst.isOnline = False
|
||||
else:
|
||||
comm_inst.isOnline = True
|
||||
|
|
Loading…
Reference in New Issue