From 8ff8e0e2cb1f1f80a7db9f8624d64dee616ff64e Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Wed, 16 Sep 2020 18:41:51 +0300 Subject: [PATCH] Make it possible to disable UDP announcing in settings --- src/bitmessagemain.py | 7 +++--- src/bitmessageqt/settings.py | 47 ++++++++++++++++++++++++++---------- src/bitmessageqt/settings.ui | 13 +++++++--- src/bmconfigparser.py | 9 ++++--- 4 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index b54805bb..e04e3187 100755 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -321,9 +321,10 @@ class Main(object): receiveQueueThread = ReceiveQueueThread(i) receiveQueueThread.daemon = True receiveQueueThread.start() - announceThread = AnnounceThread() - announceThread.daemon = True - announceThread.start() + if config.safeGetBoolean('bitmessagesettings', 'udp'): + state.announceThread = AnnounceThread() + state.announceThread.daemon = True + state.announceThread.start() state.invThread = InvThread() state.invThread.daemon = True state.invThread.start() diff --git a/src/bitmessageqt/settings.py b/src/bitmessageqt/settings.py index 6a93e2f0..76b392c4 100644 --- a/src/bitmessageqt/settings.py +++ b/src/bitmessageqt/settings.py @@ -19,7 +19,7 @@ import widgets from bmconfigparser import BMConfigParser from helper_sql import sqlExecute, sqlStoredProcedure from helper_startup import start_proxyconfig -from network import knownnodes +from network import knownnodes, AnnounceThread from network.asyncore_pollchoose import set_rates from tr import _translate @@ -138,6 +138,8 @@ class SettingsDialog(QtGui.QDialog): config.get('bitmessagesettings', 'port'))) self.checkBoxUPnP.setChecked( config.safeGetBoolean('bitmessagesettings', 'upnp')) + self.checkBoxUDP.setChecked( + config.safeGetBoolean('bitmessagesettings', 'udp')) self.checkBoxAuthentication.setChecked( config.getboolean('bitmessagesettings', 'socksauthentication')) self.checkBoxSocksListen.setChecked( @@ -326,7 +328,8 @@ class SettingsDialog(QtGui.QDialog): self.lineEditTCPPort.text()): self.config.set( 'bitmessagesettings', 'port', str(self.lineEditTCPPort.text())) - if not self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'): + if not self.config.safeGetBoolean( + 'bitmessagesettings', 'dontconnect'): self.net_restart_needed = True if self.checkBoxUPnP.isChecked() != self.config.safeGetBoolean( @@ -339,11 +342,26 @@ class SettingsDialog(QtGui.QDialog): upnpThread = upnp.uPnPThread() upnpThread.start() + udp_enabled = self.checkBoxUDP.isChecked() + if udp_enabled != self.config.safeGetBoolean( + 'bitmessagesettings', 'udp'): + self.config.set('bitmessagesettings', 'udp', str(udp_enabled)) + if udp_enabled: + announceThread = AnnounceThread() + announceThread.daemon = True + announceThread.start() + else: + try: + state.announceThread.stopThread() + except AttributeError: + pass + proxytype_index = self.comboBoxProxyType.currentIndex() if proxytype_index == 0: if self._proxy_type and state.statusIconColor != 'red': self.net_restart_needed = True - elif state.statusIconColor == 'red' and self.config.safeGetBoolean('bitmessagesettings', 'dontconnect'): + elif state.statusIconColor == 'red' and self.config.safeGetBoolean( + 'bitmessagesettings', 'dontconnect'): self.net_restart_needed = False elif self.comboBoxProxyType.currentText() != self._proxy_type: self.net_restart_needed = True @@ -369,8 +387,11 @@ class SettingsDialog(QtGui.QDialog): self.lineEditSocksPassword.text())) self.config.set('bitmessagesettings', 'sockslisten', str( self.checkBoxSocksListen.isChecked())) - if self.checkBoxOnionOnly.isChecked() \ - and not self.config.safeGetBoolean('bitmessagesettings', 'onionservicesonly'): + if ( + self.checkBoxOnionOnly.isChecked() + and not self.config.safeGetBoolean( + 'bitmessagesettings', 'onionservicesonly') + ): self.net_restart_needed = True self.config.set('bitmessagesettings', 'onionservicesonly', str( self.checkBoxOnionOnly.isChecked())) @@ -432,8 +453,8 @@ class SettingsDialog(QtGui.QDialog): acceptableDifficultyChanged = False if ( - float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 - or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 + float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 + or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 ): if self.config.get( 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte' @@ -449,8 +470,8 @@ class SettingsDialog(QtGui.QDialog): * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)) ) if ( - float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 - or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 + float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 + or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 ): if self.config.get( 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes' @@ -541,8 +562,8 @@ class SettingsDialog(QtGui.QDialog): self.parent.updateStartOnLogon() if ( - state.appdata != paths.lookupExeFolder() - and self.checkBoxPortableMode.isChecked() + state.appdata != paths.lookupExeFolder() + and self.checkBoxPortableMode.isChecked() ): # If we are NOT using portable mode now but the user selected # that we should... @@ -564,8 +585,8 @@ class SettingsDialog(QtGui.QDialog): pass if ( - state.appdata == paths.lookupExeFolder() - and not self.checkBoxPortableMode.isChecked() + state.appdata == paths.lookupExeFolder() + and not self.checkBoxPortableMode.isChecked() ): # If we ARE using portable mode now but the user selected # that we shouldn't... diff --git a/src/bitmessageqt/settings.ui b/src/bitmessageqt/settings.ui index 0ffbf442..1e9a6f09 100644 --- a/src/bitmessageqt/settings.ui +++ b/src/bitmessageqt/settings.ui @@ -231,7 +231,7 @@ - + Bandwidth limit @@ -322,7 +322,7 @@ - + Proxy server / Tor @@ -432,7 +432,14 @@ - + + + + Announce self by UDP + + + + Qt::Vertical diff --git a/src/bmconfigparser.py b/src/bmconfigparser.py index cd826bb4..ff43fd7c 100644 --- a/src/bmconfigparser.py +++ b/src/bmconfigparser.py @@ -19,24 +19,25 @@ BMConfigDefaults = { "maxtotalconnections": 200, "maxuploadrate": 0, "apiinterface": "127.0.0.1", - "apiport": 8442 + "apiport": 8442, + "udp": "True" }, "threads": { "receive": 3, }, "network": { - "bind": '', + "bind": "", "dandelion": 90, }, "inventory": { "storage": "sqlite", - "acceptmismatch": False, + "acceptmismatch": "False", }, "knownnodes": { "maxnodes": 20000, }, "zlib": { - 'maxsize': 1048576 + "maxsize": 1048576 } }