Fix issue #804 #805
69
src/api.py
69
src/api.py
|
@ -622,14 +622,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
elif len(params) == 4:
|
elif len(params) == 4:
|
||||||
toAddress, fromAddress, subject, message = params
|
toAddress, fromAddress, subject, message = params
|
||||||
encodingType = 2
|
encodingType = 2
|
||||||
|
TTL = 4*24*60*60
|
||||||
elif len(params) == 5:
|
elif len(params) == 5:
|
||||||
toAddress, fromAddress, subject, message, encodingType = params
|
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:
|
if encodingType != 2:
|
||||||
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
|
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
|
||||||
subject = self._decode(subject, "base64")
|
subject = self._decode(subject, "base64")
|
||||||
message = self._decode(message, "base64")
|
message = self._decode(message, "base64")
|
||||||
if len(subject + message) > (2 ** 18 - 500):
|
if len(subject + message) > (2 ** 18 - 500):
|
||||||
raise APIError(27, 'Message is too long.')
|
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)
|
toAddress = addBMIfNotPresent(toAddress)
|
||||||
fromAddress = addBMIfNotPresent(fromAddress)
|
fromAddress = addBMIfNotPresent(fromAddress)
|
||||||
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress)
|
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress)
|
||||||
|
@ -644,8 +652,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
|
|
||||||
ackdata = OpenSSL.rand(32)
|
ackdata = OpenSSL.rand(32)
|
||||||
|
|
||||||
t = ('', toAddress, toRipe, fromAddress, subject, message, ackdata, int(
|
t = ('',
|
||||||
time.time()), 'msgqueued', 1, 1, 'sent', 2)
|
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)
|
helper_sent.insert(t)
|
||||||
|
|
||||||
toLabel = ''
|
toLabel = ''
|
||||||
|
@ -667,14 +688,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
if len(params) == 3:
|
if len(params) == 3:
|
||||||
fromAddress, subject, message = params
|
fromAddress, subject, message = params
|
||||||
encodingType = 2
|
encodingType = 2
|
||||||
|
TTL = 4*24*60*60
|
||||||
elif len(params) == 4:
|
elif len(params) == 4:
|
||||||
fromAddress, subject, message, encodingType = params
|
fromAddress, subject, message, encodingType = params
|
||||||
|
TTL = 4*24*60*60
|
||||||
|
elif len(params) == 5:
|
||||||
|
fromAddress, subject, message, encodingType, TTL = params
|
||||||
if encodingType != 2:
|
if encodingType != 2:
|
||||||
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
|
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
|
||||||
subject = self._decode(subject, "base64")
|
subject = self._decode(subject, "base64")
|
||||||
message = self._decode(message, "base64")
|
message = self._decode(message, "base64")
|
||||||
if len(subject + message) > (2 ** 18 - 500):
|
if len(subject + message) > (2 ** 18 - 500):
|
||||||
raise APIError(27, 'Message is too long.')
|
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)
|
fromAddress = addBMIfNotPresent(fromAddress)
|
||||||
self._verifyAddress(fromAddress)
|
self._verifyAddress(fromAddress)
|
||||||
try:
|
try:
|
||||||
|
@ -686,9 +715,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
toAddress = '[Broadcast subscribers]'
|
toAddress = '[Broadcast subscribers]'
|
||||||
ripe = ''
|
ripe = ''
|
||||||
|
|
||||||
|
t = ('',
|
||||||
t = ('', toAddress, ripe, fromAddress, subject, message, ackdata, int(
|
toAddress,
|
||||||
time.time()), 'broadcastqueued', 1, 1, 'sent', 2)
|
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)
|
helper_sent.insert(t)
|
||||||
|
|
||||||
toLabel = '[Broadcast subscribers]'
|
toLabel = '[Broadcast subscribers]'
|
||||||
|
@ -884,23 +925,6 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
data += ']}'
|
data += ']}'
|
||||||
return 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):
|
def HandleClientStatus(self, params):
|
||||||
if len(shared.connectedHostsList) == 0:
|
if len(shared.connectedHostsList) == 0:
|
||||||
networkStatus = 'notConnected'
|
networkStatus = 'notConnected'
|
||||||
|
@ -980,7 +1004,6 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
handlers['disseminatePubkey'] = HandleDissimatePubKey
|
handlers['disseminatePubkey'] = HandleDissimatePubKey
|
||||||
handlers['getMessageDataByDestinationHash'] = HandleGetMessageDataByDestinationHash
|
handlers['getMessageDataByDestinationHash'] = HandleGetMessageDataByDestinationHash
|
||||||
handlers['getMessageDataByDestinationTag'] = HandleGetMessageDataByDestinationHash
|
handlers['getMessageDataByDestinationTag'] = HandleGetMessageDataByDestinationHash
|
||||||
handlers['getPubkeyByHash'] = HandleGetPubKeyByHash
|
|
||||||
handlers['clientStatus'] = HandleClientStatus
|
handlers['clientStatus'] = HandleClientStatus
|
||||||
handlers['decodeAddress'] = HandleDecodeAddress
|
handlers['decodeAddress'] = HandleDecodeAddress
|
||||||
|
|
||||||
|
|
|
@ -82,12 +82,11 @@ class sendDataThread(threading.Thread):
|
||||||
uploadRateLimitBytes = 999999999 # float("inf") doesn't work
|
uploadRateLimitBytes = 999999999 # float("inf") doesn't work
|
||||||
else:
|
else:
|
||||||
uploadRateLimitBytes = shared.config.getint('bitmessagesettings', 'maxuploadrate') * 1000
|
uploadRateLimitBytes = shared.config.getint('bitmessagesettings', 'maxuploadrate') * 1000
|
||||||
numberOfBytesWeMaySend = uploadRateLimitBytes - shared.numberOfBytesSentLastSecond
|
amountSent = self.sock.send(data[:1000])
|
||||||
self.sock.sendall(data[:numberOfBytesWeMaySend])
|
shared.numberOfBytesSent += amountSent # used for the 'network status' tab in the UI
|
||||||
shared.numberOfBytesSent += len(data[:numberOfBytesWeMaySend]) # used for the 'network status' tab in the UI
|
shared.numberOfBytesSentLastSecond += amountSent
|
||||||
shared.numberOfBytesSentLastSecond += len(data[:numberOfBytesWeMaySend])
|
|
||||||
self.lastTimeISentData = int(time.time())
|
self.lastTimeISentData = int(time.time())
|
||||||
data = data[numberOfBytesWeMaySend:]
|
data = data[amountSent:]
|
||||||
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
Reference in New Issue
Block a user