From 2293253d385bf90444261ff368d2fe001e70e29f Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Thu, 26 Sep 2013 16:21:11 +0400 Subject: [PATCH 01/14] test to check git usage --- src/bitmessageqt/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index a02c4df5..9a4777c2 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -395,3 +395,4 @@ class Ui_settingsDialog(object): self.radioButtonNamecoinNmcontrol.setText(_translate("settingsDialog", "NMControl", None)) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabNamecoin), _translate("settingsDialog", "Namecoin integration", None)) +#just test \ No newline at end of file From 234081cc1725bf4bc1793bb541b720d23f64b4ac Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Fri, 27 Sep 2013 02:14:24 +0400 Subject: [PATCH 02/14] New tab "Adjusting time period for resending messages" was added --- src/bitmessageqt/settings.py | 52 +++++++++++++++++++++++++-- src/bitmessageqt/settings.ui | 70 +++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 9a4777c2..56407d7e 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -318,7 +318,49 @@ class Ui_settingsDialog(object): self.gridLayout_8.addLayout(self.horizontalLayout, 1, 0, 1, 3) self.tabWidgetSettings.addTab(self.tabNamecoin, _fromUtf8("")) self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1) - +#this line existed before +#my new implementation starts here + self.tabResendingMessagesAdjustment=QtGui.QWidget() + self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment")) + self.gridLayout_9 = QtGui.QGridLayout(self.tabResendingMessagesAdjustment) + self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9")) + self.label_19 = QtGui.QLabel(self.tabResendingMessagesAdjustment) + self.label_19.setWordWrap(True) + self.label_19.setObjectName(_fromUtf8("label_19")) + self.gridLayout_9.addWidget(self.label_19, 0, 0, 1, 0) + spacerItem13 = QtGui.QSpacerItem(102, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) + self.gridLayout_9.addItem(spacerItem13, 1, 0, 1, 1) + self.horizontalLayout = QtGui.QHBoxLayout() + self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) + self.label_20 = QtGui.QLabel(self.tabResendingMessagesAdjustment) + self.label_20.setLayoutDirection(QtCore.Qt.LeftToRight) + self.label_20.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_20.setObjectName(_fromUtf8("label_20")) + self.gridLayout_9.addWidget(self.label_20, 2, 0, 1, 1) + self.lineEditHours = QtGui.QLineEdit(self.tabResendingMessagesAdjustment) + self.lineEditHours.setMaximumSize(QtCore.QSize(33, 16777)) + self.lineEditHours.setObjectName(_fromUtf8("lineEditHours")) + self.gridLayout_9.addWidget(self.lineEditHours, 2, 1, 1, 1) + self.label_22 = QtGui.QLabel(self.tabResendingMessagesAdjustment) + self.label_22.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_22.setObjectName(_fromUtf8("label_22")) + self.gridLayout_9.addWidget(self.label_22, 2, 2, 1, 1) + self.lineEditDays = QtGui.QLineEdit(self.tabResendingMessagesAdjustment) + self.lineEditDays.setMaximumSize(QtCore.QSize(33, 16777)) + self.lineEditDays.setObjectName(_fromUtf8("lineEditDays")) + self.gridLayout_9.addWidget(self.lineEditDays, 2, 3, 1, 1) + self.label_23 = QtGui.QLabel(self.tabResendingMessagesAdjustment) + self.label_23.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) + self.label_23.setObjectName(_fromUtf8("label_23")) + self.gridLayout_9.addWidget(self.label_23, 2, 4, 1, 1) + self.lineEditMonths = QtGui.QLineEdit(self.tabResendingMessagesAdjustment) + self.lineEditMonths.setMaximumSize(QtCore.QSize(33, 16777)) + self.lineEditMonths.setObjectName(_fromUtf8("lineEditMonths")) + self.gridLayout_9.addWidget(self.lineEditMonths, 2, 5, 1, 1) + spacerItem15 = QtGui.QSpacerItem(20, 147, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) + self.gridLayout_9.addItem(spacerItem15, 3, 1, 1, 1) + self.tabWidgetSettings.addTab(self.tabResendingMessagesAdjustment, _fromUtf8("")) + #my new implementation stops here, it wasn't line here self.retranslateUi(settingsDialog) self.tabWidgetSettings.setCurrentIndex(0) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), settingsDialog.accept) @@ -382,6 +424,13 @@ class Ui_settingsDialog(object): self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), _translate("settingsDialog", "Demanded difficulty", None)) self.label_15.setText(_translate("settingsDialog", "Here you may set the maximum amount of work you are willing to do to send a message to another person. Setting these values to 0 means that any value is acceptable.", None)) self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None)) + #my new implementation starts here,it wasn't line here + self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendingMessagesAdjustment), _translate("settingsDialog", "Adjusting time period for resending messages", 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. This time period needs to be longer than 5 days.

", 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)) + #my new implementation stops here, it wasn't line here self.label_14.setText(_translate("settingsDialog", "Maximum acceptable small message difficulty:", None)) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab_2), _translate("settingsDialog", "Max acceptable difficulty", None)) self.label_16.setText(_translate("settingsDialog", "

Bitmessage can utilize a different Bitcoin-based program called Namecoin to make addresses human-friendly. For example, instead of having to tell your friend your long Bitmessage address, you can simply tell him to send a message to test.

(Getting your own Bitmessage address into Namecoin is still rather difficult).

Bitmessage can use either namecoind directly or a running nmcontrol instance.

