From d487b522cfc791013999cf6000f7ce2f90ee2933 Mon Sep 17 00:00:00 2001
From: ikarakatsanis
If you send a message to someone and he is offline for more than two days, Bitmessage will send the message again after an additional two days. This will be continued with exponential backoff forever. Messages will continue to be sent after 4, 8,16 days and so on until the receiver get them.
Here you can adjust Bitmessage to stop trying to send messages after X hours/days/months. This time period needs to be longer than 5 days.
", None)) + self.label_19.setText(_translate("settingsDialog", "If you send a message to someone and he is offline for more than two days, Bitmessage will send the message again after an additional two days. This will be continued with exponential backoff forever. Messages will continue to be sent after 4, 8,16 days and so on until the receiver get them.
Here you can adjust Bitmessage to stop trying to send messages after X hours/days/months.
", None)) self.label_20.setText(_translate("settingsDialog", "Time in hours/days/months:", None)) self.label_22.setText(_translate("settingsDialog", "/", None)) self.label_23.setText(_translate("settingsDialog", "/", None)) diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index 84829e87..08150970 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -10,16 +10,16 @@ from debug import logger '''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: - inventory (moves data to the on-disk sql database) - inventorySets (clears then reloads data out of sql database) +inventory (moves data to the on-disk sql database) +inventorySets (clears then reloads data out of sql database) It cleans these tables on the disk: - inventory (clears data more than 2 days and 12 hours old) - pubkeys (clears pubkeys older than 4 weeks old which we have not used personally) +inventory (clears data more than 2 days and 12 hours old) +pubkeys (clears pubkeys older than 4 weeks old which we have not used personally) It resends messages when there has been no response: - resends getpubkey messages in 4 days (then 8 days, then 16 days, etc...) - resends msg messages in 4 days (then 8 days, then 16 days, etc...) +resends getpubkey messages in 4 days (then 8 days, then 16 days, etc...) +resends msg messages in 4 days (then 8 days, then 16 days, etc...) ''' @@ -52,7 +52,7 @@ class singleCleaner(threading.Thread): del shared.inventory[hash] shared.UISignalQueue.put(('updateStatusBar', '')) shared.broadcastToSendDataQueues(( - 0, 'pong', 'no data')) # commands the sendData threads to send out a pong message if they haven't sent anything else in the last five minutes. The socket timeout-time is 10 minutes. + 0, 'pong', 'no data')) # commands the sendData threads to send out a pong message if they haven't sent anything else in the last five minutes. The socket timeout-time is 10 minutes. # If we are running as a daemon then we are going to fill up the UI # queue which will never be handled by a UI. We should clear it to # save memory. @@ -65,7 +65,7 @@ class singleCleaner(threading.Thread): # inventory (clears pubkeys after 28 days and everything else # after 2 days and 12 hours) sqlExecute( - '''DELETE FROM inventory WHERE (receivedtime AND objecttype<>'pubkey') OR (receivedtime AND objecttype='pubkey') ''', + '''DELETE FROM inventory WHERE (receivedtime AND objecttype<>'pubkey') OR (receivedtime AND objecttype='pubkey') ''', int(time.time()) - shared.lengthOfTimeToLeaveObjectsInInventory, int(time.time()) - shared.lengthOfTimeToHoldOnToAllPubkeys) @@ -75,7 +75,7 @@ class singleCleaner(threading.Thread): int(time.time()) - shared.lengthOfTimeToHoldOnToAllPubkeys) queryreturn = sqlQuery( - '''select toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, pubkeyretrynumber, msgretrynumber FROM sent WHERE ((status='awaitingpubkey' OR status='msgsent') AND folder='sent') ''') # If the message's folder='trash' then we'll ignore it. + '''select toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, pubkeyretrynumber, msgretrynumber FROM sent WHERE ((status='awaitingpubkey' OR status='msgsent') AND folder='sent') ''') # If the message's folder='trash' then we'll ignore it. for row in queryreturn: if len(row) < 5: with shared.printLock: @@ -86,35 +86,68 @@ class singleCleaner(threading.Thread): break toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, pubkeyretrynumber, msgretrynumber = row if status == 'awaitingpubkey': - if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))): - print 'It has been a long time and we haven\'t heard a response to our getpubkey request. Sending again.' - try: - del shared.neededPubkeys[ - toripe] # We need to take this entry out of the shared.neededPubkeys structure because the shared.workerQueue checks to see whether the entry is already present and will not do the POW and send the message because it assumes that it has already done it recently. - except: - pass - - shared.UISignalQueue.put(( - 'updateStatusBar', 'Doing work necessary to again attempt to request a public key...')) - t = () - sqlExecute( - '''UPDATE sent SET lastactiontime=?, pubkeyretrynumber=?, status='msgqueued' WHERE toripe=?''', - int(time.time()), - pubkeyretrynumber + 1, - toripe) - 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.' - sqlExecute( + if int(shared.config.get('bitmessagesettings', 'timeperiod'))> -1:#My implemenentation starts here.In this file I just added 4 lines.Two here and other two above.The default value of timeperiod is -1.This means that bitmessage resends messages every 5 days(they say 4 but actually is 5)for ever. If user changes the time period, timeperiod variable will have a specific value so the next if will be executed.JOHN + if (int(time.time()) - lastactiontime) > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))) and ((int(time.time()) - lastactiontime) < int(shared.config.get('bitmessagesettings', 'timeperiod'))):#This line does the magic.This if checks if the time that the public key was sent is longer than 5 days. Then it sends the it again. But with this extra AND it will not send it if this time is shorter than timeperiod.JOHN + print 'It has been a long time and we haven\'t heard a response to our getpubkey request. Sending again.' + try: + del shared.neededPubkeys[ + toripe] # We need to take this entry out of the shared.neededPubkeys structure because the shared.workerQueue checks to see whether the entry is already present and will not do the POW and send the message because it assumes that it has already done it recently. + except: + pass + + shared.UISignalQueue.put(( + 'updateStatusBar', 'Doing work necessary to again attempt to request a public key...')) + t = () + sqlExecute( + '''UPDATE sent SET lastactiontime=?, pubkeyretrynumber=?, status='msgqueued' WHERE toripe=?''', + int(time.time()), + pubkeyretrynumber + 1, + toripe) + shared.workerQueue.put(('sendmessage', '')) + else:#first it wasn't an else statement here, I put it for this setting. I just copy-paste the code again. If someone has any suggestion how we can do this without this if-else just say it.JOHN + if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))): + print 'It has been a long time and we haven\'t heard a response to our getpubkey request. Sending again.' + try: + del shared.neededPubkeys[ + toripe] # We need to take this entry out of the shared.neededPubkeys structure because the shared.workerQueue checks to see whether the entry is already present and will not do the POW and send the message because it assumes that it has already done it recently. + except: + pass + + shared.UISignalQueue.put(( + 'updateStatusBar', 'Doing work necessary to again attempt to request a public key...')) + t = () + sqlExecute( + '''UPDATE sent SET lastactiontime=?, pubkeyretrynumber=?, status='msgqueued' WHERE toripe=?''', + int(time.time()), + pubkeyretrynumber + 1, + toripe) + shared.workerQueue.put(('sendmessage', '')) + else: # status == msgsent + if int(shared.config.get('bitmessagesettings', 'timeperiod'))> -1:#same thing here but for the message.Actually this is the most important thing in the whole feature!.JOHN + if (int(time.time()) - lastactiontime) > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))) and ((int(time.time()) - lastactiontime) < int(shared.config.get('bitmessagesettings', 'timeperiod'))):#same thing here.My implementation in this file stops here.JOHN + print 'It has been a long time and we haven\'t heard an acknowledgement to our msg. Sending again.' + sqlExecute( '''UPDATE sent SET lastactiontime=?, msgretrynumber=?, status=? WHERE ackdata=?''', int(time.time()), msgretrynumber + 1, 'msgqueued', ackdata) - shared.workerQueue.put(('sendmessage', '')) - shared.UISignalQueue.put(( + shared.workerQueue.put(('sendmessage', '')) + shared.UISignalQueue.put(( 'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...')) + else: + if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))): + print 'It has been a long time and we haven\'t heard an acknowledgement to our msg. Sending again.' + sqlExecute( + '''UPDATE sent SET lastactiontime=?, msgretrynumber=?, status=? WHERE ackdata=?''', + int(time.time()), + msgretrynumber + 1, + 'msgqueued', + ackdata) + shared.workerQueue.put(('sendmessage', '')) + shared.UISignalQueue.put(( + 'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...')) + # Let's also clear and reload shared.inventorySets to keep it from # taking up an unnecessary amount of memory. @@ -144,4 +177,4 @@ class singleCleaner(threading.Thread): os._exit(0) shared.knownNodesLock.release() shared.needToWriteKnownNodesToDisk = False - time.sleep(300) + time.sleep(300) \ No newline at end of file diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index ba016eba..6fa44051 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -252,22 +252,24 @@ class sqlThread(threading.Thread): shared.config.set('bitmessagesettings', 'settingsversion', '7') with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) - + # Are you hoping to add a new option to the keys.dat file of existing # Bitmessage users? Add it right above this line! - #my new implementation starts here - if shared.config.getint('bitmessagesettings', 'settingsversion') == 6: + #my new implementation starts here, the most of these comment will be deleted, they are just for documentation + if shared.config.getint('bitmessagesettings', 'settingsversion') == 7:#this is the version that all we have,if you see your keys.dat file this is your version.JOHN + shared.config.set(#in order to not have to change your keys.dat file I update it with the new lines. I add to your keys.dat three new default fields.JOHN + 'bitmessagesettings', 'hours', '')# hours, days, months have no value.This means that bitmessage works as before. It re-sends mails every 4,8,16 days..forever.JOHN shared.config.set( - 'bitmessagesettings', 'hours', '0') + 'bitmessagesettings', 'days', '') shared.config.set( - 'bitmessagesettings', 'days', '5') + 'bitmessagesettings', 'months', '') shared.config.set( - 'bitmessagesettings', 'months', '0') - shared.config.set('bitmessagesettings', 'settingsversion', '7') + 'bitmessagesettings', 'timeperiod', '-1')#time period has default value -1. This is used for checking in class_singleCleaner. If you leave default the time period or after you change it(f.i 1/0/0), again you set it with its default value(-/-/-) this variable will be -1.JOHN + shared.config.set('bitmessagesettings', 'settingsversion', '8') #We update the version.If I leave it 7 every time that Bitmessage starts your setting will be lost.The default values(-/-/-) will be loaded all the time ;).That was juicy.JOHN with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) - #my new implementation stops here + #my new implementation in this file stops here try: testpayload = '\x00\x00' diff --git a/src/helper_bootstrap.py b/src/helper_bootstrap.py index 6b5b98dc..8e9d28e5 100644 --- a/src/helper_bootstrap.py +++ b/src/helper_bootstrap.py @@ -25,7 +25,7 @@ def knownNodes(): shared.knownNodes[stream][peer] = time except: shared.knownNodes = defaultKnownNodes.createDefaultKnownNodes(shared.appdata) - if shared.config.getint('bitmessagesettings', 'settingsversion') > 7: + if shared.config.getint('bitmessagesettings', 'settingsversion') > 8: print 'Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.' raise SystemExit diff --git a/src/helper_startup.py b/src/helper_startup.py index 35251f70..fdc20cff 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -91,12 +91,16 @@ def loadConfig(): # existing users. To do that, search the class_sqlThread.py file for the # text: "right above this line!" + #my implementation starts here. JOHN shared.config.set( - 'bitmessagesettings', 'hours', '0') + 'bitmessagesettings', 'hours', '')#here I am adding the new default settings. The first time that the program is going to run these values will be loaded(UI and keys.dat also :) ).JOHN shared.config.set( - 'bitmessagesettings', 'days', '5') + 'bitmessagesettings', 'days', '') shared.config.set( - 'bitmessagesettings', 'months', '0') + 'bitmessagesettings', 'months', '') + shared.config.set( + 'bitmessagesettings', 'timeperiod', '-1') + #my implementation in this file stops here.JOHN ensureNamecoinOptions() diff --git a/src/shared.py b/src/shared.py index 1b67fef9..4825caf4 100644 --- a/src/shared.py +++ b/src/shared.py @@ -1,9 +1,9 @@ softwareVersion = '0.4.0' verbose = 1 -maximumAgeOfAnObjectThatIAmWillingToAccept = 216000 # Equals two days and 12 hours. -lengthOfTimeToLeaveObjectsInInventory = 237600 # Equals two days and 18 hours. This should be longer than maximumAgeOfAnObjectThatIAmWillingToAccept so that we don't process messages twice. +maximumAgeOfAnObjectThatIAmWillingToAccept = 1800 # Equals two days and 12 hours. +lengthOfTimeToLeaveObjectsInInventory = 237600 # Equals two days and 18 hours. This should be longer than maximumAgeOfAnObjectThatIAmWillingToAccept so that we don't process messages twice. lengthOfTimeToHoldOnToAllPubkeys = 2419200 # Equals 4 weeks. You could make this longer if you want but making it shorter would not be advisable because there is a very small possibility that it could keep you from obtaining a needed pubkey for a period of time. -maximumAgeOfObjectsThatIAdvertiseToOthers = 216000 # Equals two days and 12 hours +maximumAgeOfObjectsThatIAdvertiseToOthers = 1800 # Equals two days and 12 hours maximumAgeOfNodesThatIAdvertiseToOthers = 10800 # Equals three hours useVeryEasyProofOfWorkForTesting = False # If you set this to True while on the normal network, you won't be able to send or sometimes receive messages.