From 77411760a093bffafa3ae2c4f139990cd4ff55e6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 5 Apr 2023 17:33:45 +0800 Subject: [PATCH] Expose 'socket send/receive buffer size' options Closes #18794. --- src/base/bittorrent/session.h | 4 +++ src/base/bittorrent/sessionimpl.cpp | 32 ++++++++++++++++++++ src/base/bittorrent/sessionimpl.h | 6 ++++ src/gui/advancedsettings.cpp | 22 ++++++++++++++ src/gui/advancedsettings.h | 3 +- src/webui/api/appcontroller.cpp | 10 ++++++ src/webui/webapplication.h | 2 +- src/webui/www/private/views/preferences.html | 20 ++++++++++++ 8 files changed, 97 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 5dd6f7683..e0256aa00 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -328,6 +328,10 @@ namespace BitTorrent virtual void setSendBufferWatermarkFactor(int value) = 0; virtual int connectionSpeed() const = 0; virtual void setConnectionSpeed(int value) = 0; + virtual int socketSendBufferSize() const = 0; + virtual void setSocketSendBufferSize(int value) = 0; + virtual int socketReceiveBufferSize() const = 0; + virtual void setSocketReceiveBufferSize(int value) = 0; virtual int socketBacklogSize() const = 0; virtual void setSocketBacklogSize(int value) = 0; virtual bool isAnonymousModeEnabled() const = 0; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index b27716dc4..733627f79 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -436,6 +436,8 @@ SessionImpl::SessionImpl(QObject *parent) , m_sendBufferLowWatermark(BITTORRENT_SESSION_KEY(u"SendBufferLowWatermark"_qs), 10) , m_sendBufferWatermarkFactor(BITTORRENT_SESSION_KEY(u"SendBufferWatermarkFactor"_qs), 50) , m_connectionSpeed(BITTORRENT_SESSION_KEY(u"ConnectionSpeed"_qs), 30) + , m_socketSendBufferSize(BITTORRENT_SESSION_KEY(u"SocketSendBufferSize"_qs), 0) + , m_socketReceiveBufferSize(BITTORRENT_SESSION_KEY(u"SocketReceiveBufferSize"_qs), 0) , m_socketBacklogSize(BITTORRENT_SESSION_KEY(u"SocketBacklogSize"_qs), 30) , m_isAnonymousModeEnabled(BITTORRENT_SESSION_KEY(u"AnonymousModeEnabled"_qs), false) , m_isQueueingEnabled(BITTORRENT_SESSION_KEY(u"QueueingSystemEnabled"_qs), false) @@ -1599,6 +1601,8 @@ lt::settings_pack SessionImpl::loadLTSettings() const // from libtorrent doc: // It will not take affect until the listen_interfaces settings is updated + settingsPack.set_int(lt::settings_pack::send_socket_buffer_size, socketSendBufferSize()); + settingsPack.set_int(lt::settings_pack::recv_socket_buffer_size, socketReceiveBufferSize()); settingsPack.set_int(lt::settings_pack::listen_queue_size, socketBacklogSize()); applyNetworkInterfacesSettings(settingsPack); @@ -4181,6 +4185,34 @@ void SessionImpl::setConnectionSpeed(const int value) configureDeferred(); } +int SessionImpl::socketSendBufferSize() const +{ + return m_socketSendBufferSize; +} + +void SessionImpl::setSocketSendBufferSize(const int value) +{ + if (value == m_socketSendBufferSize) + return; + + m_socketSendBufferSize = value; + configureDeferred(); +} + +int SessionImpl::socketReceiveBufferSize() const +{ + return m_socketReceiveBufferSize; +} + +void SessionImpl::setSocketReceiveBufferSize(const int value) +{ + if (value == m_socketReceiveBufferSize) + return; + + m_socketReceiveBufferSize = value; + configureDeferred(); +} + int SessionImpl::socketBacklogSize() const { return m_socketBacklogSize; diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index 5a5bb6349..5ecbc33ee 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -305,6 +305,10 @@ namespace BitTorrent void setSendBufferWatermarkFactor(int value) override; int connectionSpeed() const override; void setConnectionSpeed(int value) override; + int socketSendBufferSize() const override; + void setSocketSendBufferSize(int value) override; + int socketReceiveBufferSize() const override; + void setSocketReceiveBufferSize(int value) override; int socketBacklogSize() const override; void setSocketBacklogSize(int value) override; bool isAnonymousModeEnabled() const override; @@ -601,6 +605,8 @@ namespace BitTorrent CachedSettingValue m_sendBufferLowWatermark; CachedSettingValue m_sendBufferWatermarkFactor; CachedSettingValue m_connectionSpeed; + CachedSettingValue m_socketSendBufferSize; + CachedSettingValue m_socketReceiveBufferSize; CachedSettingValue m_socketBacklogSize; CachedSettingValue m_isAnonymousModeEnabled; CachedSettingValue m_isQueueingEnabled; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index fb8618f6d..491090431 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -127,6 +127,8 @@ namespace SEND_BUF_WATERMARK_FACTOR, // networking & ports CONNECTION_SPEED, + SOCKET_SEND_BUFFER_SIZE, + SOCKET_RECEIVE_BUFFER_SIZE, SOCKET_BACKLOG_SIZE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, @@ -228,6 +230,10 @@ void AdvancedSettings::saveAdvancedSettings() const session->setSendBufferWatermarkFactor(m_spinBoxSendBufferWatermarkFactor.value()); // Outgoing connections per second session->setConnectionSpeed(m_spinBoxConnectionSpeed.value()); + // Socket send buffer size + session->setSocketSendBufferSize(m_spinBoxSocketSendBufferSize.value()); + // Socket receive buffer size + session->setSocketReceiveBufferSize(m_spinBoxSocketReceiveBufferSize.value()); // Socket listen backlog size session->setSocketBacklogSize(m_spinBoxSocketBacklogSize.value()); // Save resume data interval @@ -567,6 +573,22 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxConnectionSpeed.setValue(session->connectionSpeed()); addRow(CONNECTION_SPEED, (tr("Outgoing connections per second") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#connection_speed", u"(?)")) , &m_spinBoxConnectionSpeed); + // Socket send buffer size + m_spinBoxSocketSendBufferSize.setMinimum(0); + m_spinBoxSocketSendBufferSize.setMaximum(std::numeric_limits::max()); + m_spinBoxSocketSendBufferSize.setValue(session->socketSendBufferSize()); + m_spinBoxSocketSendBufferSize.setSuffix(tr(" Bytes")); + m_spinBoxSocketSendBufferSize.setSpecialValueText(tr("System default")); + addRow(SOCKET_SEND_BUFFER_SIZE, (tr("Socket send buffer size") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#send_socket_buffer_size", u"(?)")) + , &m_spinBoxSocketSendBufferSize); + // Socket receive buffer size + m_spinBoxSocketReceiveBufferSize.setMinimum(0); + m_spinBoxSocketReceiveBufferSize.setMaximum(std::numeric_limits::max()); + m_spinBoxSocketReceiveBufferSize.setValue(session->socketReceiveBufferSize()); + m_spinBoxSocketReceiveBufferSize.setSuffix(tr(" Bytes")); + m_spinBoxSocketReceiveBufferSize.setSpecialValueText(tr("System default")); + addRow(SOCKET_RECEIVE_BUFFER_SIZE, (tr("Socket receive buffer size") + u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#recv_socket_buffer_size", u"(?)")) + , &m_spinBoxSocketReceiveBufferSize); // Socket listen backlog size m_spinBoxSocketBacklogSize.setMinimum(1); m_spinBoxSocketBacklogSize.setMaximum(std::numeric_limits::max()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 79e3146b2..dee557f90 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -64,7 +64,8 @@ private: QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize, m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS, m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, - m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketBacklogSize, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, + m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketSendBufferSize, m_spinBoxSocketReceiveBufferSize, m_spinBoxSocketBacklogSize, + m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize; QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts, m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus, diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 889689876..b44e48c25 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -363,6 +363,10 @@ void AppController::preferencesAction() data[u"send_buffer_watermark_factor"_qs] = session->sendBufferWatermarkFactor(); // Outgoing connections per second data[u"connection_speed"_qs] = session->connectionSpeed(); + // Socket send buffer size + data[u"socket_send_buffer_size"_qs] = session->socketSendBufferSize(); + // Socket receive buffer size + data[u"socket_receive_buffer_size"_qs] = session->socketReceiveBufferSize(); // Socket listen backlog size data[u"socket_backlog_size"_qs] = session->socketBacklogSize(); // Outgoing ports @@ -908,6 +912,12 @@ void AppController::setPreferencesAction() // Outgoing connections per second if (hasKey(u"connection_speed"_qs)) session->setConnectionSpeed(it.value().toInt()); + // Socket send buffer size + if (hasKey(u"socket_send_buffer_size"_qs)) + session->setSocketSendBufferSize(it.value().toInt()); + // Socket receive buffer size + if (hasKey(u"socket_receive_buffer_size"_qs)) + session->setSocketReceiveBufferSize(it.value().toInt()); // Socket listen backlog size if (hasKey(u"socket_backlog_size"_qs)) session->setSocketBacklogSize(it.value().toInt()); diff --git a/src/webui/webapplication.h b/src/webui/webapplication.h index 79e0740f9..cb7e62f89 100644 --- a/src/webui/webapplication.h +++ b/src/webui/webapplication.h @@ -52,7 +52,7 @@ #include "base/utils/version.h" #include "api/isessionmanager.h" -inline const Utils::Version<3, 2> API_VERSION {2, 9, 0}; +inline const Utils::Version<3, 2> API_VERSION {2, 9, 1}; class APIController; class AuthController; diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index b9e789224..5cf1101e4 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1180,6 +1180,22 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD + + + + + +   QBT_TR(Bytes)QBT_TR[CONTEXT=OptionsDialog] + + + + + + + +   QBT_TR(Bytes)QBT_TR[CONTEXT=OptionsDialog] + + @@ -2140,6 +2156,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD $('sendBufferLowWatermark').setProperty('value', pref.send_buffer_low_watermark); $('sendBufferWatermarkFactor').setProperty('value', pref.send_buffer_watermark_factor); $('connectionSpeed').setProperty('value', pref.connection_speed); + $('socketSendBufferSize').setProperty('value', pref.socket_send_buffer_size); + $('socketReceiveBufferSize').setProperty('value', pref.socket_receive_buffer_size); $('socketBacklogSize').setProperty('value', pref.socket_backlog_size); $('outgoingPortsMin').setProperty('value', pref.outgoing_ports_min); $('outgoingPortsMax').setProperty('value', pref.outgoing_ports_max); @@ -2554,6 +2572,8 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD settings.set('send_buffer_low_watermark', $('sendBufferLowWatermark').getProperty('value')); settings.set('send_buffer_watermark_factor', $('sendBufferWatermarkFactor').getProperty('value')); settings.set('connection_speed', $('connectionSpeed').getProperty('value')); + settings.set('socket_send_buffer_size', $('socketSendBufferSize').getProperty('value')); + settings.set('socket_receive_buffer_size', $('socketReceiveBufferSize').getProperty('value')); settings.set('socket_backlog_size', $('socketBacklogSize').getProperty('value')); settings.set('outgoing_ports_min', $('outgoingPortsMin').getProperty('value')); settings.set('outgoing_ports_max', $('outgoingPortsMax').getProperty('value'));