Browse Source

Add comboBox for selecting BitTorrent protocol. Closes #6316.

Use unicode string C_UTP in place of "uTP"
adaptive-webui-19844
Chocobo1 7 years ago
parent
commit
45a0c5558a
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 70
      src/base/bittorrent/session.cpp
  2. 15
      src/base/bittorrent/session.h
  3. 3
      src/gui/advancedsettings.cpp
  4. 8
      src/gui/optionsdlg.cpp
  5. 74
      src/gui/optionsdlg.ui
  6. 6
      src/webui/prefjson.cpp
  7. 21
      src/webui/www/public/preferences_content.html

70
src/base/bittorrent/session.cpp

@ -299,7 +299,8 @@ Session::Session(QObject *parent) @@ -299,7 +299,8 @@ Session::Session(QObject *parent)
, m_maxUploads(BITTORRENT_SESSION_KEY("MaxUploads"), -1, lowerLimited(0, -1))
, m_maxConnectionsPerTorrent(BITTORRENT_SESSION_KEY("MaxConnectionsPerTorrent"), 100, lowerLimited(0, -1))
, m_maxUploadsPerTorrent(BITTORRENT_SESSION_KEY("MaxUploadsPerTorrent"), -1, lowerLimited(0, -1))
, m_isUTPEnabled(BITTORRENT_SESSION_KEY("uTPEnabled"), true)
, m_btProtocol(BITTORRENT_SESSION_KEY("BTProtocol"), BTProtocol::Both
, clampValue(BTProtocol::Both, BTProtocol::UTP))
, m_isUTPRateLimited(BITTORRENT_SESSION_KEY("uTPRateLimited"), true)
, m_utpMixedMode(BITTORRENT_SESSION_KEY("uTPMixedMode"), MixedModeAlgorithm::Proportional
, clampValue(MixedModeAlgorithm::TCP, MixedModeAlgorithm::Proportional))
@ -1342,8 +1343,30 @@ void Session::configure(libtorrent::settings_pack &settingsPack) @@ -1342,8 +1343,30 @@ void Session::configure(libtorrent::settings_pack &settingsPack)
// * Global max upload slots
settingsPack.set_int(libt::settings_pack::unchoke_slots_limit, maxUploads());
// uTP
settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, isUTPEnabled());
settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, isUTPEnabled());
switch (btProtocol()) {
case BTProtocol::Both:
default:
settingsPack.set_bool(libt::settings_pack::enable_incoming_tcp, true);
settingsPack.set_bool(libt::settings_pack::enable_outgoing_tcp, true);
settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, true);
settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, true);
break;
case BTProtocol::TCP:
settingsPack.set_bool(libt::settings_pack::enable_incoming_tcp, true);
settingsPack.set_bool(libt::settings_pack::enable_outgoing_tcp, true);
settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, false);
settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, false);
break;
case BTProtocol::UTP:
settingsPack.set_bool(libt::settings_pack::enable_incoming_tcp, false);
settingsPack.set_bool(libt::settings_pack::enable_outgoing_tcp, false);
settingsPack.set_bool(libt::settings_pack::enable_incoming_utp, true);
settingsPack.set_bool(libt::settings_pack::enable_outgoing_utp, true);
break;
}
switch (utpMixedMode()) {
case MixedModeAlgorithm::TCP:
default:
@ -1604,8 +1627,30 @@ void Session::configure(libtorrent::session_settings &sessionSettings) @@ -1604,8 +1627,30 @@ void Session::configure(libtorrent::session_settings &sessionSettings)
// * Global max upload slots
sessionSettings.unchoke_slots_limit = maxUploads();
// uTP
sessionSettings.enable_incoming_utp = isUTPEnabled();
sessionSettings.enable_outgoing_utp = isUTPEnabled();
switch (btProtocol()) {
case BTProtocol::Both:
default:
sessionSettings.enable_incoming_tcp = true;
sessionSettings.enable_outgoing_tcp = true;
sessionSettings.enable_incoming_utp = true;
sessionSettings.enable_outgoing_utp = true;
break;
case BTProtocol::TCP:
sessionSettings.enable_incoming_tcp = true;
sessionSettings.enable_outgoing_tcp = true;
sessionSettings.enable_incoming_utp = false;
sessionSettings.enable_outgoing_utp = false;
break;
case BTProtocol::UTP:
sessionSettings.enable_incoming_tcp = false;
sessionSettings.enable_outgoing_tcp = false;
sessionSettings.enable_incoming_utp = true;
sessionSettings.enable_outgoing_utp = true;
break;
}
// uTP rate limiting
sessionSettings.rate_limit_utp = isUTPRateLimited();
switch (utpMixedMode()) {
@ -3246,18 +3291,21 @@ void Session::setMaxUploads(int max) @@ -3246,18 +3291,21 @@ void Session::setMaxUploads(int max)
}
}
bool Session::isUTPEnabled() const
BTProtocol Session::btProtocol() const
{
return m_isUTPEnabled;
return m_btProtocol;
}
void Session::setUTPEnabled(bool enabled)
void Session::setBTProtocol(BTProtocol protocol)
{
if (enabled != m_isUTPEnabled) {
m_isUTPEnabled = enabled;
if ((protocol < BTProtocol::Both) || (BTProtocol::UTP < protocol))
return;
if (protocol == m_btProtocol) return;
m_btProtocol = protocol;
configureDeferred();
}
}
bool Session::isUTPRateLimited() const
{

15
src/base/bittorrent/session.h

@ -178,10 +178,19 @@ namespace BitTorrent @@ -178,10 +178,19 @@ namespace BitTorrent
Proportional = 1
};
Q_ENUM(MixedModeAlgorithm)
enum class BTProtocol : int
{
Both = 0,
TCP = 1,
UTP = 2
};
Q_ENUM(BTProtocol)
};
using ChokingAlgorithm = SessionSettingsEnums::ChokingAlgorithm;
using SeedChokingAlgorithm = SessionSettingsEnums::SeedChokingAlgorithm;
using MixedModeAlgorithm = SessionSettingsEnums::MixedModeAlgorithm;
using BTProtocol = SessionSettingsEnums::BTProtocol;
#if LIBTORRENT_VERSION_NUM >= 10100
struct SessionMetricIndices
@ -413,8 +422,8 @@ namespace BitTorrent @@ -413,8 +422,8 @@ namespace BitTorrent
void setMaxActiveUploads(int max);
int maxActiveTorrents() const;
void setMaxActiveTorrents(int max);
bool isUTPEnabled() const;
void setUTPEnabled(bool enabled);
BTProtocol btProtocol() const;
void setBTProtocol(BTProtocol protocol);
bool isUTPRateLimited() const;
void setUTPRateLimited(bool limited);
MixedModeAlgorithm utpMixedMode() const;
@ -648,7 +657,7 @@ namespace BitTorrent @@ -648,7 +657,7 @@ namespace BitTorrent
CachedSettingValue<int> m_maxUploads;
CachedSettingValue<int> m_maxConnectionsPerTorrent;
CachedSettingValue<int> m_maxUploadsPerTorrent;
CachedSettingValue<bool> m_isUTPEnabled;
CachedSettingValue<BTProtocol> m_btProtocol;
CachedSettingValue<bool> m_isUTPRateLimited;
CachedSettingValue<MixedModeAlgorithm> m_utpMixedMode;
CachedSettingValue<bool> m_multiConnectionsPerIpEnabled;

