From 516175819301620ec72875ac7496a987120156bd Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sat, 6 Mar 2021 14:17:07 +0800 Subject: [PATCH] Expose ToS setting from libtorrent Closes #14420. --- src/base/bittorrent/session.cpp | 20 ++++++++++++++++++-- src/base/bittorrent/session.h | 3 +++ src/gui/advancedsettings.cpp | 9 +++++++++ src/gui/advancedsettings.h | 2 +- src/webui/api/appcontroller.cpp | 5 +++++ src/webui/www/private/views/preferences.html | 10 ++++++++++ 6 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 1dc672ac9..50acc0b7b 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -372,6 +372,7 @@ Session::Session(QObject *parent) , m_outgoingPortsMin(BITTORRENT_SESSION_KEY("OutgoingPortsMin"), 0) , m_outgoingPortsMax(BITTORRENT_SESSION_KEY("OutgoingPortsMax"), 0) , m_UPnPLeaseDuration(BITTORRENT_SESSION_KEY("UPnPLeaseDuration"), 0) + , m_peerToS(BITTORRENT_SESSION_KEY("PeerToS"), 0x20) , m_ignoreLimitsOnLAN(BITTORRENT_SESSION_KEY("IgnoreLimitsOnLAN"), false) , m_includeOverheadInLimits(BITTORRENT_SESSION_KEY("IncludeOverheadInLimits"), false) , m_announceIP(BITTORRENT_SESSION_KEY("AnnounceIP")) @@ -1335,9 +1336,10 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) // Outgoing ports settingsPack.set_int(lt::settings_pack::outgoing_port, outgoingPortsMin()); settingsPack.set_int(lt::settings_pack::num_outgoing_ports, outgoingPortsMax() - outgoingPortsMin() + 1); - + // UPnP lease duration settingsPack.set_int(lt::settings_pack::upnp_lease_duration, UPnPLeaseDuration()); - + // Type of service + settingsPack.set_int(lt::settings_pack::peer_tos, peerToS()); // Include overhead in transfer limits settingsPack.set_bool(lt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits()); // IP address to announce to trackers @@ -3516,6 +3518,20 @@ void Session::setUPnPLeaseDuration(const int duration) } } +int Session::peerToS() const +{ + return m_peerToS; +} + +void Session::setPeerToS(const int value) +{ + if (value == m_peerToS) + return; + + m_peerToS = value; + configureDeferred(); +} + bool Session::ignoreLimitsOnLAN() const { return m_ignoreLimitsOnLAN; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index e746925d7..1b1f7ab34 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -384,6 +384,8 @@ namespace BitTorrent void setOutgoingPortsMax(int max); int UPnPLeaseDuration() const; void setUPnPLeaseDuration(int duration); + int peerToS() const; + void setPeerToS(int value); bool ignoreLimitsOnLAN() const; void setIgnoreLimitsOnLAN(bool ignore); bool includeOverheadInLimits() const; @@ -673,6 +675,7 @@ namespace BitTorrent CachedSettingValue m_outgoingPortsMin; CachedSettingValue m_outgoingPortsMax; CachedSettingValue m_UPnPLeaseDuration; + CachedSettingValue m_peerToS; CachedSettingValue m_ignoreLimitsOnLAN; CachedSettingValue m_includeOverheadInLimits; CachedSettingValue m_announceIP; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index 85eefeb61..c975a1b02 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -115,6 +115,7 @@ namespace OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, UPNP_LEASE_DURATION, + PEER_TOS, UTP_MIX_MODE, IDN_SUPPORT, MULTI_CONNECTIONS_PER_IP, @@ -223,6 +224,8 @@ void AdvancedSettings::saveAdvancedSettings() session->setOutgoingPortsMax(m_spinBoxOutgoingPortsMax.value()); // UPnP lease duration session->setUPnPLeaseDuration(m_spinBoxUPnPLeaseDuration.value()); + // Type of service + session->setPeerToS(m_spinBoxPeerToS.value()); // uTP-TCP mixed mode session->setUtpMixedMode(static_cast(m_comboBoxUtpMixedMode.currentIndex())); // Support internationalized domain name (IDN) @@ -542,6 +545,12 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxUPnPLeaseDuration.setSuffix(tr(" s", " seconds")); addRow(UPNP_LEASE_DURATION, (tr("UPnP lease duration [0: Permanent lease]") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#upnp_lease_duration", "(?)")) , &m_spinBoxUPnPLeaseDuration); + // Type of service + m_spinBoxPeerToS.setMinimum(0); + m_spinBoxPeerToS.setMaximum(255); + m_spinBoxPeerToS.setValue(session->peerToS()); + addRow(PEER_TOS, (tr("Type of service (ToS) for connections to peers") + ' ' + makeLink("https://www.libtorrent.org/reference-Settings.html#peer_tos", "(?)")) + , &m_spinBoxPeerToS); // uTP-TCP mixed mode m_comboBoxUtpMixedMode.addItems({tr("Prefer TCP"), tr("Peer proportional (throttles TCP)")}); m_comboBoxUtpMixedMode.setCurrentIndex(static_cast(session->utpMixedMode())); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 5d3124362..428b264df 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -61,7 +61,7 @@ private: template void addRow(int row, const QString &text, T *widget); QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, - m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, + m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS, m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, m_spinBoxSendBufferWatermarkFactor, m_spinBoxSocketBacklogSize, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval; diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index c0947d562..0f82313c9 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -309,6 +309,8 @@ void AppController::preferencesAction() data["outgoing_ports_max"] = session->outgoingPortsMax(); // UPnP lease duration data["upnp_lease_duration"] = session->UPnPLeaseDuration(); + // Type of service + data["peer_tos"] = session->peerToS(); // uTP-TCP mixed mode data["utp_tcp_mixed_mode"] = static_cast(session->utpMixedMode()); // Support internationalized domain name (IDN) @@ -772,6 +774,9 @@ void AppController::setPreferencesAction() // UPnP lease duration if (hasKey("upnp_lease_duration")) session->setUPnPLeaseDuration(it.value().toInt()); + // Type of service + if (hasKey("peer_tos")) + session->setPeerToS(it.value().toInt()); // uTP-TCP mixed mode if (hasKey("utp_tcp_mixed_mode")) session->setUtpMixedMode(static_cast(it.value().toInt())); diff --git a/src/webui/www/private/views/preferences.html b/src/webui/www/private/views/preferences.html index 55068372d..3527e93b3 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -1094,6 +1094,14 @@ + + + + + + + + @@ -1920,6 +1928,7 @@ $('outgoingPortsMin').setProperty('value', pref.outgoing_ports_min); $('outgoingPortsMax').setProperty('value', pref.outgoing_ports_max); $('UPnPLeaseDuration').setProperty('value', pref.upnp_lease_duration); + $('peerToS').setProperty('value', pref.peer_tos); $('utpTCPMixedModeAlgorithm').setProperty('value', pref.utp_tcp_mixed_mode); $('IDNSupportCheckbox').setProperty('checked', pref.idn_support_enabled); $('allowMultipleConnectionsFromTheSameIPAddress').setProperty('checked', pref.enable_multi_connections_from_same_ip); @@ -2308,6 +2317,7 @@ settings.set('outgoing_ports_min', $('outgoingPortsMin').getProperty('value')); settings.set('outgoing_ports_max', $('outgoingPortsMax').getProperty('value')); settings.set('upnp_lease_duration', $('UPnPLeaseDuration').getProperty('value')); + settings.set('peer_tos', $('peerToS').getProperty('value')); settings.set('utp_tcp_mixed_mode', $('utpTCPMixedModeAlgorithm').getProperty('value')); settings.set('idn_support_enabled', $('IDNSupportCheckbox').getProperty('checked')); settings.set('enable_multi_connections_from_same_ip', $('allowMultipleConnectionsFromTheSameIPAddress').getProperty('checked'));