mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-10 07:22:47 -07:00
Add port forwarding option for embedded tracker
Closes #17781. PR #17981.
This commit is contained in:
parent
c80238d66f
commit
f6735401f4
9 changed files with 54 additions and 10 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue