setting, openssl and bmproto quality fixes

This commit is contained in:
lakshya 2020-05-18 21:30:13 +05:30
parent c69decaab3
commit 3f773c78f7
No known key found for this signature in database
GPG Key ID: 7D81A5565D14CB2B
3 changed files with 35 additions and 31 deletions

View File

@ -1,3 +1,6 @@
"""
This module setting file is for settings
"""
import ConfigParser import ConfigParser
import os import os
import sys import sys
@ -110,7 +113,7 @@ class SettingsDialog(QtGui.QDialog):
tempfile.NamedTemporaryFile( tempfile.NamedTemporaryFile(
dir=paths.lookupExeFolder(), delete=True dir=paths.lookupExeFolder(), delete=True
).close() # should autodelete ).close() # should autodelete
except: except Exception:
self.checkBoxPortableMode.setDisabled(True) self.checkBoxPortableMode.setDisabled(True)
if 'darwin' in sys.platform: if 'darwin' in sys.platform:
@ -407,14 +410,14 @@ class SettingsDialog(QtGui.QDialog):
self.config.set( self.config.set(
'bitmessagesettings', 'defaultnoncetrialsperbyte', 'bitmessagesettings', 'defaultnoncetrialsperbyte',
str(int( str(int(
float(self.lineEditTotalDifficulty.text()) * float(self.lineEditTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte))) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)))
if float(self.lineEditSmallMessageDifficulty.text()) >= 1: if float(self.lineEditSmallMessageDifficulty.text()) >= 1:
self.config.set( self.config.set(
'bitmessagesettings', 'defaultpayloadlengthextrabytes', 'bitmessagesettings', 'defaultpayloadlengthextrabytes',
str(int( str(int(
float(self.lineEditSmallMessageDifficulty.text()) * float(self.lineEditSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes))) * defaults.networkDefaultPayloadLengthExtraBytes)))
if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet( if self.comboBoxOpenCL.currentText().toUtf8() != self.config.safeGet(
'bitmessagesettings', 'opencl'): 'bitmessagesettings', 'opencl'):
@ -426,40 +429,40 @@ class SettingsDialog(QtGui.QDialog):
acceptableDifficultyChanged = False acceptableDifficultyChanged = False
if ( if (
float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1 or float(self.lineEditMaxAcceptableTotalDifficulty.text()) >= 1
float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0 or float(self.lineEditMaxAcceptableTotalDifficulty.text()) == 0
): ):
if self.config.get( if self.config.get(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte' 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte'
) != str(int( ) != str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) * float(self.lineEditMaxAcceptableTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte)
): ):
# the user changed the max acceptable total difficulty # the user changed the max acceptable total difficulty
acceptableDifficultyChanged = True acceptableDifficultyChanged = True
self.config.set( self.config.set(
'bitmessagesettings', 'maxacceptablenoncetrialsperbyte', 'bitmessagesettings', 'maxacceptablenoncetrialsperbyte',
str(int( str(int(
float(self.lineEditMaxAcceptableTotalDifficulty.text()) * float(self.lineEditMaxAcceptableTotalDifficulty.text())
defaults.networkDefaultProofOfWorkNonceTrialsPerByte)) * defaults.networkDefaultProofOfWorkNonceTrialsPerByte))
) )
if ( if (
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1 or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) >= 1
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0 or float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) == 0
): ):
if self.config.get( if self.config.get(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes' 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes'
) != str(int( ) != str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes) * defaults.networkDefaultPayloadLengthExtraBytes)
): ):
# the user changed the max acceptable small message difficulty # the user changed the max acceptable small message difficulty
acceptableDifficultyChanged = True acceptableDifficultyChanged = True
self.config.set( self.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', 'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes',
str(int( str(int(
float(self.lineEditMaxAcceptableSmallMessageDifficulty.text()) * float(self.lineEditMaxAcceptableSmallMessageDifficulty.text())
defaults.networkDefaultPayloadLengthExtraBytes)) * defaults.networkDefaultPayloadLengthExtraBytes))
) )
if acceptableDifficultyChanged: if acceptableDifficultyChanged:
# It might now be possible to send msgs which were previously # It might now be possible to send msgs which were previously
@ -537,8 +540,8 @@ class SettingsDialog(QtGui.QDialog):
self.parent.updateStartOnLogon() self.parent.updateStartOnLogon()
if ( if (
state.appdata != paths.lookupExeFolder() and state.appdata != paths.lookupExeFolder()
self.checkBoxPortableMode.isChecked() and self.checkBoxPortableMode.isChecked()
): ):
# If we are NOT using portable mode now but the user selected # If we are NOT using portable mode now but the user selected
# that we should... # that we should...
@ -556,12 +559,12 @@ class SettingsDialog(QtGui.QDialog):
try: try:
os.remove(previousAppdataLocation + 'debug.log') os.remove(previousAppdataLocation + 'debug.log')
os.remove(previousAppdataLocation + 'debug.log.1') os.remove(previousAppdataLocation + 'debug.log.1')
except: except Exception:
pass pass
if ( if (
state.appdata == paths.lookupExeFolder() and state.appdata == paths.lookupExeFolder()
not self.checkBoxPortableMode.isChecked() and not self.checkBoxPortableMode.isChecked()
): ):
# If we ARE using portable mode now but the user selected # If we ARE using portable mode now but the user selected
# that we shouldn't... # that we shouldn't...
@ -579,5 +582,5 @@ class SettingsDialog(QtGui.QDialog):
try: try:
os.remove(paths.lookupExeFolder() + 'debug.log') os.remove(paths.lookupExeFolder() + 'debug.log')
os.remove(paths.lookupExeFolder() + 'debug.log.1') os.remove(paths.lookupExeFolder() + 'debug.log.1')
except: except Exception:
pass pass

