diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 86e6ea1b4..4abc6f34c 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -402,6 +402,7 @@ Session::Session(QObject *parent) , m_slowTorrentsInactivityTimer(BITTORRENT_SESSION_KEY("SlowTorrentsInactivityTimer"), 60) , m_outgoingPortsMin(BITTORRENT_SESSION_KEY("OutgoingPortsMin"), 0) , m_outgoingPortsMax(BITTORRENT_SESSION_KEY("OutgoingPortsMax"), 0) + , m_UPnPLeaseDuration(BITTORRENT_SESSION_KEY("UPnPLeaseDuration"), 0) , m_ignoreLimitsOnLAN(BITTORRENT_SESSION_KEY("IgnoreLimitsOnLAN"), false) , m_includeOverheadInLimits(BITTORRENT_SESSION_KEY("IncludeOverheadInLimits"), false) , m_announceIP(BITTORRENT_SESSION_KEY("AnnounceIP")) @@ -1367,6 +1368,10 @@ void Session::loadLTSettings(lt::settings_pack &settingsPack) settingsPack.set_int(lt::settings_pack::outgoing_port, outgoingPortsMin()); settingsPack.set_int(lt::settings_pack::num_outgoing_ports, outgoingPortsMax() - outgoingPortsMin() + 1); +#if (LIBTORRENT_VERSION_NUM >= 10206) + settingsPack.set_int(lt::settings_pack::upnp_lease_duration, UPnPLeaseDuration()); +#endif + // Include overhead in transfer limits settingsPack.set_bool(lt::settings_pack::rate_limit_ip_overhead, includeOverheadInLimits()); // IP address to announce to trackers @@ -3554,6 +3559,19 @@ void Session::setOutgoingPortsMax(const int max) } } +int Session::UPnPLeaseDuration() const +{ + return m_UPnPLeaseDuration; +} + +void Session::setUPnPLeaseDuration(const int duration) +{ + if (duration != m_UPnPLeaseDuration) { + m_UPnPLeaseDuration = duration; + configureDeferred(); + } +} + bool Session::ignoreLimitsOnLAN() const { return m_ignoreLimitsOnLAN; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 58119468a..4f5bcc332 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -367,6 +367,8 @@ namespace BitTorrent void setOutgoingPortsMin(int min); int outgoingPortsMax() const; void setOutgoingPortsMax(int max); + int UPnPLeaseDuration() const; + void setUPnPLeaseDuration(int duration); bool ignoreLimitsOnLAN() const; void setIgnoreLimitsOnLAN(bool ignore); bool includeOverheadInLimits() const; @@ -650,6 +652,7 @@ namespace BitTorrent CachedSettingValue m_slowTorrentsInactivityTimer; CachedSettingValue m_outgoingPortsMin; CachedSettingValue m_outgoingPortsMax; + CachedSettingValue m_UPnPLeaseDuration; CachedSettingValue m_ignoreLimitsOnLAN; CachedSettingValue m_includeOverheadInLimits; CachedSettingValue m_announceIP; diff --git a/src/gui/advancedsettings.cpp b/src/gui/advancedsettings.cpp index dcc2d6838..08aa5a86a 100644 --- a/src/gui/advancedsettings.cpp +++ b/src/gui/advancedsettings.cpp @@ -103,6 +103,9 @@ enum AdvSettingsRows SOCKET_BACKLOG_SIZE, OUTGOING_PORT_MIN, OUTGOING_PORT_MAX, +#if (LIBTORRENT_VERSION_NUM >= 10206) + UPNP_LEASE_DURATION, +#endif UTP_MIX_MODE, MULTI_CONNECTIONS_PER_IP, // embedded tracker @@ -205,6 +208,10 @@ void AdvancedSettings::saveAdvancedSettings() // Outgoing ports session->setOutgoingPortsMin(m_spinBoxOutgoingPortsMin.value()); session->setOutgoingPortsMax(m_spinBoxOutgoingPortsMax.value()); +#if (LIBTORRENT_VERSION_NUM >= 10206) + // UPnP lease duration + session->setUPnPLeaseDuration(m_spinBoxUPnPLeaseDuration.value()); +#endif // uTP-TCP mixed mode session->setUtpMixedMode(static_cast(m_comboBoxUtpMixedMode.currentIndex())); // multiple connections per IP @@ -476,6 +483,15 @@ void AdvancedSettings::loadAdvancedSettings() m_spinBoxOutgoingPortsMax.setMaximum(65535); m_spinBoxOutgoingPortsMax.setValue(session->outgoingPortsMax()); addRow(OUTGOING_PORT_MAX, tr("Outgoing ports (Max) [0: Disabled]"), &m_spinBoxOutgoingPortsMax); +#if (LIBTORRENT_VERSION_NUM >= 10206) + // UPnP lease duration + m_spinBoxUPnPLeaseDuration.setMinimum(0); + m_spinBoxUPnPLeaseDuration.setMaximum(std::numeric_limits::max()); + m_spinBoxUPnPLeaseDuration.setValue(session->UPnPLeaseDuration()); + 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); +#endif // 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 5e3beb192..749fa3b53 100644 --- a/src/gui/advancedsettings.h +++ b/src/gui/advancedsettings.h @@ -58,8 +58,8 @@ private: template void addRow(int row, const QString &text, T *widget); QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxCache, - m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxListRefresh, - m_spinBoxTrackerPort, m_spinBoxCacheTTL, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, + m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, + m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxCacheTTL, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, m_spinBoxSendBufferWatermarkFactor, m_spinBoxSocketBacklogSize, m_spinBoxStopTrackerTimeout, m_spinBoxSavePathHistoryLength; QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts, m_checkBoxSuperSeeding, m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus, diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index 49f5c5a72..23495031d 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -296,6 +296,8 @@ void AppController::preferencesAction() // Outgoing ports data["outgoing_ports_min"] = session->outgoingPortsMin(); data["outgoing_ports_max"] = session->outgoingPortsMax(); + // UPnP lease duration + data["upnp_lease_duration"] = session->UPnPLeaseDuration(); // uTP-TCP mixed mode data["utp_tcp_mixed_mode"] = static_cast(session->utpMixedMode()); // Multiple connections per IP @@ -717,6 +719,9 @@ void AppController::setPreferencesAction() session->setOutgoingPortsMin(it.value().toInt()); if (hasKey("outgoing_ports_max")) session->setOutgoingPortsMax(it.value().toInt()); + // UPnP lease duration + if (hasKey("upnp_lease_duration")) + session->setUPnPLeaseDuration(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 bafce04cb..5af3ebf82 100644 --- a/src/webui/www/private/views/preferences.html +++ b/src/webui/www/private/views/preferences.html @@ -999,6 +999,14 @@ + + + + + + + +