This commit is contained in:
Sam Vervaeck 2025-07-03 07:42:42 +02:00 committed by GitHub
commit 3dd8f599ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 38 additions and 1 deletions

View file

@ -379,6 +379,8 @@ namespace BitTorrent
virtual void setUploadRateForSlowTorrents(int rateInKibiBytes) = 0;
virtual int slowTorrentsInactivityTimer() const = 0;
virtual void setSlowTorrentsInactivityTimer(int timeInSeconds) = 0;
virtual QString NATPMPGateway() const = 0;
virtual void setNATPMPGateway(const QString& gateway) = 0;
virtual int outgoingPortsMin() const = 0;
virtual void setOutgoingPortsMin(int min) = 0;
virtual int outgoingPortsMax() const = 0;

View file

@ -483,6 +483,7 @@ SessionImpl::SessionImpl(QObject *parent)
, m_slowTorrentsInactivityTimer(BITTORRENT_SESSION_KEY(u"SlowTorrentsInactivityTimer"_s), 60)
, m_outgoingPortsMin(BITTORRENT_SESSION_KEY(u"OutgoingPortsMin"_s), 0)
, m_outgoingPortsMax(BITTORRENT_SESSION_KEY(u"OutgoingPortsMax"_s), 0)
, m_NATPMPGateway(BITTORRENT_SESSION_KEY(u"NATPMPGateway"_s))
, m_UPnPLeaseDuration(BITTORRENT_SESSION_KEY(u"UPnPLeaseDuration"_s), 0)
, m_peerToS(BITTORRENT_SESSION_KEY(u"PeerToS"_s), 0x04)
, m_ignoreLimitsOnLAN(BITTORRENT_SESSION_KEY(u"IgnoreLimitsOnLAN"_s), false)
@ -2054,6 +2055,8 @@ lt::settings_pack SessionImpl::loadLTSettings() const
// Outgoing ports
settingsPack.set_int(lt::settings_pack::outgoing_port, outgoingPortsMin());
settingsPack.set_int(lt::settings_pack::num_outgoing_ports, (outgoingPortsMax() - outgoingPortsMin()));
// NAT-PMP gateway
settingsPack.set_str(lt::settings_pack::nat_pmp_gateway, NATPMPGateway().toStdString());
// UPnP lease duration
settingsPack.set_int(lt::settings_pack::upnp_lease_duration, UPnPLeaseDuration());
// Type of service
@ -4932,6 +4935,18 @@ void SessionImpl::setOutgoingPortsMax(const int max)
}
}
QString SessionImpl::NATPMPGateway() const {
return m_NATPMPGateway;
}
void SessionImpl::setNATPMPGateway(const QString& gateway) {
if (gateway != m_NATPMPGateway)
{
m_NATPMPGateway = gateway;
configureDeferred();
}
}
int SessionImpl::UPnPLeaseDuration() const
{
return m_UPnPLeaseDuration;

View file

@ -357,6 +357,8 @@ namespace BitTorrent
void setOutgoingPortsMin(int min) override;
int outgoingPortsMax() const override;
void setOutgoingPortsMax(int max) override;
QString NATPMPGateway() const override;
void setNATPMPGateway(const QString &gateway) override;
int UPnPLeaseDuration() const override;
void setUPnPLeaseDuration(int duration) override;
int peerToS() const override;
@ -687,6 +689,7 @@ namespace BitTorrent
CachedSettingValue<int> m_slowTorrentsInactivityTimer;
CachedSettingValue<int> m_outgoingPortsMin;
CachedSettingValue<int> m_outgoingPortsMax;
CachedSettingValue<QString> m_NATPMPGateway;
CachedSettingValue<int> m_UPnPLeaseDuration;
CachedSettingValue<int> m_peerToS;
CachedSettingValue<bool> m_ignoreLimitsOnLAN;

View file

@ -35,6 +35,7 @@
#include <QHostAddress>
#include <QLabel>
#include <QNetworkInterface>
#include <memory>
#include "base/bittorrent/session.h"
#include "base/global.h"
@ -148,6 +149,7 @@ namespace
SOCKET_BACKLOG_SIZE,
OUTGOING_PORT_MIN,
OUTGOING_PORT_MAX,
NATPMP_GATEWAY,
UPNP_LEASE_DURATION,
PEER_TOS,
UTP_MIX_MODE,
@ -273,6 +275,8 @@ void AdvancedSettings::saveAdvancedSettings() const
// Outgoing ports
session->setOutgoingPortsMin(m_spinBoxOutgoingPortsMin.value());
session->setOutgoingPortsMax(m_spinBoxOutgoingPortsMax.value());
// NAT-PMP gateway
session->setNATPMPGateway(m_lineEditNATPMPGateway.text());
// UPnP lease duration
session->setUPnPLeaseDuration(m_spinBoxUPnPLeaseDuration.value());
// Type of service
@ -714,6 +718,11 @@ void AdvancedSettings::loadAdvancedSettings()
addRow(OUTGOING_PORT_MAX, (tr("Outgoing ports (Max) [0: disabled]")
+ u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#outgoing_port", u"(?)"))
, &m_spinBoxOutgoingPortsMax);
// NAT-PMP gateway
m_lineEditNATPMPGateway.setText(session->NATPMPGateway());
addRow(NATPMP_GATEWAY, (tr("Optional NAT-PMP gateway")
+ u' ' + makeLink(u"https://www.libtorrent.org/reference-Settings.html#natpmp-gateway", u"(?)"))
, &m_lineEditNATPMPGateway);
// UPnP lease duration
m_spinBoxUPnPLeaseDuration.setMinimum(0);
m_spinBoxUPnPLeaseDuration.setMaximum(std::numeric_limits<int>::max());

View file

@ -83,7 +83,7 @@ private:
m_checkBoxStartSessionPaused;
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm,
m_comboBoxSeedChokingAlgorithm, m_comboBoxResumeDataStorage, m_comboBoxTorrentContentRemoveOption;
QLineEdit m_lineEditAppInstanceName, m_pythonExecutablePath, m_lineEditAnnounceIP, m_lineEditDHTBootstrapNodes;
QLineEdit m_lineEditAppInstanceName, m_pythonExecutablePath, m_lineEditAnnounceIP, m_lineEditDHTBootstrapNodes, m_lineEditNATPMPGateway;
#ifndef QBT_USES_LIBTORRENT2
QSpinBox m_spinBoxCache, m_spinBoxCacheTTL;

View file

@ -456,6 +456,8 @@ void AppController::preferencesAction()
// Outgoing ports
data[u"outgoing_ports_min"_s] = session->outgoingPortsMin();
data[u"outgoing_ports_max"_s] = session->outgoingPortsMax();
// NAT-PMP gateway
data[u"natpmp_gateway"_s] = session->NATPMPGateway();
// UPnP lease duration
data[u"upnp_lease_duration"_s] = session->UPnPLeaseDuration();
// Type of service
@ -1109,6 +1111,12 @@ void AppController::setPreferencesAction()
session->setOutgoingPortsMin(it.value().toInt());
if (hasKey(u"outgoing_ports_max"_s))
session->setOutgoingPortsMax(it.value().toInt());
// NAT-PMP gateway
if (hasKey(u"natpmp_gateway"_s))
{
const QHostAddress gatewayAddr {it.value().toString().trimmed()};
session->setNATPMPGateway(gatewayAddr.isNull() ? QString() : gatewayAddr.toString());
}
// UPnP lease duration
if (hasKey(u"upnp_lease_duration"_s))
session->setUPnPLeaseDuration(it.value().toInt());