View File

@ -441,9 +441,10 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
if stream not in state.streamsInWhichIAmParticipating: if stream not in state.streamsInWhichIAmParticipating:
continue continue
if ( if (
decodedIP and time.time() - seenTime > 0 and decodedIP
seenTime > time.time() - ADDRESS_ALIVE and and time.time() - seenTime > 0
port > 0 and seenTime > time.time() - ADDRESS_ALIVE
and port > 0
): ):
peer = Peer(decodedIP, port) peer = Peer(decodedIP, port)
try: try:
@ -541,8 +542,8 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
logger.debug( logger.debug(
'%(host)s:%(port)i sending version', '%(host)s:%(port)i sending version',
self.destination._asdict()) self.destination._asdict())
if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL) and if ((self.services & protocol.NODE_SSL == protocol.NODE_SSL)
protocol.haveSSL(not self.isOutbound)): and protocol.haveSSL(not self.isOutbound)):
self.isSSL = True self.isSSL = True
if not self.verackReceived: if not self.verackReceived:
return True return True
@ -600,7 +601,7 @@ class BMProto(AdvancedDispatcher, ObjectTracker):
'Closed connection to %s because we are already' 'Closed connection to %s because we are already'
' connected to that IP.', self.destination) ' connected to that IP.', self.destination)
return False return False
except: except Exception:
pass pass
if not self.isOutbound: if not self.isOutbound:
# incoming from a peer we're connected to as outbound, # incoming from a peer we're connected to as outbound,

View File

@ -453,7 +453,7 @@ class _OpenSSL(object):
try: try:
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC
except: except Exception:
# The above is not compatible with all versions of OSX. # The above is not compatible with all versions of OSX.
self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1 self.PKCS5_PBKDF2_HMAC = self._lib.PKCS5_PBKDF2_HMAC_SHA1
@ -794,7 +794,7 @@ def loadOpenSSL():
try: try:
OpenSSL = _OpenSSL(library) OpenSSL = _OpenSSL(library)
return return
except: except Exception:
pass pass
raise Exception( raise Exception(
"Couldn't find and load the OpenSSL library. You must install it.") "Couldn't find and load the OpenSSL library. You must install it.")