diff --git a/src/class_receiveDataThread.py b/src/class_receiveDataThread.py index e5293fe8..cc7145e6 100644 --- a/src/class_receiveDataThread.py +++ b/src/class_receiveDataThread.py @@ -814,13 +814,7 @@ class receiveDataThread(threading.Thread): shared.printLock.release() del shared.ackdataForWhichImWatching[encryptedData[readPosition:]] t = ('ackreceived', encryptedData[readPosition:]) - shared.sqlLock.acquire() - shared.sqlSubmitQueue.put( - 'UPDATE sent SET status=? WHERE ackdata=?') - shared.sqlSubmitQueue.put(t) - shared.sqlReturnQueue.get() - shared.sqlSubmitQueue.put('commit') - shared.sqlLock.release() + helper_sent.updateStatusByAckData(t) shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (encryptedData[readPosition:], tr.translateText("MainWindow",'Acknowledgement of the message received. %1').arg(unicode( time.strftime(shared.config.get('bitmessagesettings', 'timeformat'), time.localtime(int(time.time()))), 'utf-8'))))) return @@ -1115,13 +1109,7 @@ class receiveDataThread(threading.Thread): print 'We have been awaiting the arrival of this pubkey.' del shared.neededPubkeys[toRipe] t = (toRipe,) - shared.sqlLock.acquire() - shared.sqlSubmitQueue.put( - '''UPDATE sent SET status='doingmsgpow' WHERE toripe=? AND (status='awaitingpubkey' or status='doingpubkeypow') and folder='sent' ''') - shared.sqlSubmitQueue.put(t) - shared.sqlReturnQueue.get() - shared.sqlSubmitQueue.put('commit') - shared.sqlLock.release() + helper_sent.updateStatusForPossibleNewPubKey(t) shared.workerQueue.put(('sendmessage', '')) else: shared.printLock.acquire() diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index 5b77fdd4..d00a808e 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -2,6 +2,7 @@ import threading import shared import time import sys +import helper_sent '''The singleCleaner class is a timer-driven thread that cleans data structures to free memory, resends messages when a remote node doesn't respond, and sends pong messages to keep connections alive if the network isn't busy. It cleans these data structures in memory: @@ -98,22 +99,14 @@ class singleCleaner(threading.Thread): 'updateStatusBar', 'Doing work necessary to again attempt to request a public key...')) t = (int( time.time()), pubkeyretrynumber + 1, toripe) - shared.sqlSubmitQueue.put( - '''UPDATE sent SET lastactiontime=?, pubkeyretrynumber=?, status='msgqueued' WHERE toripe=?''') - shared.sqlSubmitQueue.put(t) - shared.sqlReturnQueue.get() - shared.sqlSubmitQueue.put('commit') + helper_sent.updateStatusForRerequestPubKey(t) shared.workerQueue.put(('sendmessage', '')) else: # status == msgsent if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))): print 'It has been a long time and we haven\'t heard an acknowledgement to our msg. Sending again.' t = (int( time.time()), msgretrynumber + 1, 'msgqueued', ackdata) - shared.sqlSubmitQueue.put( - '''UPDATE sent SET lastactiontime=?, msgretrynumber=?, status=? WHERE ackdata=?''') - shared.sqlSubmitQueue.put(t) - shared.sqlReturnQueue.get() - shared.sqlSubmitQueue.put('commit') + helper_sent.updateStatusForResend(t) shared.workerQueue.put(('sendmessage', '')) shared.UISignalQueue.put(( 'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...')) diff --git a/src/helper_sent.py b/src/helper_sent.py index dcfe844e..63f85a38 100644 --- a/src/helper_sent.py +++ b/src/helper_sent.py @@ -9,3 +9,34 @@ def insert(t): shared.sqlSubmitQueue.put('commit') shared.sqlLock.release() +def updateStatusByAckData(t): + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put( + 'UPDATE sent SET status=? WHERE ackdata=?') + shared.sqlSubmitQueue.put(t) + shared.sqlReturnQueue.get() + shared.sqlSubmitQueue.put('commit') + shared.sqlLock.release() + +def updateStatusForPossibleNewPubKey(t): + shared.sqlLock.acquire() + shared.sqlSubmitQueue.put( + '''UPDATE sent SET status='doingmsgpow' WHERE toripe=? AND (status='awaitingpubkey' or status='doingpubkeypow') and folder='sent' ''') + shared.sqlSubmitQueue.put(t) + shared.sqlReturnQueue.get() + shared.sqlSubmitQueue.put('commit') + shared.sqlLock.release() + +def updateStatusForResend(t): + shared.sqlSubmitQueue.put( + '''UPDATE sent SET lastactiontime=?, msgretrynumber=?, status=? WHERE ackdata=?''') + shared.sqlSubmitQueue.put(t) + shared.sqlReturnQueue.get() + shared.sqlSubmitQueue.put('commit') + +def updateStatusForRerequestPubKey(t): + shared.sqlSubmitQueue.put( + '''UPDATE sent SET lastactiontime=?, pubkeyretrynumber=?, status='msgqueued' WHERE toripe=?''') + shared.sqlSubmitQueue.put(t) + shared.sqlReturnQueue.get() + shared.sqlSubmitQueue.put('commit') \ No newline at end of file