From 4b8bd3bf9ed121c7aeff6bda1e25ee1d73b6efe3 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 25 May 2021 17:57:47 +0300 Subject: [PATCH] Close extra outbound connections in BMConnectionPool.loop() --- src/network/connectionpool.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index fffc0bc3..4781adf0 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -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: