From 05182e7465ee13b2773322489075f277363bf984 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 1 Jul 2015 15:26:23 -0400 Subject: [PATCH 1/2] Make data send rate more accurate --- src/class_sendDataThread.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/class_sendDataThread.py b/src/class_sendDataThread.py index 742b1b95..bb19c9f6 100644 --- a/src/class_sendDataThread.py +++ b/src/class_sendDataThread.py @@ -82,12 +82,11 @@ class sendDataThread(threading.Thread): uploadRateLimitBytes = 999999999 # float("inf") doesn't work else: uploadRateLimitBytes = shared.config.getint('bitmessagesettings', 'maxuploadrate') * 1000 - numberOfBytesWeMaySend = uploadRateLimitBytes - shared.numberOfBytesSentLastSecond - self.sock.sendall(data[:numberOfBytesWeMaySend]) - shared.numberOfBytesSent += len(data[:numberOfBytesWeMaySend]) # used for the 'network status' tab in the UI - shared.numberOfBytesSentLastSecond += len(data[:numberOfBytesWeMaySend]) + amountSent = self.sock.send(data[:1000]) + shared.numberOfBytesSent += amountSent # used for the 'network status' tab in the UI + shared.numberOfBytesSentLastSecond += amountSent self.lastTimeISentData = int(time.time()) - data = data[numberOfBytesWeMaySend:] + data = data[amountSent:] def run(self): -- 2.45.1 From 4403cde52bcd4df9240b4b2518ce281bf5d683f8 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 15 Jul 2015 11:56:24 -0400 Subject: [PATCH 2/2] Fix issue #804 --- src/api.py | 69 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 23 deletions(-) diff --git a/src/api.py b/src/api.py index 3f44e932..f142953b 100644 --- a/src/api.py +++ b/src/api.py @@ -622,14 +622,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): elif len(params) == 4: toAddress, fromAddress, subject, message = params encodingType = 2 + TTL = 4*24*60*60 elif len(params) == 5: toAddress, fromAddress, subject, message, encodingType = params + TTL = 4*24*60*60 + elif len(params) == 6: + toAddress, fromAddress, subject, message, encodingType, TTL = params if encodingType != 2: raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.') subject = self._decode(subject, "base64") message = self._decode(message, "base64") if len(subject + message) > (2 ** 18 - 500): raise APIError(27, 'Message is too long.') + if TTL < 60*60: + TTL = 60*60 + if TTL > 28*24*60*60: + TTL = 28*24*60*60 toAddress = addBMIfNotPresent(toAddress) fromAddress = addBMIfNotPresent(fromAddress) status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress) @@ -644,8 +652,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): ackdata = OpenSSL.rand(32) - t = ('', toAddress, toRipe, fromAddress, subject, message, ackdata, int( - time.time()), 'msgqueued', 1, 1, 'sent', 2) + t = ('', + toAddress, + toRipe, + fromAddress, + subject, + message, + ackdata, + int(time.time()), # sentTime (this won't change) + int(time.time()), # lastActionTime + 0, + 'msgqueued', + 0, + 'sent', + 2, + TTL) helper_sent.insert(t) toLabel = '' @@ -667,14 +688,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if len(params) == 3: fromAddress, subject, message = params encodingType = 2 + TTL = 4*24*60*60 elif len(params) == 4: fromAddress, subject, message, encodingType = params + TTL = 4*24*60*60 + elif len(params) == 5: + fromAddress, subject, message, encodingType, TTL = params if encodingType != 2: raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.') subject = self._decode(subject, "base64") message = self._decode(message, "base64") if len(subject + message) > (2 ** 18 - 500): raise APIError(27, 'Message is too long.') + if TTL < 60*60: + TTL = 60*60 + if TTL > 28*24*60*60: + TTL = 28*24*60*60 fromAddress = addBMIfNotPresent(fromAddress) self._verifyAddress(fromAddress) try: @@ -686,9 +715,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): toAddress = '[Broadcast subscribers]' ripe = '' - - t = ('', toAddress, ripe, fromAddress, subject, message, ackdata, int( - time.time()), 'broadcastqueued', 1, 1, 'sent', 2) + t = ('', + toAddress, + ripe, + fromAddress, + subject, + message, + ackdata, + int(time.time()), # sentTime (this doesn't change) + int(time.time()), # lastActionTime + 0, + 'broadcastqueued', + 0, + 'sent', + 2, + TTL) helper_sent.insert(t) toLabel = '[Broadcast subscribers]' @@ -884,23 +925,6 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): data += ']}' return data - def HandleGetPubKeyByHash(self, params): - # Method will eventually be used by a particular Android app to - # retrieve pubkeys. Please do not yet add this to the api docs. - if len(params) != 1: - raise APIError(0, 'I need 1 parameter!') - requestedHash, = params - if len(requestedHash) != 40: - raise APIError(19, 'The length of hash should be 20 bytes (encoded in hex thus 40 characters).') - requestedHash = self._decode(requestedHash, "hex") - queryreturn = sqlQuery('''SELECT transmitdata FROM pubkeys WHERE hash = ? ; ''', requestedHash) - data = '{"pubkey":[' - for row in queryreturn: - transmitdata, = row - data += json.dumps({'data':transmitdata.encode('hex')}, indent=4, separators=(',', ': ')) - data += ']}' - return data - def HandleClientStatus(self, params): if len(shared.connectedHostsList) == 0: networkStatus = 'notConnected' @@ -980,7 +1004,6 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): handlers['disseminatePubkey'] = HandleDissimatePubKey handlers['getMessageDataByDestinationHash'] = HandleGetMessageDataByDestinationHash handlers['getMessageDataByDestinationTag'] = HandleGetMessageDataByDestinationHash - handlers['getPubkeyByHash'] = HandleGetPubKeyByHash handlers['clientStatus'] = HandleClientStatus handlers['decodeAddress'] = HandleDecodeAddress -- 2.45.1