From f9dc8eaacf9dac9ce9f10d7e9c240abc68b3fa76 Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 9 Jun 2020 23:00:42 +0300 Subject: [PATCH] Define len() for network.BMConnectionPool --- src/network/bmproto.py | 3 +-- src/network/connectionpool.py | 3 +++ src/network/tcp.py | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/network/bmproto.py b/src/network/bmproto.py index 6c23a234..ef64de94 100644 --- a/src/network/bmproto.py +++ b/src/network/bmproto.py @@ -597,8 +597,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker): if ( Peer(self.destination.host, self.peerNode.port) in connectionpool.BMConnectionPool().inboundConnections - or len(connectionpool.BMConnectionPool().inboundConnections) - + len(connectionpool.BMConnectionPool().outboundConnections) + or len(connectionpool.BMConnectionPool()) > BMConfigParser().safeGetInt( 'bitmessagesettings', 'maxtotalconnections') + BMConfigParser().safeGetInt( diff --git a/src/network/connectionpool.py b/src/network/connectionpool.py index 77eb58e4..fffc0bc3 100644 --- a/src/network/connectionpool.py +++ b/src/network/connectionpool.py @@ -72,6 +72,9 @@ class BMConnectionPool(object): ' trustedpeer=:' ) + def __len__(self): + return len(self.outboundConnections) + len(self.inboundConnections) + def connections(self): """ Shortcut for combined list of connections from diff --git a/src/network/tcp.py b/src/network/tcp.py index df4c9a75..320e776a 100644 --- a/src/network/tcp.py +++ b/src/network/tcp.py @@ -408,8 +408,7 @@ class TCPServer(AdvancedDispatcher): state.ownAddresses[Peer(*sock.getsockname())] = True if ( - len(connectionpool.BMConnectionPool().inboundConnections) - + len(connectionpool.BMConnectionPool().outboundConnections) + len(connectionpool.BMConnectionPool()) > BMConfigParser().safeGetInt( 'bitmessagesettings', 'maxtotalconnections') + BMConfigParser().safeGetInt(