diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index d9a7c7f5d8..2a279acaca 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -38,9 +38,7 @@ from bmconfigparser import BMConfigParser from debug import logger # this should go before any threads from helper_startup import ( - isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections, - start_proxyconfig -) + adjustHalfOpenConnectionsLimit, start_proxyconfig) from inventory import Inventory from knownnodes import readKnownNodes # Network objects and threads @@ -55,27 +53,6 @@ addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread) -def connectToStream(streamNumber): - """Connect to a stream""" - state.streamsInWhichIAmParticipating.append(streamNumber) - - if isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): - # Some XP and Vista systems can only have 10 outgoing connections - # at a time. - state.maximumNumberOfHalfOpenConnections = 9 - else: - state.maximumNumberOfHalfOpenConnections = 64 - try: - # don't overload Tor - if BMConfigParser().get( - 'bitmessagesettings', 'socksproxytype') != 'none': - state.maximumNumberOfHalfOpenConnections = 4 - except: - pass - - BMConnectionPool().connectToStream(streamNumber) - - def _fixSocket(): if sys.platform.startswith('linux'): socket.SO_BINDTODEVICE = 25 @@ -174,6 +151,7 @@ def start(self): """Start main application""" # pylint: disable=too-many-statements,too-many-branches,too-many-locals _fixSocket() + adjustHalfOpenConnectionsLimit() config = BMConfigParser() daemon = config.safeGetBoolean('bitmessagesettings', 'daemon') @@ -332,7 +310,7 @@ def start(self): # start network components if networking is enabled if state.enableNetwork: start_proxyconfig() - BMConnectionPool() + BMConnectionPool().connectToStream(1) asyncoreThread = BMNetworkThread() asyncoreThread.daemon = True asyncoreThread.start() @@ -356,8 +334,6 @@ def start(self): state.uploadThread.daemon = True state.uploadThread.start() - connectToStream(1) - if config.safeGetBoolean('bitmessagesettings', 'upnp'): import upnp upnpThread = upnp.uPnPThread() diff --git a/src/helper_startup.py b/src/helper_startup.py index 9711c33917..fcd12aa4de 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -276,19 +276,28 @@ def updateConfig(): config.save() -def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): - """Check for (mainly XP and Vista) limitations""" +def adjustHalfOpenConnectionsLimit(): + """Check and satisfy half-open connections limit (mainly XP and Vista)""" + if BMConfigParser().safeGet( + 'bitmessagesettings', 'socksproxytype', 'none') != 'none': + state.maximumNumberOfHalfOpenConnections = 4 + return + + is_limited = False try: if sys.platform[0:3] == "win": + # Some XP and Vista systems can only have 10 outgoing + # connections at a time. VER_THIS = StrictVersion(platform.version()) - return ( + is_limited = ( StrictVersion("5.1.2600") <= VER_THIS and StrictVersion("6.0.6000") >= VER_THIS ) - return False - except Exception: + except ValueError: pass + state.maximumNumberOfHalfOpenConnections = 9 if is_limited else 64 + def start_proxyconfig(): """Check socksproxytype and start any proxy configuration plugin""" diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index 6264191dbb..77eb58e418 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -87,6 +87,7 @@ def establishedConnections(self): def connectToStream(self, streamNumber): """Connect to a bitmessage stream""" self.streams.append(streamNumber) + state.streamsInWhichIAmParticipating.append(streamNumber) def getConnectionByAddr(self, addr): """