mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 07:18:08 +00:00
Add port forwarding option for embedded tracker
Closes #17781. PR #17981.
This commit is contained in:
parent
c80238d66f
commit
f6735401f4
@ -80,6 +80,7 @@
|
|||||||
#include "base/logger.h"
|
#include "base/logger.h"
|
||||||
#include "base/net/downloadmanager.h"
|
#include "base/net/downloadmanager.h"
|
||||||
#include "base/net/proxyconfigurationmanager.h"
|
#include "base/net/proxyconfigurationmanager.h"
|
||||||
|
#include "base/preferences.h"
|
||||||
#include "base/profile.h"
|
#include "base/profile.h"
|
||||||
#include "base/torrentfileguard.h"
|
#include "base/torrentfileguard.h"
|
||||||
#include "base/torrentfilter.h"
|
#include "base/torrentfilter.h"
|
||||||
@ -548,8 +549,6 @@ SessionImpl::SessionImpl(QObject *parent)
|
|||||||
if (isExcludedFileNamesEnabled())
|
if (isExcludedFileNamesEnabled())
|
||||||
populateExcludedFileNamesRegExpList();
|
populateExcludedFileNamesRegExpList();
|
||||||
|
|
||||||
enableTracker(isTrackerEnabled());
|
|
||||||
|
|
||||||
connect(Net::ProxyConfigurationManager::instance()
|
connect(Net::ProxyConfigurationManager::instance()
|
||||||
, &Net::ProxyConfigurationManager::proxyConfigurationChanged
|
, &Net::ProxyConfigurationManager::proxyConfigurationChanged
|
||||||
, this, &SessionImpl::configureDeferred);
|
, this, &SessionImpl::configureDeferred);
|
||||||
@ -569,11 +568,14 @@ SessionImpl::SessionImpl(QObject *parent)
|
|||||||
|
|
||||||
m_ioThread->start();
|
m_ioThread->start();
|
||||||
|
|
||||||
|
initMetrics();
|
||||||
|
loadStatistics();
|
||||||
|
|
||||||
// initialize PortForwarder instance
|
// initialize PortForwarder instance
|
||||||
new PortForwarderImpl(m_nativeSession);
|
new PortForwarderImpl(m_nativeSession);
|
||||||
|
|
||||||
initMetrics();
|
// start embedded tracker
|
||||||
loadStatistics();
|
enableTracker(isTrackerEnabled());
|
||||||
|
|
||||||
prepareStartup();
|
prepareStartup();
|
||||||
}
|
}
|
||||||
@ -1980,16 +1982,27 @@ void SessionImpl::configurePeerClasses()
|
|||||||
|
|
||||||
void SessionImpl::enableTracker(const bool enable)
|
void SessionImpl::enableTracker(const bool enable)
|
||||||
{
|
{
|
||||||
|
const QString profile = u"embeddedTracker"_qs;
|
||||||
|
auto *portForwarder = Net::PortForwarder::instance();
|
||||||
|
|
||||||
if (enable)
|
if (enable)
|
||||||
{
|
{
|
||||||
if (!m_tracker)
|
if (!m_tracker)
|
||||||
m_tracker = new Tracker(this);
|
m_tracker = new Tracker(this);
|
||||||
|
|
||||||
m_tracker->start();
|
m_tracker->start();
|
||||||
|
|
||||||
|
const auto *pref = Preferences::instance();
|
||||||
|
if (pref->isTrackerPortForwardingEnabled())
|
||||||
|
portForwarder->setPorts(profile, {static_cast<quint16>(pref->getTrackerPort())});
|
||||||
|
else
|
||||||
|
portForwarder->removePorts(profile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
delete m_tracker;
|
delete m_tracker;
|
||||||
|
|
||||||
|
portForwarder->removePorts(profile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,12 +203,12 @@ Tracker::Tracker(QObject *parent)
|
|||||||
|
|
||||||
bool Tracker::start()
|
bool Tracker::start()
|
||||||
{
|
{
|
||||||
const QHostAddress ip = QHostAddress::Any;
|
|
||||||
const int port = Preferences::instance()->getTrackerPort();
|
const int port = Preferences::instance()->getTrackerPort();
|
||||||
|
|
||||||
if (m_server->isListening())
|
if (m_server->isListening())
|
||||||
{
|
{
|
||||||
if (m_server->serverPort() == port)
|
if (const int oldPort = m_server->serverPort()
|
||||||
|
; oldPort == port)
|
||||||
{
|
{
|
||||||
// Already listening on the right port, just return
|
// Already listening on the right port, just return
|
||||||
return true;
|
return true;
|
||||||
@ -218,9 +218,9 @@ bool Tracker::start()
|
|||||||
m_server->close();
|
m_server->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen on the predefined port
|
// Listen on port
|
||||||
|
const QHostAddress ip = QHostAddress::Any;
|
||||||
const bool listenSuccess = m_server->listen(ip, port);
|
const bool listenSuccess = m_server->listen(ip, port);
|
||||||
|
|
||||||
if (listenSuccess)
|
if (listenSuccess)
|
||||||
{
|
{
|
||||||
LogMsg(tr("Embedded Tracker: Now listening on IP: %1, port: %2")
|
LogMsg(tr("Embedded Tracker: Now listening on IP: %1, port: %2")
|
||||||
|
@ -1164,6 +1164,16 @@ void Preferences::setTrackerPort(const int port)
|
|||||||
setValue(u"Preferences/Advanced/trackerPort"_qs, port);
|
setValue(u"Preferences/Advanced/trackerPort"_qs, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Preferences::isTrackerPortForwardingEnabled() const
|
||||||
|
{
|
||||||
|
return value(u"Preferences/Advanced/trackerPortForwarding"_qs, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Preferences::setTrackerPortForwardingEnabled(const bool enabled)
|
||||||
|
{
|
||||||
|
setValue(u"Preferences/Advanced/trackerPortForwarding"_qs, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
bool Preferences::isUpdateCheckEnabled() const
|
bool Preferences::isUpdateCheckEnabled() const
|
||||||
{
|
{
|
||||||
|
@ -299,6 +299,8 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
int getTrackerPort() const;
|
int getTrackerPort() const;
|
||||||
void setTrackerPort(int port);
|
void setTrackerPort(int port);
|
||||||
|
bool isTrackerPortForwardingEnabled() const;
|
||||||
|
void setTrackerPortForwardingEnabled(bool enabled);
|
||||||
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||||
bool isUpdateCheckEnabled() const;
|
bool isUpdateCheckEnabled() const;
|
||||||
void setUpdateCheckEnabled(bool enabled);
|
void setUpdateCheckEnabled(bool enabled);
|
||||||
|
@ -97,6 +97,7 @@ namespace
|
|||||||
// embedded tracker
|
// embedded tracker
|
||||||
TRACKER_STATUS,
|
TRACKER_STATUS,
|
||||||
TRACKER_PORT,
|
TRACKER_PORT,
|
||||||
|
TRACKER_PORT_FORWARDING,
|
||||||
// libtorrent section
|
// libtorrent section
|
||||||
LIBTORRENT_HEADER,
|
LIBTORRENT_HEADER,
|
||||||
ASYNC_IO_THREADS,
|
ASYNC_IO_THREADS,
|
||||||
@ -292,7 +293,9 @@ void AdvancedSettings::saveAdvancedSettings() const
|
|||||||
|
|
||||||
// Tracker
|
// Tracker
|
||||||
pref->setTrackerPort(m_spinBoxTrackerPort.value());
|
pref->setTrackerPort(m_spinBoxTrackerPort.value());
|
||||||
|
pref->setTrackerPortForwardingEnabled(m_checkBoxTrackerPortForwarding.isChecked());
|
||||||
session->setTrackerEnabled(m_checkBoxTrackerStatus.isChecked());
|
session->setTrackerEnabled(m_checkBoxTrackerStatus.isChecked());
|
||||||
|
|
||||||
// Choking algorithm
|
// Choking algorithm
|
||||||
session->setChokingAlgorithm(m_comboBoxChokingAlgorithm.currentData().value<BitTorrent::ChokingAlgorithm>());
|
session->setChokingAlgorithm(m_comboBoxChokingAlgorithm.currentData().value<BitTorrent::ChokingAlgorithm>());
|
||||||
// Seed choking algorithm
|
// Seed choking algorithm
|
||||||
@ -732,6 +735,9 @@ void AdvancedSettings::loadAdvancedSettings()
|
|||||||
m_spinBoxTrackerPort.setMaximum(65535);
|
m_spinBoxTrackerPort.setMaximum(65535);
|
||||||
m_spinBoxTrackerPort.setValue(pref->getTrackerPort());
|
m_spinBoxTrackerPort.setValue(pref->getTrackerPort());
|
||||||
addRow(TRACKER_PORT, tr("Embedded tracker port"), &m_spinBoxTrackerPort);
|
addRow(TRACKER_PORT, tr("Embedded tracker port"), &m_spinBoxTrackerPort);
|
||||||
|
// Tracker port forwarding
|
||||||
|
m_checkBoxTrackerPortForwarding.setChecked(pref->isTrackerPortForwardingEnabled());
|
||||||
|
addRow(TRACKER_PORT_FORWARDING, tr("Enable port forwarding for embedded tracker"), &m_checkBoxTrackerPortForwarding);
|
||||||
// Choking algorithm
|
// Choking algorithm
|
||||||
m_comboBoxChokingAlgorithm.addItem(tr("Fixed slots"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::FixedSlots));
|
m_comboBoxChokingAlgorithm.addItem(tr("Fixed slots"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::FixedSlots));
|
||||||
m_comboBoxChokingAlgorithm.addItem(tr("Upload rate based"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::RateBased));
|
m_comboBoxChokingAlgorithm.addItem(tr("Upload rate based"), QVariant::fromValue(BitTorrent::ChokingAlgorithm::RateBased));
|
||||||
|
@ -68,7 +68,7 @@ private:
|
|||||||
m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize;
|
m_spinBoxSavePathHistoryLength, m_spinBoxPeerTurnover, m_spinBoxPeerTurnoverCutoff, m_spinBoxPeerTurnoverInterval, m_spinBoxRequestQueueSize;
|
||||||
QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts,
|
QCheckBox m_checkBoxOsCache, m_checkBoxRecheckCompleted, m_checkBoxResolveCountries, m_checkBoxResolveHosts,
|
||||||
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
|
m_checkBoxProgramNotifications, m_checkBoxTorrentAddedNotifications, m_checkBoxReannounceWhenAddressChanged, m_checkBoxTrackerFavicon, m_checkBoxTrackerStatus,
|
||||||
m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
|
m_checkBoxTrackerPortForwarding, m_checkBoxConfirmTorrentRecheck, m_checkBoxConfirmRemoveAllTags, m_checkBoxAnnounceAllTrackers, m_checkBoxAnnounceAllTiers,
|
||||||
m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxSSRFMitigation, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity,
|
m_checkBoxMultiConnectionsPerIp, m_checkBoxValidateHTTPSTrackerCertificate, m_checkBoxSSRFMitigation, m_checkBoxBlockPeersOnPrivilegedPorts, m_checkBoxPieceExtentAffinity,
|
||||||
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport;
|
m_checkBoxSuggestMode, m_checkBoxSpeedWidgetEnabled, m_checkBoxIDNSupport;
|
||||||
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm,
|
QComboBox m_comboBoxInterface, m_comboBoxInterfaceAddress, m_comboBoxDiskIOReadMode, m_comboBoxDiskIOWriteMode, m_comboBoxUtpMixedMode, m_comboBoxChokingAlgorithm,
|
||||||
|
@ -372,6 +372,7 @@ void AppController::preferencesAction()
|
|||||||
// Embedded tracker
|
// Embedded tracker
|
||||||
data[u"enable_embedded_tracker"_qs] = session->isTrackerEnabled();
|
data[u"enable_embedded_tracker"_qs] = session->isTrackerEnabled();
|
||||||
data[u"embedded_tracker_port"_qs] = pref->getTrackerPort();
|
data[u"embedded_tracker_port"_qs] = pref->getTrackerPort();
|
||||||
|
data[u"embedded_tracker_port_forwarding"_qs] = pref->isTrackerPortForwardingEnabled();
|
||||||
// Choking algorithm
|
// Choking algorithm
|
||||||
data[u"upload_slots_behavior"_qs] = static_cast<int>(session->chokingAlgorithm());
|
data[u"upload_slots_behavior"_qs] = static_cast<int>(session->chokingAlgorithm());
|
||||||
// Seed choking algorithm
|
// Seed choking algorithm
|
||||||
@ -899,6 +900,8 @@ void AppController::setPreferencesAction()
|
|||||||
// Embedded tracker
|
// Embedded tracker
|
||||||
if (hasKey(u"embedded_tracker_port"_qs))
|
if (hasKey(u"embedded_tracker_port"_qs))
|
||||||
pref->setTrackerPort(it.value().toInt());
|
pref->setTrackerPort(it.value().toInt());
|
||||||
|
if (hasKey(u"embedded_tracker_port_forwarding"_qs))
|
||||||
|
pref->setTrackerPortForwardingEnabled(it.value().toBool());
|
||||||
if (hasKey(u"enable_embedded_tracker"_qs))
|
if (hasKey(u"enable_embedded_tracker"_qs))
|
||||||
session->setTrackerEnabled(it.value().toBool());
|
session->setTrackerEnabled(it.value().toBool());
|
||||||
// Choking algorithm
|
// Choking algorithm
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
#include "base/utils/version.h"
|
#include "base/utils/version.h"
|
||||||
#include "api/isessionmanager.h"
|
#include "api/isessionmanager.h"
|
||||||
|
|
||||||
inline const Utils::Version<3, 2> API_VERSION {2, 8, 17};
|
inline const Utils::Version<3, 2> API_VERSION {2, 8, 18};
|
||||||
|
|
||||||
class APIController;
|
class APIController;
|
||||||
class AuthController;
|
class AuthController;
|
||||||
|
@ -1016,6 +1016,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
|||||||
<input type="text" id="embeddedTrackerPort" style="width: 15em;" />
|
<input type="text" id="embeddedTrackerPort" style="width: 15em;" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label for="embeddedTrackerPortForwarding">QBT_TR(Enable port forwarding for embedded tracker:)QBT_TR[CONTEXT=OptionsDialog]</label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input type="checkbox" id="embeddedTrackerPortForwarding" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset class="settings">
|
<fieldset class="settings">
|
||||||
@ -2099,6 +2107,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
|||||||
$('blockPeersOnPrivilegedPorts').setProperty('checked', pref.block_peers_on_privileged_ports);
|
$('blockPeersOnPrivilegedPorts').setProperty('checked', pref.block_peers_on_privileged_ports);
|
||||||
$('enableEmbeddedTracker').setProperty('checked', pref.enable_embedded_tracker);
|
$('enableEmbeddedTracker').setProperty('checked', pref.enable_embedded_tracker);
|
||||||
$('embeddedTrackerPort').setProperty('value', pref.embedded_tracker_port);
|
$('embeddedTrackerPort').setProperty('value', pref.embedded_tracker_port);
|
||||||
|
$('embeddedTrackerPortForwarding').setProperty('checked', pref.embedded_tracker_port_forwarding);
|
||||||
$('uploadSlotsBehavior').setProperty('value', pref.upload_slots_behavior);
|
$('uploadSlotsBehavior').setProperty('value', pref.upload_slots_behavior);
|
||||||
$('uploadChokingAlgorithm').setProperty('value', pref.upload_choking_algorithm);
|
$('uploadChokingAlgorithm').setProperty('value', pref.upload_choking_algorithm);
|
||||||
$('announceAllTrackers').setProperty('checked', pref.announce_to_all_trackers);
|
$('announceAllTrackers').setProperty('checked', pref.announce_to_all_trackers);
|
||||||
@ -2526,6 +2535,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
|||||||
settings.set('block_peers_on_privileged_ports', $('blockPeersOnPrivilegedPorts').getProperty('checked'));
|
settings.set('block_peers_on_privileged_ports', $('blockPeersOnPrivilegedPorts').getProperty('checked'));
|
||||||
settings.set('enable_embedded_tracker', $('enableEmbeddedTracker').getProperty('checked'));
|
settings.set('enable_embedded_tracker', $('enableEmbeddedTracker').getProperty('checked'));
|
||||||
settings.set('embedded_tracker_port', $('embeddedTrackerPort').getProperty('value'));
|
settings.set('embedded_tracker_port', $('embeddedTrackerPort').getProperty('value'));
|
||||||
|
settings.set('embedded_tracker_port_forwarding', $('embeddedTrackerPortForwarding').getProperty('checked'));
|
||||||
settings.set('upload_slots_behavior', $('uploadSlotsBehavior').getProperty('value'));
|
settings.set('upload_slots_behavior', $('uploadSlotsBehavior').getProperty('value'));
|
||||||
settings.set('upload_choking_algorithm', $('uploadChokingAlgorithm').getProperty('value'));
|
settings.set('upload_choking_algorithm', $('uploadChokingAlgorithm').getProperty('value'));
|
||||||
settings.set('announce_to_all_trackers', $('announceAllTrackers').getProperty('checked'));
|
settings.set('announce_to_all_trackers', $('announceAllTrackers').getProperty('checked'));
|
||||||
|
Loading…
Reference in New Issue
Block a user