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
|
|
|
|
else:
|
2017-05-25 14:59:18 +02:00
|
|
|
try:
|
2017-05-27 19:39:19 +02:00
|
|
|
retval = portCheckerQueue.get(False)
|
|
|
|
portCheckerQueue.task_done()
|
2017-05-25 14:59:18 +02:00
|
|
|
except Queue.Empty:
|
2017-05-27 19:09:21 +02:00
|
|
|
try:
|
2017-05-27 19:39:19 +02:00
|
|
|
retval = peerDiscoveryQueue.get(False)
|
|
|
|
peerDiscoveryQueue.task_done()
|
2017-05-27 19:09:21 +02:00
|
|
|
except Queue.Empty:
|
|
|
|
return random.choice(knownnodes.knownNodes[stream].keys())
|
2017-05-27 19:39:19 +02:00
|
|
|
return retval
|