Refactoring various SQL into helper_sent.py
This commit is contained in:
parent
bfdb04716a
commit
9c5104d2e1
|
@ -814,13 +814,7 @@ class receiveDataThread(threading.Thread):
|
||||||
shared.printLock.release()
|
shared.printLock.release()
|
||||||
del shared.ackdataForWhichImWatching[encryptedData[readPosition:]]
|
del shared.ackdataForWhichImWatching[encryptedData[readPosition:]]
|
||||||
t = ('ackreceived', encryptedData[readPosition:])
|
t = ('ackreceived', encryptedData[readPosition:])
|
||||||
shared.sqlLock.acquire()
|
helper_sent.updateStatusByAckData(t)
|
||||||
shared.sqlSubmitQueue.put(
|
|
||||||
'UPDATE sent SET status=? WHERE ackdata=?')
|
|
||||||
shared.sqlSubmitQueue.put(t)
|
|
||||||
shared.sqlReturnQueue.get()
|
|
||||||
shared.sqlSubmitQueue.put('commit')
|
|
||||||
shared.sqlLock.release()
|
|
||||||
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (encryptedData[readPosition:], tr.translateText("MainWindow",'Acknowledgement of the message received. %1').arg(unicode(
|
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')))))
|
time.strftime(shared.config.get('bitmessagesettings', 'timeformat'), time.localtime(int(time.time()))), 'utf-8')))))
|
||||||
return
|
return
|
||||||
|
@ -1115,13 +1109,7 @@ class receiveDataThread(threading.Thread):
|
||||||
print 'We have been awaiting the arrival of this pubkey.'
|
print 'We have been awaiting the arrival of this pubkey.'
|
||||||
del shared.neededPubkeys[toRipe]
|
del shared.neededPubkeys[toRipe]
|
||||||
t = (toRipe,)
|
t = (toRipe,)
|
||||||
shared.sqlLock.acquire()
|
helper_sent.updateStatusForPossibleNewPubKey(t)
|
||||||
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()
|
|
||||||
shared.workerQueue.put(('sendmessage', ''))
|
shared.workerQueue.put(('sendmessage', ''))
|
||||||
else:
|
else:
|
||||||
shared.printLock.acquire()
|
shared.printLock.acquire()
|
||||||
|
|
|
@ -2,6 +2,7 @@ import threading
|
||||||
import shared
|
import shared
|
||||||
import time
|
import time
|
||||||
import sys
|
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.
|
'''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:
|
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...'))
|
'updateStatusBar', 'Doing work necessary to again attempt to request a public key...'))
|
||||||
t = (int(
|
t = (int(
|
||||||
time.time()), pubkeyretrynumber + 1, toripe)
|
time.time()), pubkeyretrynumber + 1, toripe)
|
||||||
shared.sqlSubmitQueue.put(
|
helper_sent.updateStatusForRerequestPubKey(t)
|
||||||
'''UPDATE sent SET lastactiontime=?, pubkeyretrynumber=?, status='msgqueued' WHERE toripe=?''')
|
|
||||||
shared.sqlSubmitQueue.put(t)
|
|
||||||
shared.sqlReturnQueue.get()
|
|
||||||
shared.sqlSubmitQueue.put('commit')
|
|
||||||
shared.workerQueue.put(('sendmessage', ''))
|
shared.workerQueue.put(('sendmessage', ''))
|
||||||
else: # status == msgsent
|
else: # status == msgsent
|
||||||
if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))):
|
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.'
|
print 'It has been a long time and we haven\'t heard an acknowledgement to our msg. Sending again.'
|
||||||
t = (int(
|
t = (int(
|
||||||
time.time()), msgretrynumber + 1, 'msgqueued', ackdata)
|
time.time()), msgretrynumber + 1, 'msgqueued', ackdata)
|
||||||
shared.sqlSubmitQueue.put(
|
helper_sent.updateStatusForResend(t)
|
||||||
'''UPDATE sent SET lastactiontime=?, msgretrynumber=?, status=? WHERE ackdata=?''')
|
|
||||||
shared.sqlSubmitQueue.put(t)
|
|
||||||
shared.sqlReturnQueue.get()
|
|
||||||
shared.sqlSubmitQueue.put('commit')
|
|
||||||
shared.workerQueue.put(('sendmessage', ''))
|
shared.workerQueue.put(('sendmessage', ''))
|
||||||
shared.UISignalQueue.put((
|
shared.UISignalQueue.put((
|
||||||
'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...'))
|
'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...'))
|
||||||
|
|
|
@ -9,3 +9,34 @@ def insert(t):
|
||||||
shared.sqlSubmitQueue.put('commit')
|
shared.sqlSubmitQueue.put('commit')
|
||||||
shared.sqlLock.release()
|
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')
|
Reference in New Issue
Block a user