Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions WebAPI_Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# WebAPI Changelog

## 2.16.0
* [#23065](https://github.com/qbittorrent/qBittorrent/pull/23065)
* Replace preferences key `max_connec_per_torrent` with keys `max_connec_per_downloading_torrent` and `max_connec_per_seeding_torrent`

## 2.15.0
* [#23585](https://github.com/qbittorrent/qBittorrent/pull/23585)
* `sync/maindata` endpoint no longer includes the key `use_subcategories` as subcategories are now always enabled
Expand Down
16 changes: 14 additions & 2 deletions src/app/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

namespace
{
const int MIGRATION_VERSION = 8;
const int MIGRATION_VERSION = 9;
const QString MIGRATION_VERSION_KEY = u"Meta/MigrationVersion"_s;

void exportWebUIHttpsFiles()
Expand Down Expand Up @@ -283,7 +283,6 @@ namespace
{u"BitTorrent/Session/MaxActiveTorrents"_s, u"Preferences/Queueing/MaxActiveTorrents"_s},
{u"BitTorrent/Session/MaxActiveUploads"_s, u"Preferences/Queueing/MaxActiveUploads"_s},
{u"BitTorrent/Session/MaxConnections"_s, u"Preferences/Bittorrent/MaxConnecs"_s},
{u"BitTorrent/Session/MaxConnectionsPerTorrent"_s, u"Preferences/Bittorrent/MaxConnecsPerTorrent"_s},
{u"BitTorrent/Session/MaxHalfOpenConnections"_s, u"Preferences/Connection/MaxHalfOpenConnec"_s},
{u"BitTorrent/Session/MaxRatioAction"_s, u"Preferences/Bittorrent/MaxRatioAction"_s},
{u"BitTorrent/Session/MaxUploads"_s, u"Preferences/Bittorrent/MaxUploads"_s},
Expand Down Expand Up @@ -478,6 +477,16 @@ namespace
settingsStorage->storeValue(newKey, settingsStorage->loadValue<bool>(oldKey));
settingsStorage->removeValue(oldKey);
}

void migrateMaxConnectionSetting()
{
auto *settingsStorage = SettingsStorage::instance();
const auto oldKey = u"BitTorrent/Session/MaxConnectionsPerTorrent"_s;
const auto newKey = u"BitTorrent/Session/MaxConnectionsPerDownloadingTorrent"_s;

settingsStorage->storeValue(newKey, settingsStorage->loadValue<bool>(oldKey));
settingsStorage->removeValue(oldKey);
}
}

bool upgrade()
Expand Down Expand Up @@ -522,6 +531,9 @@ bool upgrade()
if (version < 8)
migrateAddPausedSetting();

if (version < 9)
migrateMaxConnectionSetting();

version = MIGRATION_VERSION;
}

Expand Down
6 changes: 4 additions & 2 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ namespace BitTorrent
virtual void setStopTrackerTimeout(int value) = 0;
virtual int maxConnections() const = 0;
virtual void setMaxConnections(int max) = 0;
virtual int maxConnectionsPerTorrent() const = 0;
virtual void setMaxConnectionsPerTorrent(int max) = 0;
virtual int maxConnectionsPerDownloadingTorrent() const = 0;
virtual void setMaxConnectionsPerDownloadingTorrent(int max) = 0;
virtual int maxConnectionsPerSeedingTorrent() const = 0;
virtual void setMaxConnectionsPerSeedingTorrent(int max) = 0;
virtual int maxUploads() const = 0;
virtual void setMaxUploads(int max) = 0;
virtual int maxUploadsPerTorrent() const = 0;
Expand Down
48 changes: 39 additions & 9 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,8 @@ SessionImpl::SessionImpl(QObject *parent)
, m_stopTrackerTimeout(BITTORRENT_SESSION_KEY(u"StopTrackerTimeout"_s), 2)
, m_maxConnections(BITTORRENT_SESSION_KEY(u"MaxConnections"_s), 500, lowerLimited(0, -1))
, m_maxUploads(BITTORRENT_SESSION_KEY(u"MaxUploads"_s), 20, lowerLimited(0, -1))
, m_maxConnectionsPerTorrent(BITTORRENT_SESSION_KEY(u"MaxConnectionsPerTorrent"_s), 100, lowerLimited(0, -1))
, m_maxConnectionsPerDownloadingTorrent(BITTORRENT_SESSION_KEY(u"MaxConnectionsPerDownloadingTorrent"_s), 100, lowerLimited(0, -1))
, m_maxConnectionsPerSeedingTorrent(BITTORRENT_SESSION_KEY(u"MaxConnectionsPerSeedingTorrent"_s), 40, lowerLimited(0, -1))
, m_maxUploadsPerTorrent(BITTORRENT_SESSION_KEY(u"MaxUploadsPerTorrent"_s), 4, lowerLimited(0, -1))
, m_btProtocol(BITTORRENT_SESSION_KEY(u"BTProtocol"_s), BTProtocol::Both
, clampValue(BTProtocol::Both, BTProtocol::UTP))
Expand Down Expand Up @@ -2924,7 +2925,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
p.added_time = std::time(nullptr);

