connectionpool.py pylint fixes
This commit is contained in:
parent
5521c16478
commit
f1b6b16940
|
@ -1,3 +1,7 @@
|
||||||
|
"""
|
||||||
|
src/network/connectionpool.py
|
||||||
|
==================================
|
||||||
|
"""
|
||||||
import errno
|
import errno
|
||||||
import re
|
import re
|
||||||
import socket
|
import socket
|
||||||
|
@ -20,6 +24,7 @@ from udp import UDPSocket
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
|
# pylint: disable=too-many-instance-attributes
|
||||||
class BMConnectionPool(object):
|
class BMConnectionPool(object):
|
||||||
"""Pool of all existing connections"""
|
"""Pool of all existing connections"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -68,8 +73,8 @@ class BMConnectionPool(object):
|
||||||
def isAlreadyConnected(self, nodeid):
|
def isAlreadyConnected(self, nodeid):
|
||||||
"""Check if we're already connected to this peer"""
|
"""Check if we're already connected to this peer"""
|
||||||
for i in (
|
for i in (
|
||||||
self.inboundConnections.values() +
|
self.inboundConnections.values() +
|
||||||
self.outboundConnections.values()
|
self.outboundConnections.values()
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
if nodeid == i.nodeid:
|
if nodeid == i.nodeid:
|
||||||
|
@ -113,7 +118,8 @@ class BMConnectionPool(object):
|
||||||
pass
|
pass
|
||||||
connection.handle_close()
|
connection.handle_close()
|
||||||
|
|
||||||
def getListeningIP(self):
|
@staticmethod
|
||||||
|
def getListeningIP():
|
||||||
"""What IP are we supposed to be listening on?"""
|
"""What IP are we supposed to be listening on?"""
|
||||||
if BMConfigParser().safeGet(
|
if BMConfigParser().safeGet(
|
||||||
"bitmessagesettings", "onionhostname").endswith(".onion"):
|
"bitmessagesettings", "onionhostname").endswith(".onion"):
|
||||||
|
@ -123,8 +129,8 @@ class BMConnectionPool(object):
|
||||||
host = '127.0.0.1'
|
host = '127.0.0.1'
|
||||||
if (BMConfigParser().safeGetBoolean(
|
if (BMConfigParser().safeGetBoolean(
|
||||||
"bitmessagesettings", "sockslisten") or
|
"bitmessagesettings", "sockslisten") or
|
||||||
BMConfigParser().safeGet(
|
BMConfigParser().safeGet(
|
||||||
"bitmessagesettings", "socksproxytype") == "none"):
|
"bitmessagesettings", "socksproxytype") == "none"):
|
||||||
# python doesn't like bind + INADDR_ANY?
|
# python doesn't like bind + INADDR_ANY?
|
||||||
# host = socket.INADDR_ANY
|
# host = socket.INADDR_ANY
|
||||||
host = BMConfigParser().get("network", "bind")
|
host = BMConfigParser().get("network", "bind")
|
||||||
|
@ -154,7 +160,7 @@ class BMConnectionPool(object):
|
||||||
udpSocket = UDPSocket(host=bind, announcing=True)
|
udpSocket = UDPSocket(host=bind, announcing=True)
|
||||||
self.udpSockets[udpSocket.listening.host] = udpSocket
|
self.udpSockets[udpSocket.listening.host] = udpSocket
|
||||||
|
|
||||||
def loop(self):
|
def loop(self): # pylint: disable=too-many-branches, too-many-statements
|
||||||
"""Main Connectionpool's loop"""
|
"""Main Connectionpool's loop"""
|
||||||
# defaults to empty loop if outbound connections are maxed
|
# defaults to empty loop if outbound connections are maxed
|
||||||
spawnConnections = False
|
spawnConnections = False
|
||||||
|
@ -170,12 +176,13 @@ class BMConnectionPool(object):
|
||||||
onionsocksproxytype = BMConfigParser().safeGet(
|
onionsocksproxytype = BMConfigParser().safeGet(
|
||||||
'bitmessagesettings', 'onionsocksproxytype', '')
|
'bitmessagesettings', 'onionsocksproxytype', '')
|
||||||
if (socksproxytype[:5] == 'SOCKS' and
|
if (socksproxytype[:5] == 'SOCKS' and
|
||||||
not BMConfigParser().safeGetBoolean(
|
not BMConfigParser().safeGetBoolean(
|
||||||
'bitmessagesettings', 'sockslisten') and
|
'bitmessagesettings', 'sockslisten') and
|
||||||
'.onion' not in BMConfigParser().safeGet(
|
'.onion' not in BMConfigParser().safeGet(
|
||||||
'bitmessagesettings', 'onionhostname', '')):
|
'bitmessagesettings', 'onionhostname', '')):
|
||||||
acceptConnections = False
|
acceptConnections = False
|
||||||
|
|
||||||
|
# pylint: disable=too-many-nested-blocks
|
||||||
if spawnConnections:
|
if spawnConnections:
|
||||||
if not knownnodes.knownNodesActual:
|
if not knownnodes.knownNodesActual:
|
||||||
helper_bootstrap.dns()
|
helper_bootstrap.dns()
|
||||||
|
@ -241,8 +248,8 @@ class BMConnectionPool(object):
|
||||||
self.lastSpawned = time.time()
|
self.lastSpawned = time.time()
|
||||||
else:
|
else:
|
||||||
for i in (
|
for i in (
|
||||||
self.inboundConnections.values() +
|
self.inboundConnections.values() +
|
||||||
self.outboundConnections.values()
|
self.outboundConnections.values()
|
||||||
):
|
):
|
||||||
# FIXME: rating will be increased after next connection
|
# FIXME: rating will be increased after next connection
|
||||||
i.handle_close()
|
i.handle_close()
|
||||||
|
@ -253,8 +260,8 @@ class BMConnectionPool(object):
|
||||||
self.startListening()
|
self.startListening()
|
||||||
else:
|
else:
|
||||||
for bind in re.sub(
|
for bind in re.sub(
|
||||||
"[^\w.]+", " ",
|
'[^\w.]+', ' ', # pylint: disable=anomalous-backslash-in-string
|
||||||
BMConfigParser().safeGet('network', 'bind')
|
BMConfigParser().safeGet('network', 'bind')
|
||||||
).split():
|
).split():
|
||||||
self.startListening(bind)
|
self.startListening(bind)
|
||||||
logger.info('Listening for incoming connections.')
|
logger.info('Listening for incoming connections.')
|
||||||
|
@ -263,8 +270,8 @@ class BMConnectionPool(object):
|
||||||
self.startUDPSocket()
|
self.startUDPSocket()
|
||||||
else:
|
else:
|
||||||
for bind in re.sub(
|
for bind in re.sub(
|
||||||
"[^\w.]+", " ",
|
'[^\w.]+', ' ', # pylint: disable=anomalous-backslash-in-string
|
||||||
BMConfigParser().safeGet('network', 'bind')
|
BMConfigParser().safeGet('network', 'bind')
|
||||||
).split():
|
).split():
|
||||||
self.startUDPSocket(bind)
|
self.startUDPSocket(bind)
|
||||||
self.startUDPSocket(False)
|
self.startUDPSocket(False)
|
||||||
|
@ -288,8 +295,8 @@ class BMConnectionPool(object):
|
||||||
|
|
||||||
reaper = []
|
reaper = []
|
||||||
for i in (
|
for i in (
|
||||||
self.inboundConnections.values() +
|
self.inboundConnections.values() +
|
||||||
self.outboundConnections.values()
|
self.outboundConnections.values()
|
||||||
):
|
):
|
||||||
minTx = time.time() - 20
|
minTx = time.time() - 20
|
||||||
if i.fullyEstablished:
|
if i.fullyEstablished:
|
||||||
|
@ -302,10 +309,10 @@ class BMConnectionPool(object):
|
||||||
time.time() - i.lastTx)
|
time.time() - i.lastTx)
|
||||||
i.set_state("close")
|
i.set_state("close")
|
||||||
for i in (
|
for i in (
|
||||||
self.inboundConnections.values() +
|
self.inboundConnections.values() +
|
||||||
self.outboundConnections.values() +
|
self.outboundConnections.values() +
|
||||||
self.listeningSockets.values() +
|
self.listeningSockets.values() +
|
||||||
self.udpSockets.values()
|
self.udpSockets.values()
|
||||||
):
|
):
|
||||||
if not (i.accepting or i.connecting or i.connected):
|
if not (i.accepting or i.connecting or i.connected):
|
||||||
reaper.append(i)
|
reaper.append(i)
|
||||||
|
|
Reference in New Issue
Block a user