This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-16/src/network/connectionchooser.py

20 lines
534 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
else:
try:
return portCheckerQueue.get(False)
except Queue.Empty:
try:
return peerDiscoveryQueue.get(False)
except Queue.Empty:
return random.choice(knownnodes.knownNodes[stream].keys())