", None)) @@ -395,4 +444,3 @@ class Ui_settingsDialog(object): self.radioButtonNamecoinNmcontrol.setText(_translate("settingsDialog", "NMControl", None)) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabNamecoin), _translate("settingsDialog", "Namecoin integration", None)) -#just test \ No newline at end of file diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 23755b91..9973a1b4 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -756,6 +756,74 @@ + + + + Adjusting time period for resending messages + + + + + + 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. Μessages will continue to be sent after 4, 8,16 days etc. 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./p></body></html> + + + true + + + + + + + Qt::LeftToRight + + + Time in hours/days/months: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 33 + 16777215 + + + + + + + + / + + + + + + + + + / + + + + + + + + 33 + 16777215 + + + + + + + tabWidgetSettings checkBoxStartOnLogon @@ -792,7 +860,7 @@ buttonBox - rejected() + rejected) settingsDialog reject() From ae01c186f42b9942b2df5047581958a47c82f1ed Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Fri, 27 Sep 2013 02:24:48 +0400 Subject: [PATCH 03/14] minor change UI --- src/bitmessageqt/settings.ui | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 9973a1b4..94610c03 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -756,7 +756,6 @@ - Adjusting time period for resending messages @@ -860,7 +859,7 @@ buttonBox - rejected) + rejected() settingsDialog reject() From e1fc820226ce6a3c2a2581d7f25fecaa33ab8a30 Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Sat, 28 Sep 2013 04:47:16 +0400 Subject: [PATCH 04/14] changes in keys.dat, edit hours/days/months is working now, variable time_period inserted --- src/bitmessageqt/__init__.py | 28 +++++++++++++++++++++++++++- src/class_sqlThread.py | 13 +++++++++++++ src/helper_startup.py | 9 ++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 8cbea0f9..3f59ba4e 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2036,6 +2036,23 @@ class MyForm(QtGui.QMainWindow): if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0: shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float( self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes))) + #my implementation starts here,it was a line here + time_period = (int(str(self.settingsDialogInstance.ui.lineEditHours.text())) * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60 + + int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12) + if time_period < shared.maximumAgeOfAnObjectThatIAmWillingToAccept * 2: + QMessageBox.about(self, _translate("MainWindow", "Error"), _translate( + "MainWindow", "You must insert a time period longer than 5 days.")) + shared.config.set('bitmessagesettings', 'hours', '0') + shared.config.set('bitmessagesettings', 'days', '5') + shared.config.set('bitmessagesettings', 'months', '0') + else: + shared.config.set('bitmessagesettings', 'hours', str( + self.settingsDialogInstance.ui.lineEditHours.text())) + shared.config.set('bitmessagesettings', 'days', str( + self.settingsDialogInstance.ui.lineEditDays.text())) + shared.config.set('bitmessagesettings', 'months', str( + self.settingsDialogInstance.ui.lineEditMonths.text())) + #my implementation stops here, there is a line # if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': # shared.config.set('bitmessagesettings', 'maxcores', '99999') @@ -2964,7 +2981,7 @@ class settingsDialog(QtGui.QDialog): self.ui.lineEditNamecoinPassword.setEnabled(False) self.ui.labelNamecoinPassword.setEnabled(False) else: - assert False + assert False QtCore.QObject.connect(self.ui.radioButtonNamecoinNamecoind, QtCore.SIGNAL( "toggled(bool)"), self.namecoinTypeChanged) @@ -2973,6 +2990,15 @@ class settingsDialog(QtGui.QDialog): QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL( "clicked()"), self.click_pushButtonNamecoinTest) + #Adjust tab + self.ui.lineEditHours.setText(str( + shared.config.get('bitmessagesettings', 'hours'))) + self.ui.lineEditDays.setText(str( + shared.config.get('bitmessagesettings', 'days'))) + self.ui.lineEditMonths.setText(str( + shared.config.get('bitmessagesettings', 'months'))) + + #'System' tab removed for now. """try: maxCores = shared.config.getint('bitmessagesettings', 'maxcores') diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 829b243d..ba016eba 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -256,6 +256,19 @@ class sqlThread(threading.Thread): # 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: + shared.config.set( + 'bitmessagesettings', 'hours', '0') + shared.config.set( + 'bitmessagesettings', 'days', '5') + shared.config.set( + 'bitmessagesettings', 'months', '0') + shared.config.set('bitmessagesettings', 'settingsversion', '7') + with open(shared.appdata + 'keys.dat', 'wb') as configfile: + shared.config.write(configfile) + #my new implementation stops here + try: testpayload = '\x00\x00' t = ('1234', testpayload, '12345678', 'no') diff --git a/src/helper_startup.py b/src/helper_startup.py index 5a5d7b81..35251f70 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -84,12 +84,19 @@ def loadConfig(): 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0') shared.config.set('bitmessagesettings', 'dontconnect', 'true') shared.config.set('bitmessagesettings', 'userlocale', 'system') - + # Are you hoping to add a new option to the keys.dat file? You're in # the right place for adding it to users who install the software for # the first time. But you must also add it to the keys.dat file of # existing users. To do that, search the class_sqlThread.py file for the # text: "right above this line!" + + shared.config.set( + 'bitmessagesettings', 'hours', '0') + shared.config.set( + 'bitmessagesettings', 'days', '5') + shared.config.set( + 'bitmessagesettings', 'months', '0') ensureNamecoinOptions() From d487b522cfc791013999cf6000f7ce2f90ee2933 Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Wed, 2 Oct 2013 04:14:53 +0400 Subject: [PATCH 05/14] feature_v1 --- src/bitmessageqt/__init__.py | 45 +++++++++------- src/bitmessageqt/settings.py | 12 ++--- src/class_singleCleaner.py | 99 ++++++++++++++++++++++++------------ src/class_sqlThread.py | 18 ++++--- src/helper_bootstrap.py | 2 +- src/helper_startup.py | 10 ++-- src/shared.py | 6 +-- 7 files changed, 121 insertions(+), 71 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 3f59ba4e..b9f168ae 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2036,23 +2036,34 @@ class MyForm(QtGui.QMainWindow): if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0: shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float( self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes))) - #my implementation starts here,it was a line here - time_period = (int(str(self.settingsDialogInstance.ui.lineEditHours.text())) * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60 + - int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12) - if time_period < shared.maximumAgeOfAnObjectThatIAmWillingToAccept * 2: - QMessageBox.about(self, _translate("MainWindow", "Error"), _translate( - "MainWindow", "You must insert a time period longer than 5 days.")) - shared.config.set('bitmessagesettings', 'hours', '0') - shared.config.set('bitmessagesettings', 'days', '5') - shared.config.set('bitmessagesettings', 'months', '0') - else: - shared.config.set('bitmessagesettings', 'hours', str( + #my implementation starts here,it was a line here.JOHN + if ((self.settingsDialogInstance.ui.lineEditHours.text()=='') and (self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')): + if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.JOHN + ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or + ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))) : + QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) + + shared.config.set('bitmessagesettings', 'hours', '')#give default values to fields..this default situation is special and thats why its needs special treatment ;).JOHN + shared.config.set('bitmessagesettings', 'days', '')#these commands update each field in the keys.dat file.JOHN + shared.config.set('bitmessagesettings', 'months', '') + shared.config.set('bitmessagesettings', 'timeperiod', '-1') + else:#So,if all time period fields(hours,months,days) have valid values(valid values---> 0/0/0, 0/3/2, -/-/-, no valid--> -/0/5, 5/-/-), you can calculate the time period + shared.config.set('bitmessagesettings', 'timeperiod', str(int(str(self.settingsDialogInstance.ui.lineEditHours.text())) * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60 + + int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)) + + if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or#inform user tha he needs to restart bitmessage in order his changes to take effect.JOHN + ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or + ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))) : + QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) + shared.config.set('bitmessagesettings', 'hours', str(#this three commands update the fields of this new setting in keys.dat file.JOHN self.settingsDialogInstance.ui.lineEditHours.text())) - shared.config.set('bitmessagesettings', 'days', str( + shared.config.set('bitmessagesettings', 'days', str( self.settingsDialogInstance.ui.lineEditDays.text())) - shared.config.set('bitmessagesettings', 'months', str( + shared.config.set('bitmessagesettings', 'months', str( self.settingsDialogInstance.ui.lineEditMonths.text())) - #my implementation stops here, there is a line + #my implementation stops here, there is a line.JOHN # if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': # shared.config.set('bitmessagesettings', 'maxcores', '99999') @@ -2990,13 +3001,13 @@ class settingsDialog(QtGui.QDialog): QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL( "clicked()"), self.click_pushButtonNamecoinTest) - #Adjust tab - self.ui.lineEditHours.setText(str( + #Adjusting time period for resending messages tab.JOHN + self.ui.lineEditHours.setText(str(#Giving values to edit boxes in the UI.JOHN shared.config.get('bitmessagesettings', 'hours'))) self.ui.lineEditDays.setText(str( shared.config.get('bitmessagesettings', 'days'))) self.ui.lineEditMonths.setText(str( - shared.config.get('bitmessagesettings', 'months'))) + shared.config.get('bitmessagesettings', 'months')))#JOHN. #'System' tab removed for now. diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 56407d7e..d15d1319 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -320,8 +320,8 @@ class Ui_settingsDialog(object): self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1) #this line existed before #my new implementation starts here - self.tabResendingMessagesAdjustment=QtGui.QWidget() - self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment")) + self.tabResendingMessagesAdjustment=QtGui.QWidget()#all these lines are for the UI implementation, I dont think that you need special explanation about them.JOHN + self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment"))#Please note that approximately 58 line codes added to setting.ui also responsible for the UI.JOHN self.gridLayout_9 = QtGui.QGridLayout(self.tabResendingMessagesAdjustment) self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9")) self.label_19 = QtGui.QLabel(self.tabResendingMessagesAdjustment) @@ -335,11 +335,11 @@ class Ui_settingsDialog(object): self.label_20 = QtGui.QLabel(self.tabResendingMessagesAdjustment) self.label_20.setLayoutDirection(QtCore.Qt.LeftToRight) self.label_20.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.label_20.setObjectName(_fromUtf8("label_20")) + self.label_20.setObjectName(_fromUtf8("label_20"))#This are Qt code..I just add a label to my tab.JOHN self.gridLayout_9.addWidget(self.label_20, 2, 0, 1, 1) self.lineEditHours = QtGui.QLineEdit(self.tabResendingMessagesAdjustment) self.lineEditHours.setMaximumSize(QtCore.QSize(33, 16777)) - self.lineEditHours.setObjectName(_fromUtf8("lineEditHours")) + self.lineEditHours.setObjectName(_fromUtf8("lineEditHours"))##This are Qt code..I just add a edit box to my tab.JOHN self.gridLayout_9.addWidget(self.lineEditHours, 2, 1, 1, 1) self.label_22 = QtGui.QLabel(self.tabResendingMessagesAdjustment) self.label_22.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) @@ -424,9 +424,9 @@ class Ui_settingsDialog(object): self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), _translate("settingsDialog", "Demanded difficulty", None)) self.label_15.setText(_translate("settingsDialog", "Here you may set the maximum amount of work you are willing to do to send a message to another person. Setting these values to 0 means that any value is acceptable.", None)) self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None)) - #my new implementation starts here,it wasn't line here + #my new implementation starts here,it wasn't line here.Too simple to explain :D..JOHN self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendingMessagesAdjustment), _translate("settingsDialog", "Adjusting time period for resending messages", 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. 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'pubkey') OR (receivedtime'pubkey') OR (receivedtime (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. From 511185055d9a33df9fdcb451a2ebbc228d36d47b Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Wed, 2 Oct 2013 04:16:42 +0400 Subject: [PATCH 06/14] feature_v2 --- src/shared.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared.py b/src/shared.py index 4825caf4..68a6e719 100644 --- a/src/shared.py +++ b/src/shared.py @@ -1,9 +1,9 @@ softwareVersion = '0.4.0' verbose = 1 -maximumAgeOfAnObjectThatIAmWillingToAccept = 1800 # Equals two days and 12 hours. +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. 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 = 1800 # Equals two days and 12 hours +maximumAgeOfObjectsThatIAdvertiseToOthers = 216000 # 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. From c16d9787d289b1f6ae05358e55ad46cd4b8d2a30 Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Thu, 3 Oct 2013 18:29:50 +0400 Subject: [PATCH 07/14] feature1_v3_AQWA --- src/bitmessageqt/__init__.py | 20 +++---- src/bitmessageqt/settings.py | 10 ++-- src/class_singleCleaner.py | 103 +++++++++++++++-------------------- src/class_sqlThread.py | 10 ++-- src/helper_startup.py | 6 +- 5 files changed, 67 insertions(+), 82 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index b9f168ae..af8946c0 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2036,34 +2036,34 @@ class MyForm(QtGui.QMainWindow): if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0: shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float( self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes))) - #my implementation starts here,it was a line here.JOHN + #my implementation starts here,it was a line here.AQWA if ((self.settingsDialogInstance.ui.lineEditHours.text()=='') and (self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')): - if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.JOHN + if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.AQWA ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))) : QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) - shared.config.set('bitmessagesettings', 'hours', '')#give default values to fields..this default situation is special and thats why its needs special treatment ;).JOHN - shared.config.set('bitmessagesettings', 'days', '')#these commands update each field in the keys.dat file.JOHN + shared.config.set('bitmessagesettings', 'hours', '')#give default values to fields..this default situation is special and thats why its needs special treatment ;).AQWA + shared.config.set('bitmessagesettings', 'days', '')#these commands update each field in the keys.dat file.AQWA shared.config.set('bitmessagesettings', 'months', '') shared.config.set('bitmessagesettings', 'timeperiod', '-1') else:#So,if all time period fields(hours,months,days) have valid values(valid values---> 0/0/0, 0/3/2, -/-/-, no valid--> -/0/5, 5/-/-), you can calculate the time period shared.config.set('bitmessagesettings', 'timeperiod', str(int(str(self.settingsDialogInstance.ui.lineEditHours.text())) * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)) - if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or#inform user tha he needs to restart bitmessage in order his changes to take effect.JOHN + if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or#inform user tha he needs to restart bitmessage in order his changes to take effect.AQWA ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))) : QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) - shared.config.set('bitmessagesettings', 'hours', str(#this three commands update the fields of this new setting in keys.dat file.JOHN + shared.config.set('bitmessagesettings', 'hours', str(#this three commands update the fields of this new setting in keys.dat file.AQWA self.settingsDialogInstance.ui.lineEditHours.text())) shared.config.set('bitmessagesettings', 'days', str( self.settingsDialogInstance.ui.lineEditDays.text())) shared.config.set('bitmessagesettings', 'months', str( self.settingsDialogInstance.ui.lineEditMonths.text())) - #my implementation stops here, there is a line.JOHN + #my implementation stops here, there is a line.AQWA # if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': # shared.config.set('bitmessagesettings', 'maxcores', '99999') @@ -3001,13 +3001,13 @@ class settingsDialog(QtGui.QDialog): QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL( "clicked()"), self.click_pushButtonNamecoinTest) - #Adjusting time period for resending messages tab.JOHN - self.ui.lineEditHours.setText(str(#Giving values to edit boxes in the UI.JOHN + #Adjusting time period for resending messages tab.AQWA + self.ui.lineEditHours.setText(str(#Giving values to edit boxes in the UI.AQWA shared.config.get('bitmessagesettings', 'hours'))) self.ui.lineEditDays.setText(str( shared.config.get('bitmessagesettings', 'days'))) self.ui.lineEditMonths.setText(str( - shared.config.get('bitmessagesettings', 'months')))#JOHN. + shared.config.get('bitmessagesettings', 'months')))#AQWA. #'System' tab removed for now. diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index d15d1319..f9c3518a 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -320,8 +320,8 @@ class Ui_settingsDialog(object): self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1) #this line existed before #my new implementation starts here - self.tabResendingMessagesAdjustment=QtGui.QWidget()#all these lines are for the UI implementation, I dont think that you need special explanation about them.JOHN - self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment"))#Please note that approximately 58 line codes added to setting.ui also responsible for the UI.JOHN + self.tabResendingMessagesAdjustment=QtGui.QWidget()#all these lines are for the UI implementation, I dont think that you need special explanation about them.AQWA + self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment"))#Please note that approximately 58 line codes added to setting.ui also responsible for the UI.AQWA self.gridLayout_9 = QtGui.QGridLayout(self.tabResendingMessagesAdjustment) self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9")) self.label_19 = QtGui.QLabel(self.tabResendingMessagesAdjustment) @@ -335,11 +335,11 @@ class Ui_settingsDialog(object): self.label_20 = QtGui.QLabel(self.tabResendingMessagesAdjustment) self.label_20.setLayoutDirection(QtCore.Qt.LeftToRight) self.label_20.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.label_20.setObjectName(_fromUtf8("label_20"))#This are Qt code..I just add a label to my tab.JOHN + self.label_20.setObjectName(_fromUtf8("label_20"))#This are Qt code..I just add a label to my tab.AQWA self.gridLayout_9.addWidget(self.label_20, 2, 0, 1, 1) self.lineEditHours = QtGui.QLineEdit(self.tabResendingMessagesAdjustment) self.lineEditHours.setMaximumSize(QtCore.QSize(33, 16777)) - self.lineEditHours.setObjectName(_fromUtf8("lineEditHours"))##This are Qt code..I just add a edit box to my tab.JOHN + self.lineEditHours.setObjectName(_fromUtf8("lineEditHours"))##This are Qt code..I just add a edit box to my tab.AQWA self.gridLayout_9.addWidget(self.lineEditHours, 2, 1, 1, 1) self.label_22 = QtGui.QLabel(self.tabResendingMessagesAdjustment) self.label_22.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) @@ -424,7 +424,7 @@ class Ui_settingsDialog(object): self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), _translate("settingsDialog", "Demanded difficulty", None)) self.label_15.setText(_translate("settingsDialog", "Here you may set the maximum amount of work you are willing to do to send a message to another person. Setting these values to 0 means that any value is acceptable.", None)) self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None)) - #my new implementation starts here,it wasn't line here.Too simple to explain :D..JOHN + #my new implementation starts here,it wasn't line here.Too simple to explain :D..AQWA self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendingMessagesAdjustment), _translate("settingsDialog", "Adjusting time period for resending messages", 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)) diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index 08150970..dfeaf4a1 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -86,67 +86,19 @@ class singleCleaner(threading.Thread): break toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, pubkeyretrynumber, msgretrynumber = row if status == 'awaitingpubkey': - 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(shared.config.get('bitmessagesettings', 'timeperiod'))> -1:#My implemenentation starts here.This if statement would become very big with my new code,so I created two function(see at the end of this file) to reduce code.I did.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.AQWA + 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.AQWA + resendPubkey(pubkeyretrynumber,toripe) + 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.AQWA 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', '')) + resendPubkey(pubkeyretrynumber,toripe) 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(( - 'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...')) + 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!.AQWA + if (int(time.time()) - lastactiontime) > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))) and ((int(time.time()) - lastactiontime) < int(shared.config.get('bitmessagesettings', 'timeperiod'))):#same thing here.My implementation in this file stops here.AQWA + resendMsg(msgretrynumber,ackdata) 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...')) + if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))): + resendMsg(msgretrynumber,ackdata) # Let's also clear and reload shared.inventorySets to keep it from @@ -177,4 +129,37 @@ class singleCleaner(threading.Thread): os._exit(0) shared.knownNodesLock.release() shared.needToWriteKnownNodesToDisk = False - time.sleep(300) \ No newline at end of file + time.sleep(300) + +def resendPubkey(pubkeyretrynumber,toripe):#I just structured the code with these two functions. The code inside existed.It is not mine.AQWA + 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', '')) + +def resendMsg(msgretrynumber,ackdata): + 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...')) + + + \ No newline at end of file diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 6fa44051..6e5e9163 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -257,16 +257,16 @@ class sqlThread(threading.Thread): # Bitmessage users? Add it right above this line! #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 + 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.AQWA + 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.AQWA + '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.AQWA shared.config.set( 'bitmessagesettings', 'days', '') shared.config.set( 'bitmessagesettings', 'months', '') shared.config.set( - '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 + '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.AQWA + 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.AQWA with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) #my new implementation in this file stops here diff --git a/src/helper_startup.py b/src/helper_startup.py index fdc20cff..2469f82e 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -91,16 +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 + #my implementation starts here. AQWA shared.config.set( - '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 + '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 :) ).AQWA shared.config.set( 'bitmessagesettings', 'days', '') shared.config.set( 'bitmessagesettings', 'months', '') shared.config.set( 'bitmessagesettings', 'timeperiod', '-1') - #my implementation in this file stops here.JOHN + #my implementation in this file stops here.AQWA ensureNamecoinOptions() From 44bd876a40d668e386087dca798cbf77b25b5f47 Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Sun, 6 Oct 2013 12:32:14 +0400 Subject: [PATCH 08/14] feature1_v4 --- src/bitmessageqt/__init__.py | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 27338fd1..3280f2d8 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2027,34 +2027,34 @@ class MyForm(QtGui.QMainWindow): if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0: shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float( self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes))) - #my implementation starts here,it was a line here.AQWA + #my implementation starts here,it was a line here.AQWA if ((self.settingsDialogInstance.ui.lineEditHours.text()=='') and (self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')): if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.AQWA - ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or - ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))) : - QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( - "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) - + ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or + ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))): + QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) shared.config.set('bitmessagesettings', 'hours', '')#give default values to fields..this default situation is special and thats why its needs special treatment ;).AQWA shared.config.set('bitmessagesettings', 'days', '')#these commands update each field in the keys.dat file.AQWA shared.config.set('bitmessagesettings', 'months', '') shared.config.set('bitmessagesettings', 'timeperiod', '-1') else:#So,if all time period fields(hours,months,days) have valid values(valid values---> 0/0/0, 0/3/2, -/-/-, no valid--> -/0/5, 5/-/-), you can calculate the time period + if (int(str(self.settingsDialogInstance.ui.lineEditHours.text())) >=0 and int(str(self.settingsDialogInstance.ui.lineEditDays.text())) >=0 and + int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) >=0): + if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.AQWA + ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or + ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))): + QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) + shared.config.set('bitmessagesettings', 'hours', str(#this three commands update the fields of this new setting in keys.dat file.AQWA + self.settingsDialogInstance.ui.lineEditHours.text())) + shared.config.set('bitmessagesettings', 'days', str( + self.settingsDialogInstance.ui.lineEditDays.text())) + shared.config.set('bitmessagesettings', 'months', str( + self.settingsDialogInstance.ui.lineEditMonths.text())) shared.config.set('bitmessagesettings', 'timeperiod', str(int(str(self.settingsDialogInstance.ui.lineEditHours.text())) * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)) - - if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or#inform user tha he needs to restart bitmessage in order his changes to take effect.AQWA - ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or - ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))) : - QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( - "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) - shared.config.set('bitmessagesettings', 'hours', str(#this three commands update the fields of this new setting in keys.dat file.AQWA - self.settingsDialogInstance.ui.lineEditHours.text())) - shared.config.set('bitmessagesettings', 'days', str( - self.settingsDialogInstance.ui.lineEditDays.text())) - shared.config.set('bitmessagesettings', 'months', str( - self.settingsDialogInstance.ui.lineEditMonths.text())) - #my implementation stops here, there is a line.AQWA + #my implementation stops here, it was a line.AQWA # if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': # shared.config.set('bitmessagesettings', 'maxcores', '99999') From 6787e4b932ff95fdc932445c6ea4f4a9dd72e531 Mon Sep 17 00:00:00 2001 From: John Kozan Date: Sun, 6 Oct 2013 22:04:09 -0600 Subject: [PATCH 09/14] == should be = --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 90e02cc1..ef2a2ddd 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -643,7 +643,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): raise APIError(0, 'I need parameters!') if len(params) == 1: address, = params - label == '' + label = '' if len(params) == 2: address, label = params label = self._decode(label, "base64") From 9066dad5e3e4e97549a0f727a437b3b8fe941acf Mon Sep 17 00:00:00 2001 From: ikarakatsanis Date: Thu, 10 Oct 2013 09:10:46 +0400 Subject: [PATCH 10/14] AQWA feature: UI setting for Bitmessage to stop trying to send messages after X hours/days/months --- src/bitmessageqt/__init__.py | 65 +++++++++++++++++++++--------------- src/bitmessageqt/settings.py | 21 ++++++------ src/bitmessageqt/settings.ui | 4 +-- src/class_singleCleaner.py | 23 +++++++------ src/class_sqlThread.py | 21 ++++++------ src/helper_startup.py | 18 +++++----- 6 files changed, 82 insertions(+), 70 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 3280f2d8..f8563a9c 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2027,34 +2027,47 @@ class MyForm(QtGui.QMainWindow): if float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0: shared.config.set('bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', str(int(float( self.settingsDialogInstance.ui.lineEditMaxAcceptableSmallMessageDifficulty.text()) * shared.networkDefaultPayloadLengthExtraBytes))) - #my implementation starts here,it was a line here.AQWA - if ((self.settingsDialogInstance.ui.lineEditHours.text()=='') and (self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')): - if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.AQWA + #start:UI setting to stop trying to send messages after X hours/days/months + if ((self.settingsDialogInstance.ui.lineEditHours.text()=='') and (self.settingsDialogInstance.ui.lineEditDays.text()=='') and (self.settingsDialogInstance.ui.lineEditMonths.text()=='')):#We need to handle this special case. Bitmessage has its default behavior. The input is blank/blank/blank + if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #the user updated the input, restart is needed ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or - ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))): - QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( - "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) - shared.config.set('bitmessagesettings', 'hours', '')#give default values to fields..this default situation is special and thats why its needs special treatment ;).AQWA - shared.config.set('bitmessagesettings', 'days', '')#these commands update each field in the keys.dat file.AQWA - shared.config.set('bitmessagesettings', 'months', '') - shared.config.set('bitmessagesettings', 'timeperiod', '-1') - else:#So,if all time period fields(hours,months,days) have valid values(valid values---> 0/0/0, 0/3/2, -/-/-, no valid--> -/0/5, 5/-/-), you can calculate the time period - if (int(str(self.settingsDialogInstance.ui.lineEditHours.text())) >=0 and int(str(self.settingsDialogInstance.ui.lineEditDays.text())) >=0 and - int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) >=0): - if (((shared.config.get('bitmessagesettings', 'hours')) != str(self.settingsDialogInstance.ui.lineEditHours.text())) or #if we update the time period from one time period(f.e 1/0/0) to default -/-/,inform the user that restart is needed in order his changes to take effect.AQWA - ((shared.config.get('bitmessagesettings', 'days')) != str(self.settingsDialogInstance.ui.lineEditDays.text())) or ((shared.config.get('bitmessagesettings', 'months')) != str(self.settingsDialogInstance.ui.lineEditMonths.text()))): QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( - "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) - shared.config.set('bitmessagesettings', 'hours', str(#this three commands update the fields of this new setting in keys.dat file.AQWA - self.settingsDialogInstance.ui.lineEditHours.text())) - shared.config.set('bitmessagesettings', 'days', str( - self.settingsDialogInstance.ui.lineEditDays.text())) - shared.config.set('bitmessagesettings', 'months', str( - self.settingsDialogInstance.ui.lineEditMonths.text())) + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) + shared.config.set('bitmessagesettings', 'hours', '') + shared.config.set('bitmessagesettings', 'days', '') + shared.config.set('bitmessagesettings', 'months', '') + shared.config.set('bitmessagesettings', 'timeperiod', '-1')#when bitmessage has its default resending behavior, we set timeperiod to -1. + else:#So,if all time period's variables (hours,days,months) have valid values, we calculate the time period + if (int(self.settingsDialogInstance.ui.lineEditHours.text()) >=0 and int(self.settingsDialogInstance.ui.lineEditDays.text()) >=0 and + int(self.settingsDialogInstance.ui.lineEditMonths.text()) >=0): shared.config.set('bitmessagesettings', 'timeperiod', str(int(str(self.settingsDialogInstance.ui.lineEditHours.text())) * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditDays.text())) * 24 * 60 * 60 + int(str(self.settingsDialogInstance.ui.lineEditMonths.text())) * (60 * 60 * 24 *365)/12)) - #my implementation stops here, it was a line.AQWA + if int(shared.config.get('bitmessagesettings', 'timeperiod')) < 432000:#if the time period is less than 5 hours, we give zero values to all fields. No message will be sent again. + if ((shared.config.get('bitmessagesettings', 'hours')) != str(int(self.settingsDialogInstance.ui.lineEditHours.text())) or #if the user has given an input bigger than 5 days and he tries now to give an input less than 5 days, restart is needed + shared.config.get('bitmessagesettings', 'days') != str(int(self.settingsDialogInstance.ui.lineEditDays.text())) or + shared.config.get('bitmessagesettings', 'months') != str(int(self.settingsDialogInstance.ui.lineEditMonths.text()))): + if((shared.config.get('bitmessagesettings', 'hours')) != '0' or (shared.config.get('bitmessagesettings', 'days')) != '0' or#if the user has already given an input less than 5 days and he tries now to give again an input less than 5 days, there is no need for restart. Input values will remain zero + (shared.config.get('bitmessagesettings', 'months')) != '0'): + QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate( + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) + shared.config.set('bitmessagesettings', 'hours', '0') + shared.config.set('bitmessagesettings', 'days', '0') + shared.config.set('bitmessagesettings', 'months', '0') + shared.config.set('bitmessagesettings', 'timeperiod', '0') + else: + if ((shared.config.get('bitmessagesettings', 'hours')) != str(int(self.settingsDialogInstance.ui.lineEditHours.text())) or + shared.config.get('bitmessagesettings', 'days') != str(int(self.settingsDialogInstance.ui.lineEditDays.text())) or + shared.config.get('bitmessagesettings', 'months') != str(int(self.settingsDialogInstance.ui.lineEditMonths.text()))): + QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(#the user updated the input, restart is needed + "MainWindow", "You must restart Bitmessage for the time period change to take effect.")) + shared.config.set('bitmessagesettings', 'hours', str(int( + self.settingsDialogInstance.ui.lineEditHours.text()))) + shared.config.set('bitmessagesettings', 'days', str(int( + self.settingsDialogInstance.ui.lineEditDays.text()))) + shared.config.set('bitmessagesettings', 'months', str(int( + self.settingsDialogInstance.ui.lineEditMonths.text()))) + #end # if str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()) == 'All': # shared.config.set('bitmessagesettings', 'maxcores', '99999') @@ -2992,13 +3005,13 @@ class settingsDialog(QtGui.QDialog): QtCore.QObject.connect(self.ui.pushButtonNamecoinTest, QtCore.SIGNAL( "clicked()"), self.click_pushButtonNamecoinTest) - #Adjusting time period for resending messages tab.AQWA - self.ui.lineEditHours.setText(str(#Giving values to edit boxes in the UI.AQWA + #Adjusting time period to stop sending messages tab + self.ui.lineEditHours.setText(str( shared.config.get('bitmessagesettings', 'hours'))) self.ui.lineEditDays.setText(str( shared.config.get('bitmessagesettings', 'days'))) self.ui.lineEditMonths.setText(str( - shared.config.get('bitmessagesettings', 'months')))#AQWA. + shared.config.get('bitmessagesettings', 'months'))) #'System' tab removed for now. diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index f9c3518a..4667021b 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -318,10 +318,9 @@ class Ui_settingsDialog(object): self.gridLayout_8.addLayout(self.horizontalLayout, 1, 0, 1, 3) self.tabWidgetSettings.addTab(self.tabNamecoin, _fromUtf8("")) self.gridLayout.addWidget(self.tabWidgetSettings, 0, 0, 1, 1) -#this line existed before -#my new implementation starts here - self.tabResendingMessagesAdjustment=QtGui.QWidget()#all these lines are for the UI implementation, I dont think that you need special explanation about them.AQWA - self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment"))#Please note that approximately 58 line codes added to setting.ui also responsible for the UI.AQWA + #start:UI setting to stop trying to send messages after X hours/days/months + self.tabResendingMessagesAdjustment=QtGui.QWidget() + self.tabResendingMessagesAdjustment.setObjectName(_fromUtf8("tabResendingMessagesAdjustment")) self.gridLayout_9 = QtGui.QGridLayout(self.tabResendingMessagesAdjustment) self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9")) self.label_19 = QtGui.QLabel(self.tabResendingMessagesAdjustment) @@ -335,11 +334,11 @@ class Ui_settingsDialog(object): self.label_20 = QtGui.QLabel(self.tabResendingMessagesAdjustment) self.label_20.setLayoutDirection(QtCore.Qt.LeftToRight) self.label_20.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) - self.label_20.setObjectName(_fromUtf8("label_20"))#This are Qt code..I just add a label to my tab.AQWA + self.label_20.setObjectName(_fromUtf8("label_20")) self.gridLayout_9.addWidget(self.label_20, 2, 0, 1, 1) self.lineEditHours = QtGui.QLineEdit(self.tabResendingMessagesAdjustment) self.lineEditHours.setMaximumSize(QtCore.QSize(33, 16777)) - self.lineEditHours.setObjectName(_fromUtf8("lineEditHours"))##This are Qt code..I just add a edit box to my tab.AQWA + self.lineEditHours.setObjectName(_fromUtf8("lineEditHours")) self.gridLayout_9.addWidget(self.lineEditHours, 2, 1, 1, 1) self.label_22 = QtGui.QLabel(self.tabResendingMessagesAdjustment) self.label_22.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignTrailing|QtCore.Qt.AlignVCenter) @@ -360,7 +359,7 @@ class Ui_settingsDialog(object): spacerItem15 = QtGui.QSpacerItem(20, 147, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_9.addItem(spacerItem15, 3, 1, 1, 1) self.tabWidgetSettings.addTab(self.tabResendingMessagesAdjustment, _fromUtf8("")) - #my new implementation stops here, it wasn't line here + #end self.retranslateUi(settingsDialog) self.tabWidgetSettings.setCurrentIndex(0) QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), settingsDialog.accept) @@ -424,13 +423,13 @@ class Ui_settingsDialog(object): self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab), _translate("settingsDialog", "Demanded difficulty", None)) self.label_15.setText(_translate("settingsDialog", "Here you may set the maximum amount of work you are willing to do to send a message to another person. Setting these values to 0 means that any value is acceptable.", None)) self.label_13.setText(_translate("settingsDialog", "Maximum acceptable total difficulty:", None)) - #my new implementation starts here,it wasn't line here.Too simple to explain :D..AQWA - self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendingMessagesAdjustment), _translate("settingsDialog", "Adjusting time period for resending messages", 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)) + #start:UI setting to stop trying to send messages after X hours/days/months + self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tabResendingMessagesAdjustment), _translate("settingsDialog", "Adjusting time period to stop sending messages", None)) + self.label_19.setText(_translate("settingsDialog", "

If you send a message to someone and he is offline for more than two and a half days, Bitmessage will send the message again after an additional two and a half days. This will be continued with exponential backoff forever. Μessages will continue to be sent after 5, 10, 20 days etc. until the receiver gets them.

Leaving all the input fields blank means the default behavior which will continue the resending with exponential backoff.

Setting these values to 0/0/0 or less than 5 days mean that the client will not resend any messages.

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)) - #my new implementation stops here, it wasn't line here + #end self.label_14.setText(_translate("settingsDialog", "Maximum acceptable small message difficulty:", None)) self.tabWidgetSettings.setTabText(self.tabWidgetSettings.indexOf(self.tab_2), _translate("settingsDialog", "Max acceptable difficulty", None)) self.label_16.setText(_translate("settingsDialog", "

Bitmessage can utilize a different Bitcoin-based program called Namecoin to make addresses human-friendly. For example, instead of having to tell your friend your long Bitmessage address, you can simply tell him to send a message to test.

(Getting your own Bitmessage address into Namecoin is still rather difficult).

Bitmessage can use either namecoind directly or a running nmcontrol instance.

", None)) diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 94610c03..9ecdfa11 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -758,13 +758,13 @@ - Adjusting time period for resending messages + Adjusting time period to stop sending messages - 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. Μessages will continue to be sent after 4, 8,16 days etc. 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./p></body></html> + If you send a message to someone and he is offline for more than two and a half days, Bitmessage will send the message again after an additional two and a half days. This will be continued with exponential backoff forever. Μessages will continue to be sent after 5, 10, 20 days etc. until the receiver gets them. Leaving all the input fields blank means the default behavior which will continue the resending with exponential backoff. Setting these values to 0/0/0 or less than 5 days mean that the client will not resend any messages. Here you can adjust Bitmessage to stop trying to send messages after X hours/days/months./p></body></html> true diff --git a/src/class_singleCleaner.py b/src/class_singleCleaner.py index dfeaf4a1..2d80c6ce 100644 --- a/src/class_singleCleaner.py +++ b/src/class_singleCleaner.py @@ -85,21 +85,21 @@ class singleCleaner(threading.Thread): break toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, pubkeyretrynumber, msgretrynumber = row - if status == 'awaitingpubkey': - if int(shared.config.get('bitmessagesettings', 'timeperiod'))> -1:#My implemenentation starts here.This if statement would become very big with my new code,so I created two function(see at the end of this file) to reduce code.I did.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.AQWA - 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.AQWA - resendPubkey(pubkeyretrynumber,toripe) - 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.AQWA + if status == 'awaitingpubkey':#start:UI setting to stop trying to send messages after X hours/days/months + if int(shared.config.get('bitmessagesettings', 'timeperiod'))> -1:#The default value of timeperiod is -1. + if (int(time.time()) - lastactiontime) > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))) and ((int(time.time()) - lastactiontime) < int(shared.config.get('bitmessagesettings', 'timeperiod'))): + resendPubkey(pubkeyretrynumber,toripe)#This will be executed if the user has adjusted the time period with some value + else: if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (pubkeyretrynumber))): - resendPubkey(pubkeyretrynumber,toripe) + resendPubkey(pubkeyretrynumber,toripe)#This will be executed if the time period has its default value -1. Input (blank/blank/blank) 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!.AQWA - if (int(time.time()) - lastactiontime) > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))) and ((int(time.time()) - lastactiontime) < int(shared.config.get('bitmessagesettings', 'timeperiod'))):#same thing here.My implementation in this file stops here.AQWA + if int(shared.config.get('bitmessagesettings', 'timeperiod'))> -1: + if (int(time.time()) - lastactiontime) > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))) and ((int(time.time()) - lastactiontime) < int(shared.config.get('bitmessagesettings', 'timeperiod'))): resendMsg(msgretrynumber,ackdata) else: if int(time.time()) - lastactiontime > (shared.maximumAgeOfAnObjectThatIAmWillingToAccept * (2 ** (msgretrynumber))): resendMsg(msgretrynumber,ackdata) - + #end # Let's also clear and reload shared.inventorySets to keep it from # taking up an unnecessary amount of memory. @@ -130,8 +130,8 @@ class singleCleaner(threading.Thread): shared.knownNodesLock.release() shared.needToWriteKnownNodesToDisk = False time.sleep(300) - -def resendPubkey(pubkeyretrynumber,toripe):#I just structured the code with these two functions. The code inside existed.It is not mine.AQWA + #start:UI setting to stop trying to send messages after X hours/days/months +def resendPubkey(pubkeyretrynumber,toripe):#We just structured the code with these two functions to reduce code redundancy print 'It has been a long time and we haven\'t heard a response to our getpubkey request. Sending again.' try: del shared.neededPubkeys[ @@ -160,6 +160,7 @@ def resendMsg(msgretrynumber,ackdata): shared.workerQueue.put(('sendmessage', '')) shared.UISignalQueue.put(( 'updateStatusBar', 'Doing work necessary to again attempt to deliver a message...')) + #end \ No newline at end of file diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 228bd3ad..e6c9b38a 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -268,24 +268,23 @@ class sqlThread(threading.Thread): item = '''update settings set value=? WHERE key='version';''' parameters = (5,) self.cur.execute(item, parameters) - - # 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, 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.AQWA - 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.AQWA - '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.AQWA + + #Adjusting time period to stop sending messages + if shared.config.getint('bitmessagesettings', 'settingsversion') == 7: + shared.config.set( + 'bitmessagesettings', 'hours', '') shared.config.set( 'bitmessagesettings', 'days', '') shared.config.set( 'bitmessagesettings', 'months', '') shared.config.set( - '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.AQWA - 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.AQWA + 'bitmessagesettings', 'timeperiod', '-1') + shared.config.set('bitmessagesettings', 'settingsversion', '8') with open(shared.appdata + 'keys.dat', 'wb') as configfile: shared.config.write(configfile) - #my new implementation in this file stops here + + # Are you hoping to add a new option to the keys.dat file of existing + # Bitmessage users? Add it right above this line! try: testpayload = '\x00\x00' diff --git a/src/helper_startup.py b/src/helper_startup.py index 2469f82e..de92e456 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -85,22 +85,22 @@ def loadConfig(): shared.config.set('bitmessagesettings', 'dontconnect', 'true') shared.config.set('bitmessagesettings', 'userlocale', 'system') - # Are you hoping to add a new option to the keys.dat file? You're in - # the right place for adding it to users who install the software for - # the first time. But you must also add it to the keys.dat file of - # existing users. To do that, search the class_sqlThread.py file for the - # text: "right above this line!" - - #my implementation starts here. AQWA + #start:UI setting to stop trying to send messages after X hours/days/months shared.config.set( - '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 :) ).AQWA + 'bitmessagesettings', 'hours', '') shared.config.set( 'bitmessagesettings', 'days', '') shared.config.set( 'bitmessagesettings', 'months', '') shared.config.set( 'bitmessagesettings', 'timeperiod', '-1') - #my implementation in this file stops here.AQWA + #end + + # Are you hoping to add a new option to the keys.dat file? You're in + # the right place for adding it to users who install the software for + # the first time. But you must also add it to the keys.dat file of + # existing users. To do that, search the class_sqlThread.py file for the + # text: "right above this line!" ensureNamecoinOptions() From ed0a57d99886a8c89bbb7120ec3036b27a6b7019 Mon Sep 17 00:00:00 2001 From: Joshua Noble Date: Sat, 12 Oct 2013 00:33:19 -0400 Subject: [PATCH 11/14] Fixed typo in getInboxMessagesByAddress --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index ef2a2ddd..26a2a92d 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -461,7 +461,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if len(params) == 0: raise APIError(0, 'I need parameters!') toAddress = params[0] - queryReturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype FROM inbox WHERE folder='inbox' AND toAddress=?''', toAddress) + queryreturn = sqlQuery('''SELECT msgid, toaddress, fromaddress, subject, received, message, encodingtype FROM inbox WHERE folder='inbox' AND toAddress=?''', toAddress) data = '{"inboxMessages":[' for row in queryreturn: msgid, toAddress, fromAddress, subject, received, message, encodingtype = row From 55568fa242e50a7dbc73400d9e60fe4e34875bf7 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Sun, 13 Oct 2013 13:45:30 -0400 Subject: [PATCH 12/14] Don't store messages in UI table (and thus in memory), pull from SQL inventory as needed --- src/bitmessageqt/__init__.py | 71 +++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 768e681b..b0193e33 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -560,7 +560,7 @@ class MyForm(QtGui.QMainWindow): where = "toaddress || fromaddress || subject || message" sqlStatement = ''' - SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime + SELECT toaddress, fromaddress, subject, status, ackdata, lastactiontime FROM sent WHERE folder="sent" AND %s LIKE ? ORDER BY lastactiontime ''' % (where,) @@ -570,9 +570,9 @@ class MyForm(QtGui.QMainWindow): queryreturn = sqlQuery(sqlStatement, what) for row in queryreturn: - toAddress, fromAddress, subject, message, status, ackdata, lastactiontime = row + toAddress, fromAddress, subject, status, ackdata, lastactiontime = row subject = shared.fixPotentiallyInvalidUTF8Data(subject) - message = shared.fixPotentiallyInvalidUTF8Data(message) + #message = shared.fixPotentiallyInvalidUTF8Data(message) try: fromLabel = shared.config.get(fromAddress, 'label') except: @@ -612,7 +612,7 @@ class MyForm(QtGui.QMainWindow): self.ui.tableWidgetSent.setItem(0, 1, newItem) newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8')) newItem.setToolTip(unicode(subject, 'utf-8')) - newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) + #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed. newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.tableWidgetSent.setItem(0, 2, newItem) @@ -680,7 +680,7 @@ class MyForm(QtGui.QMainWindow): where = "toaddress || fromaddress || subject || message" sqlStatement = ''' - SELECT msgid, toaddress, fromaddress, subject, received, message, read + SELECT msgid, toaddress, fromaddress, subject, received, read FROM inbox WHERE folder="inbox" AND %s LIKE ? ORDER BY received ''' % (where,) @@ -692,9 +692,9 @@ class MyForm(QtGui.QMainWindow): font.setBold(True) queryreturn = sqlQuery(sqlStatement, what) for row in queryreturn: - msgid, toAddress, fromAddress, subject, received, message, read = row + msgid, toAddress, fromAddress, subject, received, read = row subject = shared.fixPotentiallyInvalidUTF8Data(subject) - message = shared.fixPotentiallyInvalidUTF8Data(message) + #message = shared.fixPotentiallyInvalidUTF8Data(message) try: if toAddress == self.str_broadcast_subscribers: toLabel = self.str_broadcast_subscribers @@ -750,7 +750,7 @@ class MyForm(QtGui.QMainWindow): self.ui.tableWidgetInbox.setItem(0, 1, newItem) newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8')) newItem.setToolTip(unicode(subject, 'utf-8')) - newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) + #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table (and thus in memory); we'll use a SQL query when we need to display it. newItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) if not read: @@ -1765,7 +1765,7 @@ class MyForm(QtGui.QMainWindow): self.ui.tableWidgetSent.setItem(0, 1, newItem) newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)')) newItem.setToolTip(unicode(subject, 'utf-8)')) - newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) + #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed. self.ui.tableWidgetSent.setItem(0, 2, newItem) # newItem = QtGui.QTableWidgetItem('Doing work necessary to send # broadcast...'+ @@ -1778,13 +1778,12 @@ class MyForm(QtGui.QMainWindow): newItem.setData(Qt.UserRole, QByteArray(ackdata)) newItem.setData(33, int(time.time())) self.ui.tableWidgetSent.setItem(0, 3, newItem) - self.ui.textEditSentMessage.setPlainText( - self.ui.tableWidgetSent.item(0, 2).data(Qt.UserRole).toPyObject()) + self.ui.textEditSentMessage.setPlainText(message) self.ui.tableWidgetSent.setSortingEnabled(True) def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): subject = shared.fixPotentiallyInvalidUTF8Data(subject) - message = shared.fixPotentiallyInvalidUTF8Data(message) + #message = shared.fixPotentiallyInvalidUTF8Data(message) fromLabel = '' queryreturn = sqlQuery( '''select label from addressbook where address=?''', fromAddress) @@ -1838,7 +1837,7 @@ class MyForm(QtGui.QMainWindow): self.ui.tableWidgetInbox.setItem(0, 1, newItem) newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)')) newItem.setToolTip(unicode(subject, 'utf-8)')) - newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) + #newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) # No longer hold the message in the table; we'll use a SQL query to display it as needed. newItem.setFont(font) self.ui.tableWidgetInbox.setItem(0, 2, newItem) newItem = myTableWidgetItem(unicode(strftime(shared.config.get( @@ -2292,6 +2291,13 @@ class MyForm(QtGui.QMainWindow): currentInboxRow, 0).data(Qt.UserRole).toPyObject()) fromAddressAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item( currentInboxRow, 1).data(Qt.UserRole).toPyObject()) + msgid = str(self.ui.tableWidgetInbox.item( + currentInboxRow, 3).data(Qt.UserRole).toPyObject()) + queryreturn = sqlQuery( + '''select message from inbox where msgid=?''', msgid) + if queryreturn != []: + for row in queryreturn: + messageAtCurrentInboxRow, = row if toAddressAtCurrentInboxRow == self.str_broadcast_subscribers: self.ui.labelFrom.setText('') elif not shared.config.has_section(toAddressAtCurrentInboxRow): @@ -2315,9 +2321,7 @@ class MyForm(QtGui.QMainWindow): self.ui.lineEditTo.setText(str(toAddressAtCurrentInboxRow)) self.ui.comboBoxSendFrom.setCurrentIndex(0) - # self.ui.comboBoxSendFrom.setEditText(str(self.ui.tableWidgetInbox.item(currentInboxRow,0).text)) - self.ui.textEditMessage.setText('\n\n------------------------------------------------------\n' + self.ui.tableWidgetInbox.item( - currentInboxRow, 2).data(Qt.UserRole).toPyObject()) + self.ui.textEditMessage.setText('\n\n------------------------------------------------------\n' + unicode(messageAtCurrentInboxRow, 'utf-8)')) if self.ui.tableWidgetInbox.item(currentInboxRow, 2).text()[0:3] in ['Re:', 'RE:']: self.ui.lineEditSubject.setText( self.ui.tableWidgetInbox.item(currentInboxRow, 2).text()) @@ -2716,21 +2720,27 @@ class MyForm(QtGui.QMainWindow): fromAddress = str(self.ui.tableWidgetInbox.item( currentRow, 1).data(Qt.UserRole).toPyObject()) + msgid = str(self.ui.tableWidgetInbox.item( + currentRow, 3).data(Qt.UserRole).toPyObject()) + queryreturn = sqlQuery( + '''select message from inbox where msgid=?''', msgid) + if queryreturn != []: + for row in queryreturn: + message, = row + message = unicode(message, 'utf-8)') # If we have received this message from either a broadcast address # or from someone in our address book, display as HTML if decodeAddress(fromAddress)[3] in shared.broadcastSendersForWhichImWatching or shared.isAddressInMyAddressBook(fromAddress): - if len(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()) < 30000: - self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item( - currentRow, 2).data(Qt.UserRole).toPyObject()) # Only show the first 30K characters + if len(message) < 30000: + self.ui.textEditInboxMessage.setText(message) # Only show the first 30K characters else: - self.ui.textEditInboxMessage.setText(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()[ + self.ui.textEditInboxMessage.setText(message[ :30000] + '\n\nDisplay of the remainder of the message truncated because it is too long.') # Only show the first 30K characters else: - if len(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()) < 30000: - self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item( - currentRow, 2).data(Qt.UserRole).toPyObject()) # Only show the first 30K characters + if len(message) < 30000: + self.ui.textEditInboxMessage.setPlainText(message) # Only show the first 30K characters else: - self.ui.textEditInboxMessage.setPlainText(self.ui.tableWidgetInbox.item(currentRow, 2).data(Qt.UserRole).toPyObject()[ + self.ui.textEditInboxMessage.setPlainText(message[ :30000] + '\n\nDisplay of the remainder of the message truncated because it is too long.') # Only show the first 30K characters self.ui.tableWidgetInbox.item(currentRow, 0).setFont(font) @@ -2746,8 +2756,17 @@ class MyForm(QtGui.QMainWindow): def tableWidgetSentItemClicked(self): currentRow = self.ui.tableWidgetSent.currentRow() if currentRow >= 0: - self.ui.textEditSentMessage.setPlainText(self.ui.tableWidgetSent.item( - currentRow, 2).data(Qt.UserRole).toPyObject()) + ackdata = str(self.ui.tableWidgetSent.item( + currentRow, 3).data(Qt.UserRole).toPyObject()) + queryreturn = sqlQuery( + '''select message from sent where ackdata=?''', ackdata) + if queryreturn != []: + for row in queryreturn: + message, = row + else: + message = "Error occurred: could not load message from disk." + message = unicode(message, 'utf-8)') + self.ui.textEditSentMessage.setPlainText(message) def tableWidgetYourIdentitiesItemChanged(self): currentRow = self.ui.tableWidgetYourIdentities.currentRow() From 24452cddb21376ac474ad41601c99a5a25b6040a Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Sun, 13 Oct 2013 14:08:12 -0400 Subject: [PATCH 13/14] check return value of RAND_bytes --- src/pyelliptic/openssl.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pyelliptic/openssl.py b/src/pyelliptic/openssl.py index ee75f90a..f83630d4 100644 --- a/src/pyelliptic/openssl.py +++ b/src/pyelliptic/openssl.py @@ -268,7 +268,7 @@ class _OpenSSL: self.EVP_MD_CTX_destroy.argtypes = [ctypes.c_void_p] self.RAND_bytes = self._lib.RAND_bytes - self.RAND_bytes.restype = None + self.RAND_bytes.restype = ctypes.c_int self.RAND_bytes.argtypes = [ctypes.c_void_p, ctypes.c_int] @@ -394,7 +394,15 @@ class _OpenSSL: OpenSSL random function """ buffer = self.malloc(0, size) - self.RAND_bytes(buffer, size) + # This pyelliptic library, by default, didn't check the return value of RAND_bytes. It is + # evidently possible that it returned an error and not-actually-random data. However, in + # tests on various operating systems, while generating hundreds of gigabytes of random + # strings of various sizes I could not get an error to occur. Also Bitcoin doesn't check + # the return value of RAND_bytes either. + # Fixed in Bitmessage version 0.4.2 (in source code on 2013-10-13) + while self.RAND_bytes(buffer, size) != 1: + import time + time.sleep(1) return buffer.raw def malloc(self, data, size): From 7a30db75f1a3d37691519fc9f17f08151f44e29d Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Wed, 16 Oct 2013 01:08:22 -0400 Subject: [PATCH 14/14] Use SQL-stored message when using 'Display as HTML' feature --- src/bitmessageqt/__init__.py | 69 ++++++++++++++---------------------- src/shared.py | 4 +-- 2 files changed, 29 insertions(+), 44 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index b0193e33..f8ba57a8 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -1632,44 +1632,12 @@ class MyForm(QtGui.QMainWindow): sqlExecute( '''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t) - shared.workerQueue.put(('sendbroadcast', '')) - - try: - fromLabel = shared.config.get(fromAddress, 'label') - except: - fromLabel = '' - if fromLabel == '': - fromLabel = fromAddress - toLabel = self.str_broadcast_subscribers + + self.displayNewSentMessage( + toAddress, toLabel, fromAddress, subject, message, ackdata) - self.ui.tableWidgetSent.insertRow(0) - newItem = QtGui.QTableWidgetItem(unicode(toLabel, 'utf-8')) - newItem.setData(Qt.UserRole, str(toAddress)) - self.ui.tableWidgetSent.setItem(0, 0, newItem) - - if fromLabel == '': - newItem = QtGui.QTableWidgetItem( - unicode(fromAddress, 'utf-8')) - else: - newItem = QtGui.QTableWidgetItem( - unicode(fromLabel, 'utf-8')) - newItem.setData(Qt.UserRole, str(fromAddress)) - self.ui.tableWidgetSent.setItem(0, 1, newItem) - newItem = QtGui.QTableWidgetItem(unicode(subject, 'utf-8)')) - newItem.setData(Qt.UserRole, unicode(message, 'utf-8)')) - self.ui.tableWidgetSent.setItem(0, 2, newItem) - # newItem = QtGui.QTableWidgetItem('Doing work necessary to - # send broadcast...'+ - # unicode(strftime(config.get('bitmessagesettings', - # 'timeformat'),localtime(int(time.time()))),'utf-8')) - newItem = myTableWidgetItem(_translate("MainWindow", "Work is queued.")) - newItem.setData(Qt.UserRole, QByteArray(ackdata)) - newItem.setData(33, int(time.time())) - self.ui.tableWidgetSent.setItem(0, 3, newItem) - - self.ui.textEditSentMessage.setPlainText( - self.ui.tableWidgetSent.item(0, 2).data(Qt.UserRole).toPyObject()) + shared.workerQueue.put(('sendbroadcast', '')) self.ui.comboBoxSendFrom.setCurrentIndex(0) self.ui.labelFrom.setText('') @@ -1778,7 +1746,7 @@ class MyForm(QtGui.QMainWindow): newItem.setData(Qt.UserRole, QByteArray(ackdata)) newItem.setData(33, int(time.time())) self.ui.tableWidgetSent.setItem(0, 3, newItem) - self.ui.textEditSentMessage.setPlainText(message) + self.ui.textEditSentMessage.setPlainText(unicode(message, 'utf-8)')) self.ui.tableWidgetSent.setSortingEnabled(True) def displayNewInboxMessage(self, inventoryHash, toAddress, fromAddress, subject, message): @@ -2254,10 +2222,18 @@ class MyForm(QtGui.QMainWindow): def on_action_InboxMessageForceHtml(self): currentInboxRow = self.ui.tableWidgetInbox.currentRow() - lines = self.ui.tableWidgetInbox.item( - currentInboxRow, 2).data(Qt.UserRole).toPyObject().split('\n') + + msgid = str(self.ui.tableWidgetInbox.item( + currentInboxRow, 3).data(Qt.UserRole).toPyObject()) + queryreturn = sqlQuery( + '''select message from inbox where msgid=?''', msgid) + if queryreturn != []: + for row in queryreturn: + messageAtCurrentInboxRow, = row + + lines = messageAtCurrentInboxRow.split('\n') for i in xrange(len(lines)): - if lines[i].contains('Message ostensibly from '): + if 'Message ostensibly from ' in lines[i]: lines[i] = '

