From 5c3bc63a1f7e1d6c0ce9dc725eff9b3b8974adde Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Thu, 1 Aug 2013 12:16:31 -0400 Subject: [PATCH] Only allow 1 connection per IP --- src/bitmessagemain.py | 4 ++-- src/class_outgoingSynSender.py | 2 +- src/class_receiveDataThread.py | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 16a11c6f..f2ffed92 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -325,7 +325,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): 'base64'), 'message': message.encode('base64'), 'encodingType': encodingtype, 'receivedTime': received, 'read': read}, indent=4, separators=(',', ': ')) data += ']}' return data - elif method == 'getAllInboxMessageIds': + elif method == 'getAllInboxMessageIds' or method == 'getAllInboxMessageIDs': shared.sqlLock.acquire() shared.sqlSubmitQueue.put( '''SELECT msgid FROM inbox where folder='inbox' ORDER BY received''') @@ -374,7 +374,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += json.dumps({'msgid':msgid.encode('hex'), 'toAddress':toAddress, 'fromAddress':fromAddress, 'subject':subject.encode('base64'), 'message':message.encode('base64'), 'encodingType':encodingtype, 'lastActionTime':lastactiontime, 'status':status, 'ackData':ackdata.encode('hex')}, indent=4, separators=(',', ': ')) data += ']}' return data - elif method == 'getAllSentMessageIds': + elif method == 'getAllSentMessageIds' or method == 'getAllSentMessageIDs': shared.sqlLock.acquire() shared.sqlSubmitQueue.put('''SELECT msgid FROM sent where folder='sent' ORDER BY lastactiontime''') shared.sqlSubmitQueue.put('') diff --git a/src/class_outgoingSynSender.py b/src/class_outgoingSynSender.py index aa9cadf1..8a929c7d 100644 --- a/src/class_outgoingSynSender.py +++ b/src/class_outgoingSynSender.py @@ -35,7 +35,7 @@ class outgoingSynSender(threading.Thread): peer, = random.sample(shared.knownNodes[self.streamNumber], 1) shared.knownNodesLock.release() shared.alreadyAttemptedConnectionsListLock.acquire() - while peer in shared.alreadyAttemptedConnectionsList or peer in shared.connectedHostsList: + while peer in shared.alreadyAttemptedConnectionsList or peer.host in shared.connectedHostsList: shared.alreadyAttemptedConnectionsListLock.release() # print 'choosing new sample' random.seed() diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index 5af33157..6adfe490 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -48,7 +48,7 @@ class receiveDataThread(threading.Thread): self.objectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHave = {} self.selfInitiatedConnections = selfInitiatedConnections shared.connectedHostsList[ - self.peer] = 0 # The very fact that this receiveData thread exists shows that we are connected to the remote host. Let's add it to this list so that an outgoingSynSender thread doesn't try to connect to it. + self.peer.host] = 0 # The very fact that this receiveData thread exists shows that we are connected to the remote host. Let's add it to this list so that an outgoingSynSender thread doesn't try to connect to it. self.connectionIsOrWasFullyEstablished = False # set to true after the remote node and I accept each other's version messages. This is needed to allow the user interface to accurately reflect the current number of connections. if self.streamNumber == -1: # This was an incoming connection. Send out a version message if we accept the other node's version message. self.initiatedConnection = False @@ -94,10 +94,10 @@ class receiveDataThread(threading.Thread): pass shared.broadcastToSendDataQueues((0, 'shutdown', self.peer)) try: - del shared.connectedHostsList[self.peer] + del shared.connectedHostsList[self.peer.host] except Exception as err: with shared.printLock: - print 'Could not delete', self.peer, 'from shared.connectedHostsList.', err + print 'Could not delete', self.peer.host, 'from shared.connectedHostsList.', err try: del shared.numberOfObjectsThatWeHaveYetToCheckAndSeeWhetherWeAlreadyHavePerPeer[ @@ -1979,7 +1979,7 @@ class receiveDataThread(threading.Thread): return shared.connectedHostsList[ - self.peer] = 1 # We use this data structure to not only keep track of what hosts we are connected to so that we don't try to connect to them again, but also to list the connections count on the Network Status tab. + self.peer.host] = 1 # We use this data structure to not only keep track of what hosts we are connected to so that we don't try to connect to them again, but also to list the connections count on the Network Status tab. # If this was an incoming connection, then the sendData thread # doesn't know the stream. We have to set it. if not self.initiatedConnection: