diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index cae03ba83..b097d7521 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -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; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 3bdd9ff13..df9fd5ff3 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -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; diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index e923f8a13..a23f4855d 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -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 m_slowTorrentsInactivityTimer; CachedSettingValue m_outgoingPortsMin; CachedSettingValue m_outgoingPortsMax; + CachedSettingValue m_NATPMPGateway; CachedSettingValue m_UPnPLeaseDuration; CachedSettingValue m_peerToS; CachedSettingValue m_ignoreLimitsOnLAN; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index ba620e027..09c21b4bd 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #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::max()); diff --git a/src/gui/advancedsettings.h b/src/gui/advancedsettings.h index 7ffca4f33..0d67abae6 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -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; diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index e2e465acd..02479d9ef 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -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());