MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / BMConnectionPool

Class BMConnectionPool

src/network/connectionpool.py:21–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19
20@Singleton
21class BMConnectionPool(object):
22 def __init__(self):
23 asyncore.set_rates(
24 BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"),
25 BMConfigParser().safeGetInt("bitmessagesettings", "maxuploadrate"))
26 self.outboundConnections = {}
27 self.inboundConnections = {}
28 self.listeningSockets = {}
29 self.udpSockets = {}
30 self.streams = []
31 self.lastSpawned = 0
32 self.spawnWait = 2
33 self.bootstrapped = False
34
35 def connectToStream(self, streamNumber):
36 self.streams.append(streamNumber)
37
38 def getConnectionByAddr(self, addr):
39 if addr in self.inboundConnections:
40 return self.inboundConnections[addr]
41 try:
42 if addr.host in self.inboundConnections:
43 return self.inboundConnections[addr.host]
44 except AttributeError:
45 pass
46 if addr in self.outboundConnections:
47 return self.outboundConnections[addr]
48 try:
49 if addr.host in self.udpSockets:
50 return self.udpSockets[addr.host]
51 except AttributeError:
52 pass
53 raise KeyError
54
55 def isAlreadyConnected(self, nodeid):
56 for i in self.inboundConnections.values() + self.outboundConnections.values():
57 try:
58 if nodeid == i.nodeid:
59 return True
60 except AttributeError:
61 pass
62 return False
63
64 def addConnection(self, connection):
65 if isinstance(connection, UDPSocket):
66 return
67 if connection.isOutbound:
68 self.outboundConnections[connection.destination] = connection
69 else:
70 if connection.destination.host in self.inboundConnections:
71 self.inboundConnections[connection.destination] = connection
72 else:
73 self.inboundConnections[connection.destination.host] = connection
74
75 def removeConnection(self, connection):
76 if isinstance(connection, UDPSocket):
77 del self.udpSockets[connection.listening.host]
78 elif isinstance(connection, TCPServer):

Callers 14

runMethod · 0.90
runMethod · 0.90
connectToStreamFunction · 0.90
startMethod · 0.90
runMethod · 0.90
stopThreadMethod · 0.90
announceSelfMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90
runMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected