Add port forwarding option for embedded tracker

Closes #17781.
PR #17981.
This commit is contained in:
Chocobo1 2022-11-07 11:32:11 +08:00 committed by GitHub
parent c80238d66f
commit f6735401f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 10 deletions

View file

@ -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);
}
}