3
src/gui/advancedsettings.cpp

@ -36,6 +36,7 @@ @@ -36,6 +36,7 @@
#include "app/application.h"
#include "base/bittorrent/session.h"
#include "base/preferences.h"
#include "base/unicodestrings.h"
#include "gui/mainwindow.h"
enum AdvSettingsCols
@ -345,7 +346,7 @@ void AdvancedSettings::loadAdvancedSettings() @@ -345,7 +346,7 @@ void AdvancedSettings::loadAdvancedSettings()
// uTP-TCP mixed mode
comboUtpMixedMode.addItems({"Prefer TCP", "Peer proportional (throttles TCP)"});
comboUtpMixedMode.setCurrentIndex(static_cast<int>(session->utpMixedMode()));
addRow(UTP_MIX_MODE, tr("uTP-TCP mixed mode algorithm"), &comboUtpMixedMode);
addRow(UTP_MIX_MODE, tr("%1-TCP mixed mode algorithm", "uTP-TCP mixed mode algorithm").arg(C_UTP), &comboUtpMixedMode);
// multiple connections per IP
cbMultiConnectionsPerIp.setChecked(session->multiConnectionsPerIpEnabled());
addRow(MULTI_CONNECTIONS_PER_IP, tr("Allow multiple connections from the same IP address"), &cbMultiConnectionsPerIp);

8
src/gui/optionsdlg.cpp

