Skip to content

Commit 1300222

Browse files
committed
Merge pull request #805 from Atheros1/master
Fix issue #804
2 parents fb9f503 + 4403cde commit 1300222

File tree

2 files changed

+50
-28
lines changed

2 files changed

+50
-28
lines changed

src/api.py

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -622,14 +622,22 @@ def HandleSendMessage(self, params):
622622
elif len(params) == 4:
623623
toAddress, fromAddress, subject, message = params
624624
encodingType = 2
625+
TTL = 4*24*60*60
625626
elif len(params) == 5:
626627
toAddress, fromAddress, subject, message, encodingType = params
628+
TTL = 4*24*60*60
629+
elif len(params) == 6:
630+
toAddress, fromAddress, subject, message, encodingType, TTL = params
627631
if encodingType != 2:
628632
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
629633
subject = self._decode(subject, "base64")
630634
message = self._decode(message, "base64")
631635
if len(subject + message) > (2 ** 18 - 500):
632636
raise APIError(27, 'Message is too long.')
637+
if TTL < 60*60:
638+
TTL = 60*60
639+
if TTL > 28*24*60*60:
640+
TTL = 28*24*60*60
633641
toAddress = addBMIfNotPresent(toAddress)
634642
fromAddress = addBMIfNotPresent(fromAddress)
635643
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress)
@@ -644,8 +652,21 @@ def HandleSendMessage(self, params):
644652

645653
ackdata = OpenSSL.rand(32)
646654

647-
t = ('', toAddress, toRipe, fromAddress, subject, message, ackdata, int(
648-
time.time()), 'msgqueued', 1, 1, 'sent', 2)
655+
t = ('',
656+
toAddress,
657+
toRipe,
658+
fromAddress,
659+
subject,
660+
message,
661+
ackdata,
662+
int(time.time()), # sentTime (this won't change)
663+
int(time.time()), # lastActionTime
664+
0,
665+
'msgqueued',
666+
0,
667+
'sent',
668+
2,
669+
TTL)
649670
helper_sent.insert(t)
650671

651672
toLabel = ''
@@ -667,14 +688,22 @@ def HandleSendBroadcast(self, params):
667688
if len(params) == 3:
668689
fromAddress, subject, message = params
669690
encodingType = 2
691+
TTL = 4*24*60*60
670692
elif len(params) == 4:
671693
fromAddress, subject, message, encodingType = params
694+
TTL = 4*24*60*60
695+
elif len(params) == 5:
696+
fromAddress, subject, message, encodingType, TTL = params
672697
if encodingType != 2:
673698
raise APIError(6, 'The encoding type must be 2 because that is the only one this program currently supports.')
674699
subject = self._decode(subject, "base64")
675700
message = self._decode(message, "base64")
676701
if len(subject + message) > (2 ** 18 - 500):
677702
raise APIError(27, 'Message is too long.')
703+
if TTL < 60*60:
704+
TTL = 60*60
705+
if TTL > 28*24*60*60:
706+
TTL = 28*24*60*60
678707
fromAddress = addBMIfNotPresent(fromAddress)
679708
self._verifyAddress(fromAddress)
680709
try:
@@ -686,9 +715,21 @@ def HandleSendBroadcast(self, params):
686715
toAddress = '[Broadcast subscribers]'
687716
ripe = ''
688717

689-
690-
t = ('', toAddress, ripe, fromAddress, subject, message, ackdata, int(
691-
time.time()), 'broadcastqueued', 1, 1, 'sent', 2)
718+
t = ('',
719+
toAddress,
720+
ripe,
721+
fromAddress,
722+
subject,
723+
message,
724+
ackdata,
725+
int(time.time()), # sentTime (this doesn't change)
726+
int(time.time()), # lastActionTime
727+
0,
728+
'broadcastqueued',
729+
0,
730+
'sent',
731+
2,
732+
TTL)
692733
helper_sent.insert(t)
693734

694735
toLabel = '[Broadcast subscribers]'
@@ -884,23 +925,6 @@ def HandleGetMessageDataByDestinationHash(self, params):
884925
data += ']}'
885926
return data
886927

887-
def HandleGetPubKeyByHash(self, params):
888-
# Method will eventually be used by a particular Android app to
889-
# retrieve pubkeys. Please do not yet add this to the api docs.
890-
if len(params) != 1:
891-
raise APIError(0, 'I need 1 parameter!')
892-
requestedHash, = params
893-
if len(requestedHash) != 40:
894-
raise APIError(19, 'The length of hash should be 20 bytes (encoded in hex thus 40 characters).')
895-
requestedHash = self._decode(requestedHash, "hex")
896-
queryreturn = sqlQuery('''SELECT transmitdata FROM pubkeys WHERE hash = ? ; ''', requestedHash)
897-
data = '{"pubkey":['
898-
for row in queryreturn:
899-
transmitdata, = row
900-
data += json.dumps({'data':transmitdata.encode('hex')}, indent=4, separators=(',', ': '))
901-
data += ']}'
902-
return data
903-
904928
def HandleClientStatus(self, params):
905929
if len(shared.connectedHostsList) == 0:
906930
networkStatus = 'notConnected'
@@ -980,7 +1004,6 @@ def HandleStatusBar(self, params):
9801004
handlers['disseminatePubkey'] = HandleDissimatePubKey
9811005
handlers['getMessageDataByDestinationHash'] = HandleGetMessageDataByDestinationHash
9821006
handlers['getMessageDataByDestinationTag'] = HandleGetMessageDataByDestinationHash
983-
handlers['getPubkeyByHash'] = HandleGetPubKeyByHash
9841007
handlers['clientStatus'] = HandleClientStatus
9851008
handlers['decodeAddress'] = HandleDecodeAddress
9861009

src/class_sendDataThread.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,11 @@ def sendBytes(self, data):
8282
uploadRateLimitBytes = 999999999 # float("inf") doesn't work
8383
else:
8484
uploadRateLimitBytes = shared.config.getint('bitmessagesettings', 'maxuploadrate') * 1000
85-
numberOfBytesWeMaySend = uploadRateLimitBytes - shared.numberOfBytesSentLastSecond
86-
self.sock.sendall(data[:numberOfBytesWeMaySend])
87-
shared.numberOfBytesSent += len(data[:numberOfBytesWeMaySend]) # used for the 'network status' tab in the UI
88-
shared.numberOfBytesSentLastSecond += len(data[:numberOfBytesWeMaySend])
85+
amountSent = self.sock.send(data[:1000])
86+
shared.numberOfBytesSent += amountSent # used for the 'network status' tab in the UI
87+
shared.numberOfBytesSentLastSecond += amountSent
8988
self.lastTimeISentData = int(time.time())
90-
data = data[numberOfBytesWeMaySend:]
89+
data = data[amountSent:]
9190

9291

9392
def run(self):

0 commit comments

Comments
 (0)