Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/network/connectionchooser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from queues import Queue
import random
import time

from bmconfigparser import BMConfigParser
import knownnodes
Expand Down Expand Up @@ -33,6 +34,8 @@ def chooseConnection(stream):
if helper_random.randomchoice((False, True)) and not haveOnion:
# discovered peers are already filtered by allowed streams
return getDiscoveredPeer()
while not knownnodes.knownNodes[stream]:
time.sleep(1)
for _ in range(50):
peer = helper_random.randomchoice(knownnodes.knownNodes[stream].keys())
try:
Expand Down
8 changes: 5 additions & 3 deletions src/network/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self):
self.udpSockets = {}
self.streams = []
self.lastSpawned = 0
self.spawnWait = 2
self.spawnWait = 2
self.bootstrapped = False

def connectToStream(self, streamNumber):
Expand Down Expand Up @@ -156,6 +156,8 @@ def loop(self):
Proxy.onionproxy = None
established = sum(1 for c in self.outboundConnections.values() if (c.connected and c.fullyEstablished))
pending = len(self.outboundConnections) - established
while not self.streams:
time.sleep(1)
if established < BMConfigParser().safeGetInt("bitmessagesettings", "maxoutboundconnections"):
for i in range(state.maximumNumberOfHalfOpenConnections - pending):
try:
Expand All @@ -169,7 +171,7 @@ def loop(self):
# don't connect to self
if chosen in state.ownAddresses:
continue

#for c in self.outboundConnections:
# if chosen == c.destination:
# continue
Expand Down Expand Up @@ -247,7 +249,7 @@ def loop(self):
if i.fullyEstablished:
i.append_write_buf(protocol.CreatePacket('ping'))
else:
i.close_reason = "Timeout (%is)" % (time.time() - i.lastTx)
i.close_reason = "Timeout (%is)" % (time.time() - i.lastTx)
i.set_state("close")
for i in self.inboundConnections.values() + self.outboundConnections.values() + self.listeningSockets.values() + self.udpSockets.values():
if not (i.accepting or i.connecting or i.connected):
Expand Down