@ -272,6 +272,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -272,6 +272,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
m_ui->autoRun_param->setText(autoRunStr);
// Connection tab
connect(m_ui->comboProtocol, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinPort, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkRandomPort, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkUPnP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
@ -287,8 +288,6 @@ OptionsDialog::OptionsDialog(QWidget *parent) @@ -287,8 +288,6 @@ OptionsDialog::OptionsDialog(QWidget *parent)
connect(m_ui->schedule_from, &QDateTimeEdit::timeChanged, this, &ThisType::enableApplyButton);
connect(m_ui->schedule_to, &QDateTimeEdit::timeChanged, this, &ThisType::enableApplyButton);
connect(m_ui->schedule_days, qComboBoxCurrentIndexChanged, this, &ThisType::enableApplyButton);
connect(m_ui->checkuTP, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkuTP, &QAbstractButton::toggled, m_ui->checkLimituTPConnections, &QWidget::setEnabled);
connect(m_ui->checkLimituTPConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkLimitTransportOverhead, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkLimitLocalPeerRate, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
@ -573,13 +572,13 @@ void OptionsDialog::saveOptions() @@ -573,13 +572,13 @@ void OptionsDialog::saveOptions()
// End Downloads preferences
// Connection preferences
session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m_ui->comboProtocol->currentIndex()));
session->setPort(getPort());
session->setUseRandomPort(m_ui->checkRandomPort->isChecked());
Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());
const QPair<int, int> down_up_limit = getGlobalBandwidthLimits();
session->setGlobalDownloadSpeedLimit(down_up_limit.first);
session->setGlobalUploadSpeedLimit(down_up_limit.second);
session->setUTPEnabled(m_ui->checkuTP->isChecked());
session->setUTPRateLimited(m_ui->checkLimituTPConnections->isChecked());
session->setIncludeOverheadInLimits(m_ui->checkLimitTransportOverhead->isChecked());
session->setIgnoreLimitsOnLAN(!m_ui->checkLimitLocalPeerRate->isChecked());
@ -824,6 +823,7 @@ void OptionsDialog::loadOptions() @@ -824,6 +823,7 @@ void OptionsDialog::loadOptions()
// End Downloads preferences
// Connection preferences
m_ui->comboProtocol->setCurrentIndex(static_cast<int>(session->btProtocol()));
m_ui->checkUPnP->setChecked(Net::PortForwarder::instance()->isEnabled());
m_ui->checkRandomPort->setChecked(session->useRandomPort());
m_ui->spinPort->setValue(session->port());
@ -973,8 +973,6 @@ void OptionsDialog::loadOptions() @@ -973,8 +973,6 @@ void OptionsDialog::loadOptions()
m_ui->spinUploadLimitAlt->setEnabled(false);
}
m_ui->checkuTP->setChecked(session->isUTPEnabled());
m_ui->checkLimituTPConnections->setEnabled(m_ui->checkuTP->isChecked());
m_ui->checkLimituTPConnections->setChecked(session->isUTPRateLimited());
m_ui->checkLimitTransportOverhead->setChecked(session->includeOverheadInLimits());
m_ui->checkLimitLocalPeerRate->setChecked(!session->ignoreLimitsOnLAN());

74
src/gui/optionsdlg.ui

@ -1250,6 +1250,42 @@ @@ -1250,6 +1250,42 @@
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_20">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="label_24">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enabled protocol:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboProtocol">
<item>
<property name="text">
<string>TCP and μTP</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">TCP</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">μTP</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="ListeningPortBox">
<property name="title">
@ -2011,48 +2047,28 @@ @@ -2011,48 +2047,28 @@
<property name="title">
<string>Rate Limits Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="checkLimitLocalPeerRate">
<layout class="QVBoxLayout" name="verticalLayout_30">
<item>
<widget class="QCheckBox" name="checkLimituTPConnections">
<property name="text">
<string>Apply rate limit to peers on LAN</string>
<string>Apply rate limit to µTP protocol</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<item>
<widget class="QCheckBox" name="checkLimitTransportOverhead">
<property name="text">
<string>Apply rate limit to transport overhead</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QCheckBox" name="checkuTP">
<property name="text">
<string>Enable µTP protocol</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkLimituTPConnections">
<item>
<widget class="QCheckBox" name="checkLimitLocalPeerRate">
<property name="text">
<string>Apply rate limit to µTP protocol</string>
<string>Apply rate limit to peers on LAN</string>
</property>
</widget>
</item>
<item row="2" column="2">
<spacer name="horizontalSpacer_9">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -3239,8 +3255,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string> @@ -3239,8 +3255,6 @@ Use ';' to split multiple entries. Can use wildcard '*'.</string>
<tabstop>spinDownloadLimitAlt</tabstop>
<tabstop>checkLimitLocalPeerRate</tabstop>
<tabstop>checkLimitTransportOverhead</tabstop>
<tabstop>checkuTP</tabstop>
<tabstop>checkLimituTPConnections</tabstop>
<tabstop>scrollArea_4</tabstop>
<tabstop>checkDHT</tabstop>
<tabstop>checkPeX</tabstop>

6
src/webui/prefjson.cpp

