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 bmconfigparser import BMConfigParser
|
||||||
from debug import logger # this should go before any threads
|
from debug import logger # this should go before any threads
|
||||||
from helper_startup import (
|
from helper_startup import (
|
||||||
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections,
|
adjustHalfOpenConnectionsLimit, start_proxyconfig)
|
||||||
start_proxyconfig
|
|
||||||
)
|
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from knownnodes import readKnownNodes
|
from knownnodes import readKnownNodes
|
||||||
# Network objects and threads
|
# Network objects and threads
|
||||||
|
@ -55,27 +53,6 @@ from threads import (
|
||||||
addressGenerator, objectProcessor, singleCleaner, singleWorker, sqlThread)
|
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():
|
def _fixSocket():
|
||||||
if sys.platform.startswith('linux'):
|
if sys.platform.startswith('linux'):
|
||||||
socket.SO_BINDTODEVICE = 25
|
socket.SO_BINDTODEVICE = 25
|
||||||
|
@ -174,6 +151,7 @@ class Main(object):
|
||||||
"""Start main application"""
|
"""Start main application"""
|
||||||
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
|
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
|
||||||
_fixSocket()
|
_fixSocket()
|
||||||
|
adjustHalfOpenConnectionsLimit()
|
||||||
|
|
||||||
config = BMConfigParser()
|
config = BMConfigParser()
|
||||||
daemon = config.safeGetBoolean('bitmessagesettings', 'daemon')
|
daemon = config.safeGetBoolean('bitmessagesettings', 'daemon')
|
||||||
|
@ -332,7 +310,7 @@ class Main(object):
|
||||||
# start network components if networking is enabled
|
# start network components if networking is enabled
|
||||||
if state.enableNetwork:
|
if state.enableNetwork:
|
||||||
start_proxyconfig()
|
start_proxyconfig()
|
||||||
BMConnectionPool()
|
BMConnectionPool().connectToStream(1)
|
||||||
asyncoreThread = BMNetworkThread()
|
asyncoreThread = BMNetworkThread()
|
||||||
asyncoreThread.daemon = True
|
asyncoreThread.daemon = True
|
||||||
asyncoreThread.start()
|
asyncoreThread.start()
|
||||||
|
@ -356,8 +334,6 @@ class Main(object):
|
||||||
state.uploadThread.daemon = True
|
state.uploadThread.daemon = True
|
||||||
state.uploadThread.start()
|
state.uploadThread.start()
|
||||||
|
|
||||||
connectToStream(1)
|
|
||||||
|
|
||||||
if config.safeGetBoolean('bitmessagesettings', 'upnp'):
|
if config.safeGetBoolean('bitmessagesettings', 'upnp'):
|
||||||
import upnp
|
import upnp
|
||||||
upnpThread = upnp.uPnPThread()
|
upnpThread = upnp.uPnPThread()
|
||||||
|
|
|
@ -276,19 +276,28 @@ def updateConfig():
|
||||||
config.save()
|
config.save()
|
||||||
|
|
||||||
|
|
||||||
def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
|
def adjustHalfOpenConnectionsLimit():
|
||||||
"""Check for (mainly XP and Vista) limitations"""
|
"""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:
|
try:
|
||||||
if sys.platform[0:3] == "win":
|
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())
|
VER_THIS = StrictVersion(platform.version())
|
||||||
return (
|
is_limited = (
|
||||||
StrictVersion("5.1.2600") <= VER_THIS and
|
StrictVersion("5.1.2600") <= VER_THIS and
|
||||||
StrictVersion("6.0.6000") >= VER_THIS
|
StrictVersion("6.0.6000") >= VER_THIS
|
||||||
)
|
)
|
||||||
return False
|
except ValueError:
|
||||||
except Exception:
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
state.maximumNumberOfHalfOpenConnections = 9 if is_limited else 64
|
||||||
|
|
||||||
|
|
||||||
def start_proxyconfig():
|
def start_proxyconfig():
|
||||||
"""Check socksproxytype and start any proxy configuration plugin"""
|
"""Check socksproxytype and start any proxy configuration plugin"""
|
||||||
|
|
|
@ -87,6 +87,7 @@ class BMConnectionPool(object):
|
||||||
def connectToStream(self, streamNumber):
|
def connectToStream(self, streamNumber):
|
||||||
"""Connect to a bitmessage stream"""
|
"""Connect to a bitmessage stream"""
|
||||||
self.streams.append(streamNumber)
|
self.streams.append(streamNumber)
|
||||||
|
state.streamsInWhichIAmParticipating.append(streamNumber)
|
||||||
|
|
||||||
def getConnectionByAddr(self, addr):
|
def getConnectionByAddr(self, addr):
|
||||||
"""
|
"""
|
||||||
|
|
Reference in New Issue
Block a user