From 30044f75163af962f8a6e66a3e0ea316e9f72458 Mon Sep 17 00:00:00 2001 From: navjot Date: Sat, 19 Sep 2020 17:28:23 +0530 Subject: [PATCH 1/3] implemented filter query in sent table on the bases of folder= 'sent' --- src/class_singleCleaner.py | 4 +-- src/class_singleWorker.py | 51 +++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index 03ba1f9c92..4555b40f34 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -179,7 +179,7 @@ def resendPubkeyRequest(self, address): 'Doing work necessary to again attempt to request a public key...' )) sqlExecute( - '''UPDATE sent SET status='msgqueued' WHERE toaddress=?''', + '''UPDATE sent SET status='msgqueued' WHERE toaddress=? AND folder='sent' ''', address) queues.workerQueue.put(('sendmessage', '')) @@ -190,7 +190,7 @@ def resendMsg(self, ackdata): ' to our msg. Sending again.' ) sqlExecute( - '''UPDATE sent SET status='msgqueued' WHERE ackdata=?''', + '''UPDATE sent SET status='msgqueued' WHERE ackdata=? AND folder='sent' ''', ackdata) queues.workerQueue.put(('sendmessage', '')) queues.UISignalQueue.put(( diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index 699506def1..c8640e49dd 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -96,7 +96,7 @@ def run(self): # Initialize the state.ackdataForWhichImWatching data structure queryreturn = sqlQuery( - '''SELECT ackdata FROM sent WHERE status = 'msgsent' ''') + '''SELECT ackdata FROM sent WHERE status = 'msgsent' AND folder = 'sent' ''') for row in queryreturn: ackdata, = row self.logger.info('Watching for ackdata %s', hexlify(ackdata)) @@ -109,7 +109,7 @@ def run(self): newack = '\x00\x00\x00\x02\x01\x01' + oldack state.ackdataForWhichImWatching[newack] = 0 sqlExecute( - 'UPDATE sent SET ackdata=? WHERE ackdata=?', + 'UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = "sent" ', newack, oldack ) del state.ackdataForWhichImWatching[oldack] @@ -522,7 +522,7 @@ def sendBroadcast(self): sqlExecute( '''UPDATE sent SET status='broadcastqueued' ''' - '''WHERE status = 'doingbroadcastpow' ''') + '''WHERE status = 'doingbroadcastpow' AND folder = 'sent' ''') queryreturn = sqlQuery( '''SELECT fromaddress, subject, message, ''' ''' ackdata, ttl, encodingtype FROM sent ''' @@ -556,10 +556,12 @@ def sendBroadcast(self): )) continue - sqlExecute( + if not sqlExecute( '''UPDATE sent SET status='doingbroadcastpow' ''' - ''' WHERE ackdata=? AND status='broadcastqueued' ''', - ackdata) + ''' WHERE ackdata=? AND status='broadcastqueued' ''' + ''' AND folder='sent' ''', + ackdata): + continue # At this time these pubkeys are 65 bytes long # because they include the encoding byte which we won't @@ -681,7 +683,7 @@ def sendBroadcast(self): # a 'broadcastsent' status sqlExecute( 'UPDATE sent SET msgid=?, status=?, lastactiontime=?' - ' WHERE ackdata=?', + ' WHERE ackdata=? AND folder="sent" ', inventoryHash, 'broadcastsent', int(time.time()), ackdata ) @@ -691,7 +693,8 @@ def sendMsg(self): # Reset just in case sqlExecute( '''UPDATE sent SET status='msgqueued' ''' - ''' WHERE status IN ('doingpubkeypow', 'doingmsgpow')''') + ''' WHERE status IN ('doingpubkeypow', 'doingmsgpow') ''' + ''' AND folder='sent' ''') queryreturn = sqlQuery( '''SELECT toaddress, fromaddress, subject, message, ''' ''' ackdata, status, ttl, retrynumber, encodingtype FROM ''' @@ -727,11 +730,12 @@ def sendMsg(self): # we can calculate the needed pubkey using the private keys # in our keys.dat file. elif BMConfigParser().has_section(toaddress): - sqlExecute( + if not sqlExecute( '''UPDATE sent SET status='doingmsgpow' ''' - ''' WHERE toaddress=? AND status='msgqueued' ''', + ''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''', toaddress - ) + ): + continue status = 'doingmsgpow' elif status == 'msgqueued': # Let's see if we already have the pubkey in our pubkeys table @@ -742,11 +746,12 @@ def sendMsg(self): # If we have the needed pubkey in the pubkey table already, if queryreturn != []: # set the status of this msg to doingmsgpow - sqlExecute( + if not sqlExecute( '''UPDATE sent SET status='doingmsgpow' ''' - ''' WHERE toaddress=? AND status='msgqueued' ''', + ''' WHERE toaddress=? AND status='msgqueued' AND folder='sent' ''', toaddress - ) + ): + continue status = 'doingmsgpow' # mark the pubkey as 'usedpersonally' so that # we don't delete it later. If the pubkey version @@ -829,7 +834,8 @@ def sendMsg(self): ''' toaddress=? AND ''' ''' (status='msgqueued' or ''' ''' status='awaitingpubkey' or ''' - ''' status='doingpubkeypow')''', + ''' status='doingpubkeypow') AND ''' + ''' folder='sent' ''', toaddress) del state.neededPubkeys[tag] break @@ -846,7 +852,7 @@ def sendMsg(self): sqlExecute( '''UPDATE sent SET ''' ''' status='doingpubkeypow' WHERE ''' - ''' toaddress=? AND status='msgqueued' ''', + ''' toaddress=? AND status='msgqueued' AND folder='sent' ''', toaddress ) queues.UISignalQueue.put(( @@ -1039,7 +1045,7 @@ def sendMsg(self): # we are willing to do. sqlExecute( '''UPDATE sent SET status='toodifficult' ''' - ''' WHERE ackdata=? ''', + ''' WHERE ackdata=? AND folder='sent' ''', ackdata) queues.UISignalQueue.put(( 'updateSentItemStatusByAckdata', ( @@ -1187,7 +1193,7 @@ def sendMsg(self): ) except: sqlExecute( - '''UPDATE sent SET status='badkey' WHERE ackdata=?''', + '''UPDATE sent SET status='badkey' WHERE ackdata=? AND folder='sent' ''', ackdata ) queues.UISignalQueue.put(( @@ -1292,13 +1298,12 @@ def sendMsg(self): newStatus = 'msgsent' # wait 10% past expiration sleepTill = int(time.time() + TTL * 1.1) - sqlExecute( + au = sqlExecute( '''UPDATE sent SET msgid=?, status=?, retrynumber=?, ''' - ''' sleeptill=?, lastactiontime=? WHERE ackdata=?''', + ''' sleeptill=?, lastactiontime=? WHERE ackdata=? AND folder='sent' ''', inventoryHash, newStatus, retryNumber + 1, sleepTill, int(time.time()), ackdata ) - # If we are sending to ourselves or a chan, let's put # the message in our own inbox. if BMConfigParser().has_section(toaddress): @@ -1340,7 +1345,7 @@ def requestPubKey(self, toAddress): queryReturn = sqlQuery( '''SELECT retrynumber FROM sent WHERE toaddress=? ''' ''' AND (status='doingpubkeypow' OR status='awaitingpubkey') ''' - ''' LIMIT 1''', + ''' AND folder='sent' LIMIT 1''', toAddress ) if not queryReturn: @@ -1426,7 +1431,7 @@ def requestPubKey(self, toAddress): '''UPDATE sent SET lastactiontime=?, ''' ''' status='awaitingpubkey', retrynumber=?, sleeptill=? ''' ''' WHERE toaddress=? AND (status='doingpubkeypow' OR ''' - ''' status='awaitingpubkey') ''', + ''' status='awaitingpubkey') AND folder='sent' ''', int(time.time()), retryNumber + 1, sleeptill, toAddress) queues.UISignalQueue.put(( From a7c1018f473402695ce93e283430bd55ecd2de32 Mon Sep 17 00:00:00 2001 From: navjot Date: Mon, 12 Oct 2020 23:17:05 +0530 Subject: [PATCH 2/3] fixed CQ for src.class_singleWorker module --- src/class_singleWorker.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index c8640e49dd..b0cbfb693e 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -557,10 +557,10 @@ def sendBroadcast(self): continue if not sqlExecute( - '''UPDATE sent SET status='doingbroadcastpow' ''' - ''' WHERE ackdata=? AND status='broadcastqueued' ''' - ''' AND folder='sent' ''', - ackdata): + '''UPDATE sent SET status='doingbroadcastpow' ''' + ''' WHERE ackdata=? AND status='broadcastqueued' ''' + ''' AND folder='sent' ''', + ackdata): continue # At this time these pubkeys are 65 bytes long @@ -1298,7 +1298,7 @@ def sendMsg(self): newStatus = 'msgsent' # wait 10% past expiration sleepTill = int(time.time() + TTL * 1.1) - au = sqlExecute( + sqlExecute( '''UPDATE sent SET msgid=?, status=?, retrynumber=?, ''' ''' sleeptill=?, lastactiontime=? WHERE ackdata=? AND folder='sent' ''', inventoryHash, newStatus, retryNumber + 1, From 6c5bb62123f89809b538e247b078342ba5d55ad3 Mon Sep 17 00:00:00 2001 From: navjot Date: Wed, 14 Oct 2020 21:06:20 +0530 Subject: [PATCH 3/3] replaced double quotes with Single quotes in class_singleWorker module --- src/class_singleWorker.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py index b0cbfb693e..499cb82f14 100644 --- a/src/class_singleWorker.py +++ b/src/class_singleWorker.py @@ -109,7 +109,7 @@ def run(self): newack = '\x00\x00\x00\x02\x01\x01' + oldack state.ackdataForWhichImWatching[newack] = 0 sqlExecute( - 'UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = "sent" ', + '''UPDATE sent SET ackdata=? WHERE ackdata=? AND folder = 'sent' ''', newack, oldack ) del state.ackdataForWhichImWatching[oldack] @@ -682,8 +682,8 @@ def sendBroadcast(self): # Update the status of the message in the 'sent' table to have # a 'broadcastsent' status sqlExecute( - 'UPDATE sent SET msgid=?, status=?, lastactiontime=?' - ' WHERE ackdata=? AND folder="sent" ', + '''UPDATE sent SET msgid=?, status=?, lastactiontime=? ''' + ''' WHERE ackdata=? AND folder='sent' ''', inventoryHash, 'broadcastsent', int(time.time()), ackdata ) @@ -1304,6 +1304,7 @@ def sendMsg(self): inventoryHash, newStatus, retryNumber + 1, sleepTill, int(time.time()), ackdata ) + # If we are sending to ourselves or a chan, let's put # the message in our own inbox. if BMConfigParser().has_section(toaddress):