@ -120,7 +120,7 @@ QByteArray prefjson::getPreferences() @@ -120,7 +120,7 @@ QByteArray prefjson::getPreferences()
// Global Rate Limits
data["dl_limit"] = session->globalDownloadSpeedLimit();
data["up_limit"] = session->globalUploadSpeedLimit();
data["enable_utp"] = session->isUTPEnabled();
data["bittorrent_protocol"] = static_cast<int>(session->btProtocol());
data["limit_utp_rate"] = session->isUTPRateLimited();
data["limit_tcp_overhead"] = session->includeOverheadInLimits();
data["alt_dl_limit"] = session->altGlobalDownloadSpeedLimit();
@ -322,8 +322,8 @@ void prefjson::setPreferences(const QString& json) @@ -322,8 +322,8 @@ void prefjson::setPreferences(const QString& json)
session->setGlobalDownloadSpeedLimit(m["dl_limit"].toInt());
if (m.contains("up_limit"))
session->setGlobalUploadSpeedLimit(m["up_limit"].toInt());
if (m.contains("enable_utp"))
session->setUTPEnabled(m["enable_utp"].toBool());
if (m.contains("bittorrent_protocol"))
session->setBTProtocol(static_cast<BitTorrent::BTProtocol>(m["bittorrent_protocol"].toInt()));
if (m.contains("limit_utp_rate"))
session->setUTPRateLimited(m["limit_utp_rate"].toBool());
if (m.contains("limit_tcp_overhead"))

21
src/webui/www/public/preferences_content.html

@ -88,6 +88,12 @@ @@ -88,6 +88,12 @@
</div>
<div id="ConnectionTab" class="PrefTab invisible">
<label>QBT_TR(Enabled protocol:)QBT_TR[CONTEXT=OptionsDialog]</label>
<select id="enable_protocol_combobox">
<option value="0" selected>QBT_TR(TCP and μTP)QBT_TR[CONTEXT=OptionsDialog]</option>
<option value="1">TCP</option>
<option value="2">μTP</option>
</select><br/>
<fieldset class="settings">
<legend>QBT_TR(Listening Port)QBT_TR[CONTEXT=OptionsDialog]</legend>
<label for="port_value">QBT_TR(Port used for incoming connections:)QBT_TR[CONTEXT=OptionsDialog]</label>
@ -256,8 +262,6 @@ @@ -256,8 +262,6 @@
<fieldset class="settings">
<legend>QBT_TR(Rate Limits Settings)QBT_TR[CONTEXT=OptionsDialog]</legend>
<input type="checkbox" id="enable_utp_checkbox" onClick="updateUTPEnabled();"/>
<label for="enable_utp_checkbox">QBT_TR(Enable µTP protocol)QBT_TR[CONTEXT=OptionsDialog]</label><br/>
<input type="checkbox" id="limit_utp_rate_checkbox"/>
<label for="limit_utp_rate_checkbox">QBT_TR(Apply rate limit to µTP protocol)QBT_TR[CONTEXT=OptionsDialog]</label><br/>
<input type="checkbox" id="limit_tcp_overhead_checkbox"/>
@ -692,14 +696,6 @@ updateDlLimitEnabled = function() { @@ -692,14 +696,6 @@ updateDlLimitEnabled = function() {
}
}
updateUTPEnabled = function() {
if($('enable_utp_checkbox').getProperty('checked')) {
$('limit_utp_rate_checkbox').setProperty('disabled', false);
} else {
$('limit_utp_rate_checkbox').setProperty('disabled', true);
}
}
updateAltUpLimitEnabled = function() {
if($('alt_up_limit_checkbox').getProperty('checked')) {
$('alt_up_limit_value').setProperty('disabled', false);
@ -974,10 +970,9 @@ loadPreferences = function() { @@ -974,10 +970,9 @@ loadPreferences = function() {
$('dl_limit_value').setProperty('value', dl_limit);
}
updateDlLimitEnabled();
$('enable_utp_checkbox').setProperty('checked', pref.enable_utp);
$('enable_protocol_combobox').setProperty('value', pref.bittorrent_protocol);
$('limit_utp_rate_checkbox').setProperty('checked', pref.limit_utp_rate);
$('limit_tcp_overhead_checkbox').setProperty('checked', pref.limit_tcp_overhead);
updateUTPEnabled();
// Alternative Global Rate Limits
var alt_up_limit = pref.alt_up_limit.toInt() / 1024;
@ -1217,7 +1212,7 @@ applyPreferences = function() { @@ -1217,7 +1212,7 @@ applyPreferences = function() {
}
}
settings.set('dl_limit', dl_limit);
settings.set('enable_utp', $('enable_utp_checkbox').getProperty('checked'));
settings.set('bittorrent_protocol', $('enable_protocol_combobox').getProperty('value'));
settings.set('limit_utp_rate', $('limit_utp_rate_checkbox').getProperty('checked'));
settings.set('limit_tcp_overhead', $('limit_tcp_overhead_checkbox').getProperty('checked'));

Loading…
Cancel
Save