allowing for max connection configuration #939

Closed
ghost wants to merge 6 commits from maxconnection-config into v0.6
6 changed files with 58 additions and 1 deletions

View File

@ -2391,6 +2391,14 @@ class MyForm(settingsmixin.SMainWindow):
QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate( QMessageBox.about(self, _translate("MainWindow", "Number needed"), _translate(
"MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed.")) "MainWindow", "Your maximum download and upload rate must be numbers. Ignoring what you typed."))
bmng-dev commented 2017-01-11 04:03:09 +01:00 (Migrated from github.com)
Review

Refer to the immediately preceding options to see how to ensure the user entered a number.

Refer to the immediately preceding options to see how to ensure the user entered a number.
try:
# Ensure we have an integer
PeterSurda commented 2017-01-11 21:10:54 +01:00 (Migrated from github.com)
Review

Instead of this whole exception handling, try something like
lineEditMaxOutboundConnections.setValidator(QIntValidator(1, 1024, lineEditMaxOutboundConnections))
in settings.py (1 being the lower limit, 1024 the top).

For a more complex example look into newchandialog.py and addressvalidator.py, in your case you don't need a new validator class, you can use the QIntValidator as it is.

Instead of this whole exception handling, try something like `lineEditMaxOutboundConnections.setValidator(QIntValidator(1, 1024, lineEditMaxOutboundConnections))` in settings.py (1 being the lower limit, 1024 the top). For a more complex example look into newchandialog.py and addressvalidator.py, in your case you don't need a new validator class, you can use the QIntValidator as it is.
Review

👍

