Apply bandwidth limits without restart

- also minor style fixes
This commit is contained in:
Peter Šurda 2018-01-01 12:49:08 +01:00
parent bcc5a210a4
commit 1864762a0a
Signed by: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 9 additions and 9 deletions

View File

@ -69,7 +69,7 @@ import queues
import shutdown import shutdown
import state import state
from statusbar import BMStatusBar from statusbar import BMStatusBar
import throttle from network.asyncore_pollchoose import set_rates
from version import softwareVersion from version import softwareVersion
import sound import sound
@ -2288,16 +2288,16 @@ class MyForm(settingsmixin.SMainWindow):
int(float(self.settingsDialogInstance.ui.lineEditMaxDownloadRate.text())))) int(float(self.settingsDialogInstance.ui.lineEditMaxDownloadRate.text()))))
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', str( BMConfigParser().set('bitmessagesettings', 'maxuploadrate', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxUploadRate.text())))) int(float(self.settingsDialogInstance.ui.lineEditMaxUploadRate.text()))))
except: except ValueError:
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."))
else:
set_rates(BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"),
BMConfigParser().safeGetInt("bitmessagesettings", "maxuploadrate"))
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', str( BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', str(
int(float(self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text())))) int(float(self.settingsDialogInstance.ui.lineEditMaxOutboundConnections.text()))))
throttle.SendThrottle().resetLimit()
throttle.ReceiveThrottle().resetLimit()
BMConfigParser().set('bitmessagesettings', 'namecoinrpctype', BMConfigParser().set('bitmessagesettings', 'namecoinrpctype',
self.settingsDialogInstance.getNamecoinType()) self.settingsDialogInstance.getNamecoinType())
BMConfigParser().set('bitmessagesettings', 'namecoinrpchost', str( BMConfigParser().set('bitmessagesettings', 'namecoinrpchost', str(

View File

@ -129,8 +129,8 @@ def write(obj):
def set_rates(download, upload): def set_rates(download, upload):
global maxDownloadRate, maxUploadRate, downloadBucket, uploadBucket, downloadTimestamp, uploadTimestamp global maxDownloadRate, maxUploadRate, downloadBucket, uploadBucket, downloadTimestamp, uploadTimestamp
maxDownloadRate = float(download) maxDownloadRate = float(download) * 1024
maxUploadRate = float(upload) maxUploadRate = float(upload) * 1024
downloadBucket = maxDownloadRate downloadBucket = maxDownloadRate
uploadBucket = maxUploadRate uploadBucket = maxUploadRate
downloadTimestamp = time.time() downloadTimestamp = time.time()

View File

@ -22,8 +22,8 @@ import state
class BMConnectionPool(object): class BMConnectionPool(object):
def __init__(self): def __init__(self):
asyncore.set_rates( asyncore.set_rates(
BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate") * 1024, BMConfigParser().safeGetInt("bitmessagesettings", "maxdownloadrate"),
BMConfigParser().safeGetInt("bitmessagesettings", "maxuploadrate") * 1024) BMConfigParser().safeGetInt("bitmessagesettings", "maxuploadrate"))
self.outboundConnections = {} self.outboundConnections = {}
self.inboundConnections = {} self.inboundConnections = {}
self.listeningSockets = {} self.listeningSockets = {}