Browse Source

Clean up Session class variable initialization

adaptive-webui-19844
Chocobo1 5 years ago
parent
commit
865394a59c
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 49
      src/base/bittorrent/session.cpp
  2. 75
      src/base/bittorrent/session.h

49
src/base/bittorrent/session.cpp

@ -42,8 +42,10 @@ @@ -42,8 +42,10 @@
#include <QDebug>
#include <QDir>
#include <QFile>
#include <QHostAddress>
#include <QNetworkAddressEntry>
#include <QNetworkConfigurationManager>
#include <QNetworkInterface>
#include <QRegularExpression>
#include <QString>
@ -243,9 +245,6 @@ Session *Session::m_instance = nullptr; @@ -243,9 +245,6 @@ Session *Session::m_instance = nullptr;
Session::Session(QObject *parent)
: QObject(parent)
, m_deferredConfigureScheduled(false)
, m_IPFilteringChanged(true)
, m_listenInterfaceChanged(true)
, m_isDHTEnabled(BITTORRENT_SESSION_KEY("DHTEnabled"), true)
, m_isLSDEnabled(BITTORRENT_SESSION_KEY("LSDEnabled"), true)
, m_isPeXEnabled(BITTORRENT_SESSION_KEY("PeXEnabled"), true)
@ -346,10 +345,14 @@ Session::Session(QObject *parent) @@ -346,10 +345,14 @@ Session::Session(QObject *parent)
return tmp;
}
)
, m_wasPexEnabled(m_isPeXEnabled)
, m_numResumeData(0)
, m_extraLimit(0)
, m_recentErroredTorrentsTimer(new QTimer(this))
, m_resumeFolderLock {new QFile {this}}
, m_refreshTimer {new QTimer {this}}
, m_seedingLimitTimer {new QTimer {this}}
, m_resumeDataTimer {new QTimer {this}}
, m_statistics {new Statistics {this}}
, m_ioThread {new QThread {this}}
, m_recentErroredTorrentsTimer {new QTimer {this}}
, m_networkManager {new QNetworkConfigurationManager {this}}
{
if (port() < 0)
m_port = Utils::Random::rand(1024, 65535);
@ -358,9 +361,9 @@ Session::Session(QObject *parent) @@ -358,9 +361,9 @@ Session::Session(QObject *parent)
m_recentErroredTorrentsTimer->setSingleShot(true);
m_recentErroredTorrentsTimer->setInterval(1000);
connect(m_recentErroredTorrentsTimer, &QTimer::timeout, this, [this]() { m_recentErroredTorrents.clear(); });
connect(m_recentErroredTorrentsTimer, &QTimer::timeout
, this, [this]() { m_recentErroredTorrents.clear(); });
m_seedingLimitTimer = new QTimer(this);
m_seedingLimitTimer->setInterval(10000);
connect(m_seedingLimitTimer, &QTimer::timeout, this, &Session::processShareLimits);
@ -379,35 +382,31 @@ Session::Session(QObject *parent) @@ -379,35 +382,31 @@ Session::Session(QObject *parent)
m_tags = QSet<QString>::fromList(m_storedTags.value());
m_refreshTimer = new QTimer(this);
m_refreshTimer->setInterval(refreshInterval());
connect(m_refreshTimer, &QTimer::timeout, this, &Session::refresh);
m_refreshTimer->start();
m_statistics = new Statistics(this);
updateSeedingLimitTimer();
populateAdditionalTrackers();
enableTracker(isTrackerEnabled());
connect(Net::ProxyConfigurationManager::instance(), &Net::ProxyConfigurationManager::proxyConfigurationChanged
, this, &Session::configureDeferred);
connect(Net::ProxyConfigurationManager::instance()
, &Net::ProxyConfigurationManager::proxyConfigurationChanged
, this, &Session::configureDeferred);
// Network configuration monitor
connect(&m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged);
connect(&m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange);
connect(&m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange);
connect(&m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange);
connect(m_networkManager, &QNetworkConfigurationManager::onlineStateChanged, this, &Session::networkOnlineStateChanged);
connect(m_networkManager, &QNetworkConfigurationManager::configurationAdded, this, &Session::networkConfigurationChange);
connect(m_networkManager, &QNetworkConfigurationManager::configurationRemoved, this, &Session::networkConfigurationChange);
connect(m_networkManager, &QNetworkConfigurationManager::configurationChanged, this, &Session::networkConfigurationChange);
m_ioThread = new QThread(this);
m_resumeDataSavingManager = new ResumeDataSavingManager {m_resumeFolderPath};
m_resumeDataSavingManager->moveToThread(m_ioThread);
connect(m_ioThread, &QThread::finished, m_resumeDataSavingManager, &QObject::deleteLater);
m_ioThread->start();
// Regular saving of fastresume data
m_resumeDataTimer = new QTimer(this);
connect(m_resumeDataTimer, &QTimer::timeout, this, [this]() { generateResumeData(); });
const uint saveInterval = saveResumeDataInterval();
if (saveInterval > 0) {
@ -419,8 +418,6 @@ Session::Session(QObject *parent) @@ -419,8 +418,6 @@ Session::Session(QObject *parent)
new PortForwarderImpl {m_nativeSession};
initMetrics();
qDebug("* BitTorrent Session constructed");
}
bool Session::isDHTEnabled() const
@ -869,8 +866,8 @@ Session::~Session() @@ -869,8 +866,8 @@ Session::~Session()
m_ioThread->quit();
m_ioThread->wait();
m_resumeFolderLock.close();
m_resumeFolderLock.remove();
m_resumeFolderLock->close();
m_resumeFolderLock->remove();
}
void Session::initInstance()
@ -3559,8 +3556,8 @@ void Session::initResumeFolder() @@ -3559,8 +3556,8 @@ void Session::initResumeFolder()
m_resumeFolderPath = Utils::Fs::expandPathAbs(specialFolderLocation(SpecialFolder::Data) + RESUME_FOLDER);
const QDir resumeFolderDir(m_resumeFolderPath);
if (resumeFolderDir.exists() || resumeFolderDir.mkpath(resumeFolderDir.absolutePath())) {
m_resumeFolderLock.setFileName(resumeFolderDir.absoluteFilePath("session.lock"));
if (!m_resumeFolderLock.open(QFile::WriteOnly)) {
m_resumeFolderLock->setFileName(resumeFolderDir.absoluteFilePath("session.lock"));
if (!m_resumeFolderLock->open(QFile::WriteOnly)) {
throw RuntimeError {tr("Cannot write to torrent resume folder.")};
}
}

75
src/base/bittorrent/session.h

@ -34,9 +34,7 @@ @@ -34,9 +34,7 @@
#include <libtorrent/fwd.hpp>
#include <QFile>
#include <QHash>
#include <QNetworkConfigurationManager>
#include <QPointer>
#include <QSet>
#include <QVector>
@ -48,16 +46,19 @@ @@ -48,16 +46,19 @@
#include "sessionstatus.h"
#include "torrentinfo.h"
class QThread;
class QTimer;
class QFile;
class QNetworkConfiguration;
class QNetworkConfigurationManager;
class QString;
class QStringList;
class QThread;
class QTimer;
class QUrl;
class FilterParserThread;
class BandwidthScheduler;
class Statistics;
class FilterParserThread;
class ResumeDataSavingManager;
class Statistics;
// These values should remain unchanged when adding new items
// so as not to break the existing user settings.
@ -89,9 +90,9 @@ namespace Net @@ -89,9 +90,9 @@ namespace Net
namespace BitTorrent
{
class InfoHash;
class MagnetUri;
class TorrentHandle;
class Tracker;
class MagnetUri;
class TrackerEntry;
struct CreateTorrentParams;
@ -102,6 +103,14 @@ namespace BitTorrent @@ -102,6 +103,14 @@ namespace BitTorrent
{
Q_NAMESPACE
enum class BTProtocol : int
{
Both = 0,
TCP = 1,
UTP = 2
};
Q_ENUM_NS(BTProtocol)
enum class ChokingAlgorithm : int
{
FixedSlots = 0,
@ -109,14 +118,6 @@ namespace BitTorrent @@ -109,14 +118,6 @@ namespace BitTorrent
};
Q_ENUM_NS(ChokingAlgorithm)
enum class SeedChokingAlgorithm : int
{
RoundRobin = 0,
FastestUpload = 1,
AntiLeech = 2
};
Q_ENUM_NS(SeedChokingAlgorithm)
enum class MixedModeAlgorithm : int
{
TCP = 0,
@ -124,13 +125,13 @@ namespace BitTorrent @@ -124,13 +125,13 @@ namespace BitTorrent
};
Q_ENUM_NS(MixedModeAlgorithm)
enum class BTProtocol : int
enum class SeedChokingAlgorithm : int
{
Both = 0,
TCP = 1,
UTP = 2
RoundRobin = 0,
FastestUpload = 1,
AntiLeech = 2
};
Q_ENUM_NS(BTProtocol)
Q_ENUM_NS(SeedChokingAlgorithm)
}
using namespace SessionSettingsEnums;
@ -492,7 +493,7 @@ namespace BitTorrent @@ -492,7 +493,7 @@ namespace BitTorrent
// Session reconfiguration triggers
void networkOnlineStateChanged(bool online);
void networkConfigurationChange(const QNetworkConfiguration&);
void networkConfigurationChange(const QNetworkConfiguration &);
private:
struct RemovingTorrentData
@ -570,11 +571,11 @@ namespace BitTorrent @@ -570,11 +571,11 @@ namespace BitTorrent
void getPendingAlerts(std::vector<lt::alert *> &out, ulong time = 0);
// BitTorrent
lt::session *m_nativeSession;
lt::session *m_nativeSession = nullptr;
bool m_deferredConfigureScheduled;
bool m_IPFilteringChanged;
bool m_listenInterfaceChanged; // optimization
bool m_deferredConfigureScheduled = false;
bool m_IPFilteringChanged = true; // initialization require this to be true
bool m_listenInterfaceChanged = true; // initialization require this to be true
CachedSettingValue<bool> m_isDHTEnabled;
CachedSettingValue<bool> m_isLSDEnabled;
@ -664,26 +665,26 @@ namespace BitTorrent @@ -664,26 +665,26 @@ namespace BitTorrent
// Order is important. This needs to be declared after its CachedSettingsValue
// counterpart, because it uses it for initialization in the constructor
// initialization list.
const bool m_wasPexEnabled;
const bool m_wasPexEnabled = m_isPeXEnabled;
int m_numResumeData;
int m_extraLimit;
int m_numResumeData = 0;
int m_extraLimit = 0;
QVector<BitTorrent::TrackerEntry> m_additionalTrackerList;
QString m_resumeFolderPath;
QFile m_resumeFolderLock;
QFile *m_resumeFolderLock = nullptr;
QTimer *m_refreshTimer;
QTimer *m_seedingLimitTimer;
QTimer *m_resumeDataTimer;
Statistics *m_statistics;
QTimer *m_refreshTimer = nullptr;
QTimer *m_seedingLimitTimer = nullptr;
QTimer *m_resumeDataTimer = nullptr;
Statistics *m_statistics = nullptr;
// IP filtering
QPointer<FilterParserThread> m_filterParser;
QPointer<BandwidthScheduler> m_bwScheduler;
// Tracker
QPointer<Tracker> m_tracker;
// fastresume data writing thread
QThread *m_ioThread;
ResumeDataSavingManager *m_resumeDataSavingManager;
QThread *m_ioThread = nullptr;
ResumeDataSavingManager *m_resumeDataSavingManager = nullptr;
QHash<InfoHash, TorrentInfo> m_loadedMetadata;
QHash<InfoHash, TorrentHandle *> m_torrents;
@ -695,7 +696,7 @@ namespace BitTorrent @@ -695,7 +696,7 @@ namespace BitTorrent
// I/O errored torrents
QSet<InfoHash> m_recentErroredTorrents;
QTimer *m_recentErroredTorrentsTimer;
QTimer *m_recentErroredTorrentsTimer = nullptr;
SessionMetricIndices m_metricIndices;
lt::time_point m_statsLastTimestamp = lt::clock_type::now();
@ -703,7 +704,7 @@ namespace BitTorrent @@ -703,7 +704,7 @@ namespace BitTorrent
SessionStatus m_status;
CacheStatus m_cacheStatus;
QNetworkConfigurationManager m_networkManager;
QNetworkConfigurationManager *m_networkManager = nullptr;
static Session *m_instance;
};

Loading…
Cancel
Save