mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 06:28:03 -06:00
Add port forwarding option for embedded tracker
Closes #17781. PR #17981.
This commit is contained in:
@@ -80,6 +80,7 @@
|
||||
#include "base/logger.h"
|
||||
#include "base/net/downloadmanager.h"
|
||||
#include "base/net/proxyconfigurationmanager.h"
|
||||
#include "base/preferences.h"
|
||||
#include "base/profile.h"
|
||||
#include "base/torrentfileguard.h"
|
||||
#include "base/torrentfilter.h"
|
||||
@@ -548,8 +549,6 @@ SessionImpl::SessionImpl(QObject *parent)
|
||||
if (isExcludedFileNamesEnabled())
|
||||
populateExcludedFileNamesRegExpList();
|
||||
|
||||
enableTracker(isTrackerEnabled());
|
||||
|
||||
connect(Net::ProxyConfigurationManager::instance()
|
||||
, &Net::ProxyConfigurationManager::proxyConfigurationChanged
|
||||
, this, &SessionImpl::configureDeferred);
|
||||
@@ -569,11 +568,14 @@ SessionImpl::SessionImpl(QObject *parent)
|
||||
|
||||
m_ioThread->start();
|
||||
|
||||
initMetrics();
|
||||
loadStatistics();
|
||||
|
||||
// initialize PortForwarder instance
|
||||
new PortForwarderImpl(m_nativeSession);
|
||||
|
||||
initMetrics();
|
||||
loadStatistics();
|
||||
// start embedded tracker
|
||||
enableTracker(isTrackerEnabled());
|
||||
|
||||
prepareStartup();
|
||||
}
|
||||
@@ -1980,16 +1982,27 @@ void SessionImpl::configurePeerClasses()
|
||||
|
||||
void SessionImpl::enableTracker(const bool enable)
|
||||
{
|
||||
const QString profile = u"embeddedTracker"_qs;
|
||||
auto *portForwarder = Net::PortForwarder::instance();
|
||||
|
||||
if (enable)
|
||||
{
|
||||
if (!m_tracker)
|
||||
m_tracker = new Tracker(this);
|
||||
|
||||
m_tracker->start();
|
||||
|
||||
const auto *pref = Preferences::instance();
|
||||
if (pref->isTrackerPortForwardingEnabled())
|
||||
portForwarder->setPorts(profile, {static_cast<quint16>(pref->getTrackerPort())});
|
||||
else
|
||||
portForwarder->removePorts(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
delete m_tracker;
|
||||
|
||||
portForwarder->removePorts(profile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user