Obsolete bitmessagemain.connectToStream(), use BMConnectionPool method
This commit is contained in:
parent
c5b77a08fa
commit
d09782e53d
|
@ -38,9 +38,7 @@ import state
|
|||
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 @@ from threads import (
|
|||
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 @@ class Main(object):
|
|||
"""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 @@ class Main(object):
|
|||
# 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 @@ class Main(object):
|
|||
state.uploadThread.daemon = True
|
||||
state.uploadThread.start()
|
||||
|
||||
connectToStream(1)
|
||||
|
||||
if config.safeGetBoolean('bitmessagesettings', 'upnp'):
|
||||
import upnp
|
||||
upnpThread = upnp.uPnPThread()
|
||||
|
|
|
@ -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"""
|
||||
|
|
|
@ -87,6 +87,7 @@ class BMConnectionPool(object):
|
|||
def connectToStream(self, streamNumber):
|
||||
"""Connect to a bitmessage stream"""
|
||||
self.streams.append(streamNumber)
|
||||
state.streamsInWhichIAmParticipating.append(streamNumber)
|
||||
|
||||
def getConnectionByAddr(self, addr):
|
||||
"""
|
||||
|
|
Reference in New Issue
Block a user