Define len() for network.BMConnectionPool

This commit is contained in:
Dmitri Bogomolov 2020-06-09 23:00:42 +03:00
parent 1035d2aec4
commit f9dc8eaacf
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
3 changed files with 5 additions and 4 deletions

View File

@ -597,8 +597,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
if ( if (
Peer(self.destination.host, self.peerNode.port) Peer(self.destination.host, self.peerNode.port)
in connectionpool.BMConnectionPool().inboundConnections in connectionpool.BMConnectionPool().inboundConnections
or len(connectionpool.BMConnectionPool().inboundConnections) or len(connectionpool.BMConnectionPool())
+ len(connectionpool.BMConnectionPool().outboundConnections)
> BMConfigParser().safeGetInt( > BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxtotalconnections') 'bitmessagesettings', 'maxtotalconnections')
+ BMConfigParser().safeGetInt( + BMConfigParser().safeGetInt(

View File

@ -72,6 +72,9 @@ class BMConnectionPool(object):
' trustedpeer=<hostname>:<portnumber>' ' trustedpeer=<hostname>:<portnumber>'
) )
def __len__(self):
return len(self.outboundConnections) + len(self.inboundConnections)
def connections(self): def connections(self):
""" """
Shortcut for combined list of connections from Shortcut for combined list of connections from

View File

@ -408,8 +408,7 @@ class TCPServer(AdvancedDispatcher):
state.ownAddresses[Peer(*sock.getsockname())] = True state.ownAddresses[Peer(*sock.getsockname())] = True
if ( if (
len(connectionpool.BMConnectionPool().inboundConnections) len(connectionpool.BMConnectionPool())
+ len(connectionpool.BMConnectionPool().outboundConnections)
> BMConfigParser().safeGetInt( > BMConfigParser().safeGetInt(
'bitmessagesettings', 'maxtotalconnections') 'bitmessagesettings', 'maxtotalconnections')
+ BMConfigParser().safeGetInt( + BMConfigParser().safeGetInt(