// Limits
p.max_connections = maxConnectionsPerTorrent();
p.max_connections = maxConnectionsPerDownloadingTorrent();
p.max_uploads = maxUploadsPerTorrent();

p.userdata = LTClientData(new ExtensionData);
Expand Down Expand Up @@ -3122,7 +3123,7 @@ bool SessionImpl::downloadMetadata(const TorrentDescriptor &torrentDescr)
p.storage_mode = lt::storage_mode_sparse;

// Limits
p.max_connections = maxConnectionsPerTorrent();
p.max_connections = maxConnectionsPerDownloadingTorrent();
p.max_uploads = maxUploadsPerTorrent();

const auto id = TorrentID::fromInfoHash(infoHash);
Expand Down Expand Up @@ -4293,23 +4294,52 @@ void SessionImpl::resume()
}
}

int SessionImpl::maxConnectionsPerTorrent() const
int SessionImpl::maxConnectionsPerDownloadingTorrent() const
{
return m_maxConnectionsPerTorrent;
return m_maxConnectionsPerDownloadingTorrent;
}

void SessionImpl::setMaxConnectionsPerTorrent(int max)
void SessionImpl::setMaxConnectionsPerDownloadingTorrent(int max)
{
max = (max > 0) ? max : -1;
if (max != maxConnectionsPerTorrent())
if (max != maxConnectionsPerDownloadingTorrent())
{
m_maxConnectionsPerTorrent = max;
m_maxConnectionsPerDownloadingTorrent = max;

for (const TorrentImpl *torrent : asConst(m_torrents))
{
try
{
torrent->nativeHandle().set_max_connections(max);
if (!torrent->isUploading())
{
torrent->nativeHandle().set_max_connections(max);
}
}
catch (const std::exception &) {}
}
}
}

int SessionImpl::maxConnectionsPerSeedingTorrent() const
{
return m_maxConnectionsPerSeedingTorrent;
}

void SessionImpl::setMaxConnectionsPerSeedingTorrent(int max)
{
max = (max > 0) ? max : -1;
if (max != maxConnectionsPerSeedingTorrent())
{
m_maxConnectionsPerSeedingTorrent = max;

for (const TorrentImpl *torrent : asConst(m_torrents))
{
try
{
if (torrent->isUploading())
{
torrent->nativeHandle().set_max_connections(max);
}
}
catch (const std::exception &) {}
}
Expand Down
9 changes: 6 additions & 3 deletions src/base/bittorrent/sessionimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ namespace BitTorrent
void setStopTrackerTimeout(int value) override;
int maxConnections() const override;
void setMaxConnections(int max) override;
int maxConnectionsPerTorrent() const override;
void setMaxConnectionsPerTorrent(int max) override;
int maxConnectionsPerDownloadingTorrent() const override;
void setMaxConnectionsPerDownloadingTorrent(int max) override;
int maxConnectionsPerSeedingTorrent() const override;
void setMaxConnectionsPerSeedingTorrent(int max) override;
int maxUploads() const override;
void setMaxUploads(int max) override;
int maxUploadsPerTorrent() const override;
Expand Down Expand Up @@ -702,7 +704,8 @@ namespace BitTorrent
CachedSettingValue<int> m_stopTrackerTimeout;
CachedSettingValue<int> m_maxConnections;
CachedSettingValue<int> m_maxUploads;
CachedSettingValue<int> m_maxConnectionsPerTorrent;
CachedSettingValue<int> m_maxConnectionsPerDownloadingTorrent;
CachedSettingValue<int> m_maxConnectionsPerSeedingTorrent;
CachedSettingValue<int> m_maxUploadsPerTorrent;
CachedSettingValue<BTProtocol> m_btProtocol;
CachedSettingValue<bool> m_isUTPRateLimited;
Expand Down
12 changes: 12 additions & 0 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2574,8 +2574,12 @@ void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus)
if (m_nativeStatus.last_seen_complete != oldStatus.last_seen_complete)
m_lastSeenComplete = QDateTime::fromSecsSinceEpoch(m_nativeStatus.last_seen_complete);

const bool wasUploading = isUploading();
updateState();

if (const bool nowUploading = isUploading(); nowUploading != wasUploading)
updateMaxConnections(nowUploading);

m_payloadRateMonitor.addSample({nativeStatus.download_payload_rate
, nativeStatus.upload_payload_rate});

Expand Down Expand Up @@ -2631,6 +2635,14 @@ void TorrentImpl::updateProgress()
}
}

