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: except ValueError:
Proxy.onion_proxy = None Proxy.onion_proxy = None
established = sum(
1 for c in self.outboundConnections.values() established = [
if (c.connected and c.fullyEstablished)) c for c in self.outboundConnections.values()
pending = len(self.outboundConnections) - established if c.connected and c.fullyEstablished]
if established < BMConfigParser().safeGetInt( established_num = len(established)
'bitmessagesettings', 'maxoutboundconnections'): 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( for i in range(
state.maximumNumberOfHalfOpenConnections - pending): state.maximumNumberOfHalfOpenConnections - pending):
try: try: