From 60d489ea1619f684bb91413c262691c7484fbb54 Mon Sep 17 00:00:00 2001 From: Justin Ramos Date: Sat, 7 Jan 2017 02:33:28 +0000 Subject: [PATCH 1/3] allowing for max outbound connection configuration --- src/bitmessageqt/__init__.py | 4 ++++ src/bitmessageqt/settings.py | 13 +++++++++++++ src/bitmessageqt/settings.ui | 23 +++++++++++++++++++++++ src/class_outgoingSynSender.py | 2 +- src/class_sqlThread.py | 2 ++ src/helper_startup.py | 1 + 6 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 593a8b4b..5ca1064b 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2418,6 +2418,8 @@ class MyForm(settingsmixin.SMainWindow): QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate( "MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed.")) + shared.config.set('bitmessagesettings', 'maxoutboundconnections', str( + self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text())) shared.config.set('bitmessagesettings', 'namecoinrpctype', self.settingsDialogInstance.getNamecoinType()) shared.config.set('bitmessagesettings', 'namecoinrpchost', str( @@ -4049,6 +4051,8 @@ class settingsDialog(QtGui.QDialog): shared.config.get('bitmessagesettings', 'sockspassword'))) QtCore.QObject.connect(self.ui.comboBoxProxyType, QtCore.SIGNAL( "currentIndexChanged(int)"), self.comboBoxProxyTypeChanged) + self.ui.lineEditMaxOutboundConnections.setText(str( + shared.config.get('bitmessagesettings', 'maxoutboundconnections'))) self.ui.lineEditMaxDownloadRate.setText(str( shared.config.get('bitmessagesettings', 'maxdownloadrate'))) self.ui.lineEditMaxUploadRate.setText(str( diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 6b7dd9b3..e58afb54 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -149,6 +149,18 @@ class Ui_settingsDialog(object): self.lineEditMaxUploadRate.setMaximumSize(QtCore.QSize(60, 16777215)) self.lineEditMaxUploadRate.setObjectName(_fromUtf8("lineEditMaxUploadRate")) self.gridLayout_9.addWidget(self.lineEditMaxUploadRate, 1, 2, 1, 1) + self.label_26 = QtGui.QLabel(self.groupBox_3) + self.label_26.setObjectName(_fromUtf8("label_26")) + self.gridLayout_9.addWidget(self.label_26, 2, 1, 1, 1) + self.lineEditMaxOutboundConnections = QtGui.QLineEdit(self.groupBox_3) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.lineEditMaxOutboundConnections.sizePolicy().hasHeightForWidth()) + self.lineEditMaxOutboundConnections.setSizePolicy(sizePolicy) + self.lineEditMaxOutboundConnections.setMaximumSize(QtCore.QSize(60, 16777215)) + self.lineEditMaxOutboundConnections.setObjectName(_fromUtf8("lineEditMaxOutboundConnections")) + self.gridLayout_9.addWidget(self.lineEditMaxOutboundConnections, 2, 2, 1, 1) self.gridLayout_4.addWidget(self.groupBox_3, 2, 0, 1, 1) self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) @@ -448,6 +460,7 @@ class Ui_settingsDialog(object): self.groupBox_3.setTitle(_translate("settingsDialog", "Bandwidth limit", None)) self.label_24.setText(_translate("settingsDialog", "Maximum download rate (kB/s): [0: unlimited]", None)) self.label_25.setText(_translate("settingsDialog", "Maximum upload rate (kB/s): [0: unlimited]", None)) + self.label_26.setText(_translate("settingsDialog", "Maximum outbound connections: [0: none]", None)) self.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None)) self.label_2.setText(_translate("settingsDialog", "Type:", None)) self.label_3.setText(_translate("settingsDialog", "Server hostname:", None)) diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 475821f8..4aeba3ce 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -317,6 +317,29 @@ + + + + Maximum outbound connections: [0: none] + + + + + + + + 0 + 0 + + + + + 60 + 16777215 + + + + diff --git a/src/class_outgoingSynSender.py b/src/class_outgoingSynSender.py index f61129a2..9f0a9abd 100644 --- a/src/class_outgoingSynSender.py +++ b/src/class_outgoingSynSender.py @@ -72,7 +72,7 @@ class outgoingSynSender(threading.Thread, StoppableThread): self.stop.wait(2) while shared.safeConfigGetBoolean('bitmessagesettings', 'sendoutgoingconnections') and not self._stopped: self.name = "outgoingSynSender" - maximumConnections = 1 if shared.trustedPeer else 8 # maximum number of outgoing connections = 8 + maximumConnections = 1 if shared.trustedPeer else shared.config.getint('bitmessagesettings', 'maxoutboundconnections') while len(self.selfInitiatedConnections[self.streamNumber]) >= maximumConnections: self.stop.wait(10) if shared.shutdown: diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 016386ab..2c08cc9e 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -427,6 +427,8 @@ class sqlThread(threading.Thread): shared.config.set('bitmessagesettings', 'onionbindip', '127.0.0.1') if not shared.config.has_option('bitmessagesettings', 'smtpdeliver'): shared.config.set('bitmessagesettings', 'smtpdeliver', '') + if not shared.config.has_option('bitmessagesettings', 'maxoutboundconnections'): + shared.config.set('bitmessagesettings', 'maxoutboundconnections', '8') shared.writeKeysFile() # Are you hoping to add a new option to the keys.dat file of existing diff --git a/src/helper_startup.py b/src/helper_startup.py index b7a1ef1b..8ef27791 100644 --- a/src/helper_startup.py +++ b/src/helper_startup.py @@ -102,6 +102,7 @@ def loadConfig(): shared.config.set('bitmessagesettings', 'useidenticons', 'True') shared.config.set('bitmessagesettings', 'identiconsuffix', ''.join(random.choice("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz") for x in range(12))) # a twelve character pseudo-password to salt the identicons shared.config.set('bitmessagesettings', 'replybelow', 'False') + shared.config.set('bitmessagesettings', 'maxoutboundconnections', '8') shared.config.set('bitmessagesettings', 'maxdownloadrate', '0') shared.config.set('bitmessagesettings', 'maxuploadrate', '0') shared.config.set('bitmessagesettings', 'ttl', '367200') -- 2.45.1 From df2d5bce4c31c9bdb95bb34d5aced550dcca2805 Mon Sep 17 00:00:00 2001 From: Justin Ramos Date: Wed, 11 Jan 2017 18:11:16 +0000 Subject: [PATCH 2/3] ensure we have an integer for maxoutboundconnections when setting --- src/bitmessageqt/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 5ca1064b..a2f41abe 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2418,8 +2418,14 @@ class MyForm(settingsmixin.SMainWindow): QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate( "MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed.")) - shared.config.set('bitmessagesettings', 'maxoutboundconnections', str( - self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text())) + try: + # Ensure we have an integer + shared.config.set('bitmessagesettings', 'maxoutboundconnections', str( + int(float(self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text())))) + except: + QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate( + "MainWindow", "Your maximum outbound connections must be a number. Ignoring what you typed.")) + shared.config.set('bitmessagesettings', 'namecoinrpctype', self.settingsDialogInstance.getNamecoinType()) shared.config.set('bitmessagesettings', 'namecoinrpchost', str( -- 2.45.1 From 37f69646e9fd6b0a984c0443173e42b2aa08f335 Mon Sep 17 00:00:00 2001 From: Justin Ramos Date: Wed, 11 Jan 2017 19:57:08 +0000 Subject: [PATCH 3/3] ensure we have an integer when we read max outgoing connections from disk --- src/class_sqlThread.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py index 92aeb5d5..2ed37e59 100644 --- a/src/class_sqlThread.py +++ b/src/class_sqlThread.py @@ -433,8 +433,16 @@ class sqlThread(threading.Thread): BMConfigParser().set('bitmessagesettings', 'smtpdeliver', '') if not BMConfigParser().has_option('bitmessagesettings', 'hidetrayconnectionnotifications'): BMConfigParser().set('bitmessagesettings', 'hidetrayconnectionnotifications', 'false') - if not BMConfigParser().has_option('bitmessagesettings', 'maxoutboundconnections'): + if BMConfigParser().has_option('bitmessagesettings', 'maxoutboundconnections'): + try: + # Ensure we have an integer + int(float(BMConfigParser().get('bitmessagesettings', 'maxoutboundconnections'))) + except: + logger.fatal('Your maximum outbound connections must be a number.') + os._exit(0) + else: BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8') + shared.writeKeysFile() # Are you hoping to add a new option to the keys.dat file of existing -- 2.45.1