2017-05-25 14:59:18 +02:00
|
|
|
from queues import Queue
|
2017-05-24 16:51:49 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
import knownnodes
|
2017-05-27 19:09:21 +02:00
|
|
|
from queues import portCheckerQueue, peerDiscoveryQueue
|
2017-05-24 16:51:49 +02:00
|
|
|
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:
|
2017-05-25 14:59:18 +02:00
|
|
|
try:
|
2017-06-24 12:13:35 +02:00
|
|
|
retval = peerDiscoveryQueue.get(False)
|
|
|
|
peerDiscoveryQueue.task_done()
|
2017-05-25 14:59:18 +02:00
|
|
|
except Queue.Empty:
|
2017-06-24 12:13:35 +02:00
|
|
|
return random.choice(knownnodes.knownNodes[stream].keys())
|
|
|
|
return retval
|