PyBitmessage-2021-04-27/src/network/connectionchooser.py

22 lines
598 B
Python
Raw Normal View History

from queues import Queue
import random
from bmconfigparser import BMConfigParser
import knownnodes
from queues import portCheckerQueue, peerDiscoveryQueue
import state
def chooseConnection(stream):
if state.trustedPeer:
return state.trustedPeer
2017-06-24 12:13:35 +02:00
try:
retval = portCheckerQueue.get(False)
portCheckerQueue.task_done()
except Queue.Empty:
try:
2017-06-24 12:13:35 +02:00
retval = peerDiscoveryQueue.get(False)
peerDiscoveryQueue.task_done()
except Queue.Empty:
2017-06-24 12:13:35 +02:00
return random.choice(knownnodes.knownNodes[stream].keys())
return retval