%s

' % ( lines[i]) elif lines[i] == '------------------------------------------------------': @@ -2381,14 +2357,23 @@ class MyForm(QtGui.QMainWindow): subjectAtCurrentInboxRow = str(self.ui.tableWidgetInbox.item(currentInboxRow,2).text()) except: subjectAtCurrentInboxRow = '' + + # Retrieve the message data out of the SQL database + msgid = str(self.ui.tableWidgetInbox.item( + currentInboxRow, 3).data(Qt.UserRole).toPyObject()) + queryreturn = sqlQuery( + '''select message from inbox where msgid=?''', msgid) + if queryreturn != []: + for row in queryreturn: + message, = row + defaultFilename = "".join(x for x in subjectAtCurrentInboxRow if x.isalnum()) + '.txt' - data = self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject() filename = QFileDialog.getSaveFileName(self, _translate("MainWindow","Save As..."), defaultFilename, "Text files (*.txt);;All files (*.*)") if filename == '': return try: f = open(filename, 'w') - f.write( self.ui.tableWidgetInbox.item(currentInboxRow,2).data(Qt.UserRole).toPyObject() ) + f.write(message) f.close() except Exception, e: sys.stderr.write('Write error: '+ e) diff --git a/src/shared.py b/src/shared.py index 54acc014..2c07f7d0 100644 --- a/src/shared.py +++ b/src/shared.py @@ -279,6 +279,8 @@ def reloadBroadcastSendersForWhichImWatching(): def doCleanShutdown(): global shutdown shutdown = 1 #Used to tell proof of work worker threads to exit. + broadcastToSendDataQueues((0, 'shutdown', 'all')) + knownNodesLock.acquire() UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...')) output = open(appdata + 'knownnodes.dat', 'wb') @@ -290,8 +292,6 @@ def doCleanShutdown(): logger.info('Finished closing knownnodes.dat output file.') UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.')) - broadcastToSendDataQueues((0, 'shutdown', 'all')) - logger.info('Flushing inventory in memory out to disk...') UISignalQueue.put(( 'updateStatusBar',