Skip to content

Commit

Permalink
Obsolete bitmessagemain.connectToStream(), use BMConnectionPool method
Browse files Browse the repository at this point in the history
  • Loading branch information
g1itch committed May 5, 2020
1 parent c5b77a0 commit d09782e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 32 deletions.
30 changes: 3 additions & 27 deletions src/bitmessagemain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
19 changes: 14 additions & 5 deletions src/helper_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
1 change: 1 addition & 0 deletions src/network/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit d09782e

Please sign in to comment.