void TorrentImpl::updateMaxConnections(const bool isUploading)
{
if (isUploading)
nativeHandle().set_max_connections(m_session->maxConnectionsPerSeedingTorrent());
else
nativeHandle().set_max_connections(m_session->maxConnectionsPerDownloadingTorrent());
}

void TorrentImpl::setRatioLimit(qreal limit)
{
if (limit < DEFAULT_RATIO_LIMIT)
Expand Down
1 change: 1 addition & 0 deletions src/base/bittorrent/torrentimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ namespace BitTorrent
void updateStatus(const lt::torrent_status &nativeStatus);
void updateProgress();
void updateState();
void updateMaxConnections(bool isUploading);

bool isMoveInProgress() const;

Expand Down
51 changes: 38 additions & 13 deletions src/gui/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,19 +859,32 @@ void OptionsDialog::loadConnectionTabOptions()
m_ui->checkMaxConnections->setChecked(false);
m_ui->spinMaxConnec->setEnabled(false);
}
intValue = session->maxConnectionsPerTorrent();
intValue = session->maxConnectionsPerDownloadingTorrent();
if (intValue > 0)
{
// enable
m_ui->checkMaxConnectionsPerTorrent->setChecked(true);
m_ui->spinMaxConnecPerTorrent->setEnabled(true);
m_ui->spinMaxConnecPerTorrent->setValue(intValue);
m_ui->checkMaxConnectionsPerDownloadingTorrent->setChecked(true);
m_ui->spinMaxConnecPerDownloadingTorrent->setEnabled(true);
m_ui->spinMaxConnecPerDownloadingTorrent->setValue(intValue);
}
else
{
// disable
m_ui->checkMaxConnectionsPerTorrent->setChecked(false);
m_ui->spinMaxConnecPerTorrent->setEnabled(false);
m_ui->checkMaxConnectionsPerDownloadingTorrent->setChecked(false);
m_ui->spinMaxConnecPerDownloadingTorrent->setEnabled(false);
}
intValue = session->maxConnectionsPerSeedingTorrent();
if (intValue > 0)
{
// enable
m_ui->checkMaxConnectionsPerSeedingTorrent->setChecked(true);
m_ui->spinMaxConnecPerSeedingTorrent->setValue(intValue);
}
else
{
// disable
m_ui->checkMaxConnectionsPerSeedingTorrent->setChecked(false);
m_ui->spinMaxConnecPerSeedingTorrent->setEnabled(false);
}
intValue = session->maxUploads();
if (intValue > 0)
Expand Down Expand Up @@ -949,14 +962,17 @@ void OptionsDialog::loadConnectionTabOptions()

