Don't freeze when out of known nodes

- bitmessage could end up having no known nodes and then it would
  freeze. Now it shouldn't freeze, however it can still end up without
  known nodes until a restart in some cases (e.g. when suspending the
  computer for more then 3 days while BM is running)
This commit is contained in:
Peter Šurda 2016-08-14 15:03:18 +02:00
parent 306a2495e0
commit 4117195b61
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -37,7 +37,12 @@ class outgoingSynSender(threading.Thread, StoppableThread):
else: else:
while not shared.shutdown: while not shared.shutdown:
shared.knownNodesLock.acquire() shared.knownNodesLock.acquire()
peer, = random.sample(shared.knownNodes[self.streamNumber], 1) try:
peer, = random.sample(shared.knownNodes[self.streamNumber], 1)
except ValueError: # no known nodes
shared.knownNodesLock.release()
time.sleep(1)
continue
priority = (183600 - (time.time() - shared.knownNodes[self.streamNumber][peer])) / 183600 # 2 days and 3 hours priority = (183600 - (time.time() - shared.knownNodes[self.streamNumber][peer])) / 183600 # 2 days and 3 hours
shared.knownNodesLock.release() shared.knownNodesLock.release()
if shared.config.get('bitmessagesettings', 'socksproxytype') != 'none': if shared.config.get('bitmessagesettings', 'socksproxytype') != 'none':