👍
BMConfigParser().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."))
BMConfigParser().set('bitmessagesettings', 'namecoinrpctype', BMConfigParser().set('bitmessagesettings', 'namecoinrpctype',
self.settingsDialogInstance.getNamecoinType()) self.settingsDialogInstance.getNamecoinType())
BMConfigParser().set('bitmessagesettings', 'namecoinrpchost', str( BMConfigParser().set('bitmessagesettings', 'namecoinrpchost', str(
@ -4075,6 +4083,8 @@ class settingsDialog(QtGui.QDialog):
BMConfigParser().get('bitmessagesettings', 'sockspassword'))) BMConfigParser().get('bitmessagesettings', 'sockspassword')))
QtCore.QObject.connect(self.ui.comboBoxProxyType, QtCore.SIGNAL( QtCore.QObject.connect(self.ui.comboBoxProxyType, QtCore.SIGNAL(
"currentIndexChanged(int)"), self.comboBoxProxyTypeChanged) "currentIndexChanged(int)"), self.comboBoxProxyTypeChanged)
self.ui.lineEditMaxOutboundConnections.setText(str(
shared.config.get('bitmessagesettings', 'maxoutboundconnections')))
self.ui.lineEditMaxDownloadRate.setText(str( self.ui.lineEditMaxDownloadRate.setText(str(
BMConfigParser().get('bitmessagesettings', 'maxdownloadrate'))) BMConfigParser().get('bitmessagesettings', 'maxdownloadrate')))
self.ui.lineEditMaxUploadRate.setText(str( self.ui.lineEditMaxUploadRate.setText(str(

View File

@ -154,6 +154,18 @@ class Ui_settingsDialog(object):
self.lineEditMaxUploadRate.setMaximumSize(QtCore.QSize(60, 16777215)) self.lineEditMaxUploadRate.setMaximumSize(QtCore.QSize(60, 16777215))
self.lineEditMaxUploadRate.setObjectName(_fromUtf8("lineEditMaxUploadRate")) self.lineEditMaxUploadRate.setObjectName(_fromUtf8("lineEditMaxUploadRate"))
self.gridLayout_9.addWidget(self.lineEditMaxUploadRate, 1, 2, 1, 1) 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"))
PeterSurda commented 2017-01-11 21:14:05 +01:00 (Migrated from github.com)
Review

how about also
self.lineEditMaxOutboundConnections.setPlaceholderText(_fromUtf8("8"))

how about also `self.lineEditMaxOutboundConnections.setPlaceholderText(_fromUtf8("8"))`
self.gridLayout_9.addWidget(self.lineEditMaxOutboundConnections, 2, 2, 1, 1)
self.gridLayout_4.addWidget(self.groupBox_3, 2, 0, 1, 1) self.gridLayout_4.addWidget(self.groupBox_3, 2, 0, 1, 1)
self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings) self.groupBox_2 = QtGui.QGroupBox(self.tabNetworkSettings)
self.groupBox_2.setObjectName(_fromUtf8("groupBox_2")) self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
@ -459,6 +471,7 @@ class Ui_settingsDialog(object):
self.groupBox_3.setTitle(_translate("settingsDialog", "Bandwidth limit", None)) 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_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_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.groupBox_2.setTitle(_translate("settingsDialog", "Proxy server / Tor", None))
self.label_2.setText(_translate("settingsDialog", "Type:", None)) self.label_2.setText(_translate("settingsDialog", "Type:", None))
self.label_3.setText(_translate("settingsDialog", "Server hostname:", None)) self.label_3.setText(_translate("settingsDialog", "Server hostname:", None))

View File

@ -317,6 +317,29 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QLabel" name="label_26">
<property name="text">
<string>Maximum outbound connections: [0: none]</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="lineEditMaxOutboundConnections">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

View File

@ -79,7 +79,7 @@ class outgoingSynSender(threading.Thread, StoppableThread):
self.stop.wait(2) self.stop.wait(2)
while BMConfigParser().safeGetBoolean('bitmessagesettings', 'sendoutgoingconnections') and not self._stopped: while BMConfigParser().safeGetBoolean('bitmessagesettings', 'sendoutgoingconnections') and not self._stopped:
self.name = "outgoingSynSender" 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: while len(self.selfInitiatedConnections[self.streamNumber]) >= maximumConnections:
self.stop.wait(10) self.stop.wait(10)
if shared.shutdown: if shared.shutdown:

View File

@ -433,6 +433,16 @@ class sqlThread(threading.Thread):
BMConfigParser().set('bitmessagesettings', 'smtpdeliver', '') BMConfigParser().set('bitmessagesettings', 'smtpdeliver', '')
if not BMConfigParser().has_option('bitmessagesettings', 'hidetrayconnectionnotifications'): if not BMConfigParser().has_option('bitmessagesettings', 'hidetrayconnectionnotifications'):
BMConfigParser().set('bitmessagesettings', 'hidetrayconnectionnotifications', 'false') BMConfigParser().set('bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
if BMConfigParser().has_option('bitmessagesettings', 'maxoutboundconnections'):
try:
# Ensure we have an integer
int(float(BMConfigParser().get('bitmessagesettings', 'maxoutboundconnections')))
PeterSurda commented 2017-01-11 21:23:02 +01:00 (Migrated from github.com)
Review

Maybe
if BMConfigParser().getint('bitmessagesettings', 'maxoutboundconnections'))) < 1: throw ValueException

Maybe `if BMConfigParser().getint('bitmessagesettings', 'maxoutboundconnections'))) < 1: throw ValueException `
except:
PeterSurda commented 2017-01-11 21:24:15 +01:00 (Migrated from github.com)
Review

And this should be
except ValueException:
because you're supposed to always name the exception. I haven't always done it but in new code we should try to do that.

And this should be `except ValueException:` because you're supposed to always name the exception. I haven't always done it but in new code we should try to do that.
logger.fatal('Your maximum outbound connections must be a number.')
PeterSurda commented 2017-01-11 21:02:28 +01:00 (Migrated from github.com)
Review

This should simply log an error and set it to 8 instead of dying.

This should simply log an error and set it to 8 instead of dying.
os._exit(0)
else:
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
shared.writeKeysFile() shared.writeKeysFile()
# Are you hoping to add a new option to the keys.dat file of existing # Are you hoping to add a new option to the keys.dat file of existing

View File

@ -108,6 +108,7 @@ def loadConfig():
BMConfigParser().set('bitmessagesettings', 'replybelow', 'False') BMConfigParser().set('bitmessagesettings', 'replybelow', 'False')
BMConfigParser().set('bitmessagesettings', 'maxdownloadrate', '0') BMConfigParser().set('bitmessagesettings', 'maxdownloadrate', '0')
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0') BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0')
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
BMConfigParser().set('bitmessagesettings', 'ttl', '367200') BMConfigParser().set('bitmessagesettings', 'ttl', '367200')
#start:UI setting to stop trying to send messages after X days/months #start:UI setting to stop trying to send messages after X days/months