Close extra outbound connections in BMConnectionPool.loop()

This commit is contained in:
Dmitri Bogomolov 2021-05-25 17:57:47 +03:00
parent ab7c500a12
commit 4b8bd3bf9e
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13

View File

@ -282,12 +282,18 @@ class BMConnectionPool(object):
)
except ValueError:
Proxy.onion_proxy = None
established = sum(
1 for c in self.outboundConnections.values()
if (c.connected and c.fullyEstablished))
pending = len(self.outboundConnections) - established
if established < BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxoutboundconnections'):
established = [
c for c in self.outboundConnections.values()
if c.connected and c.fullyEstablished]
established_num = len(established)
pending = len(self.outboundConnections) - established_num
excess = established_num - BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxoutboundconnections')
if excess > 0:
for _ in range(excess):
established.pop().handle_close()
else:
for i in range(
state.maximumNumberOfHalfOpenConnections - pending):
try: