This repository has been archived on 2024-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-10/src/network/connectionchooser.py
Peter Surda f8b4b427fc
Asyncore update
- bugfixes
- UDP socket for local peer discovery
- new function assembleAddr to unify creating address command
- open port checker functionality (inactive)
- sendBigInv is done in a thread separate from the network IO
thread
2017-05-27 19:09:21 +02:00

20 lines
534 B
Python

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