connect(m_ui->checkMaxConnections, &QAbstractButton::toggled, m_ui->spinMaxConnec, &QWidget::setEnabled);
connect(m_ui->checkMaxConnections, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkMaxConnectionsPerTorrent, &QAbstractButton::toggled, m_ui->spinMaxConnecPerTorrent, &QWidget::setEnabled);
connect(m_ui->checkMaxConnectionsPerTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkMaxConnectionsPerDownloadingTorrent, &QAbstractButton::toggled, m_ui->spinMaxConnecPerDownloadingTorrent, &QWidget::setEnabled);
connect(m_ui->checkMaxConnectionsPerDownloadingTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkMaxConnectionsPerSeedingTorrent, &QAbstractButton::toggled, m_ui->spinMaxConnecPerSeedingTorrent, &QWidget::setEnabled);
connect(m_ui->checkMaxConnectionsPerSeedingTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkMaxUploads, &QAbstractButton::toggled, m_ui->spinMaxUploads, &QWidget::setEnabled);
connect(m_ui->checkMaxUploads, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->checkMaxUploadsPerTorrent, &QAbstractButton::toggled, m_ui->spinMaxUploadsPerTorrent, &QWidget::setEnabled);
connect(m_ui->checkMaxUploadsPerTorrent, &QAbstractButton::toggled, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxConnec, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxConnecPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxConnecPerDownloadingTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxConnecPerSeedingTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxUploads, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);
connect(m_ui->spinMaxUploadsPerTorrent, qSpinBoxValueChanged, this, &ThisType::enableApplyButton);

Expand Down Expand Up @@ -999,7 +1015,8 @@ void OptionsDialog::saveConnectionTabOptions() const
Net::PortForwarder::instance()->setEnabled(isUPnPEnabled());

session->setMaxConnections(getMaxConnections());
session->setMaxConnectionsPerTorrent(getMaxConnectionsPerTorrent());
session->setMaxConnectionsPerDownloadingTorrent(getMaxConnectionsPerDownloadingTorrent());
session->setMaxConnectionsPerSeedingTorrent(getMaxConnectionsPerSeedingTorrent());
session->setMaxUploads(getMaxUploads());
session->setMaxUploadsPerTorrent(getMaxUploadsPerTorrent());

Expand Down Expand Up @@ -1699,12 +1716,20 @@ int OptionsDialog::getMaxConnections() const
return m_ui->spinMaxConnec->value();
}

int OptionsDialog::getMaxConnectionsPerTorrent() const
int OptionsDialog::getMaxConnectionsPerDownloadingTorrent() const
{
if (!m_ui->checkMaxConnectionsPerDownloadingTorrent->isChecked())
return -1;

return m_ui->spinMaxConnecPerDownloadingTorrent->value();
}

int OptionsDialog::getMaxConnectionsPerSeedingTorrent() const
{
if (!m_ui->checkMaxConnectionsPerTorrent->isChecked())
if (!m_ui->checkMaxConnectionsPerSeedingTorrent->isChecked())
return -1;

return m_ui->spinMaxConnecPerTorrent->value();
return m_ui->spinMaxConnecPerSeedingTorrent->value();
}

int OptionsDialog::getMaxUploads() const
Expand Down
3 changes: 2 additions & 1 deletion src/gui/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ private slots:
bool isUPnPEnabled() const;
// Bittorrent options
int getMaxConnections() const;
int getMaxConnectionsPerTorrent() const;
int getMaxConnectionsPerDownloadingTorrent() const;
int getMaxConnectionsPerSeedingTorrent() const;
int getMaxUploads() const;
int getMaxUploadsPerTorrent() const;
bool isDHTEnabled() const;
Expand Down
35 changes: 29 additions & 6 deletions src/gui/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1932,17 +1932,17 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</spacer>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkMaxConnectionsPerTorrent">
<widget class="QCheckBox" name="checkMaxConnectionsPerDownloadingTorrent">
<property name="text">
<string>Maximum number of connections per torrent:</string>
<string>Maximum number of connections per downloading torrent:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinMaxConnecPerTorrent">
<widget class="QSpinBox" name="spinMaxConnecPerDownloadingTorrent">
<property name="minimum">
<number>2</number>
</property>
Expand All @@ -1955,13 +1955,36 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkMaxConnectionsPerSeedingTorrent">
<property name="text">
<string>Maximum number of connections per seeding torrent:</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinMaxConnecPerSeedingTorrent">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>2147483647</number>
</property>
<property name="value">
<number>40</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="checkMaxUploads">
<property name="text">
<string>Global maximum number of upload slots:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="spinMaxUploads">
<property name="maximum">
<number>2147483647</number>
Expand All @@ -1971,14 +1994,14 @@ readme[0-9].txt: filter 'readme1.txt', 'readme2.txt' but not 'readme10.txt'.</st
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="checkMaxUploadsPerTorrent">
<property name="text">
<string>Maximum number of upload slots per torrent:</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QSpinBox" name="spinMaxUploadsPerTorrent">
<property name="maximum">
<number>2147483647</number>
Expand Down
Loading