From 87864531ab747b10094b4e0efc32ea80c586b6b9 Mon Sep 17 00:00:00 2001 From: FranciscoPombal Date: Wed, 7 Oct 2020 12:27:46 +0100 Subject: [PATCH] Clean up in Session class --- src/base/bittorrent/session.cpp | 41 +++++++++++++++++---------------- src/base/bittorrent/session.h | 2 +- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 6a2c3f9c7..a63df5d85 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -30,6 +30,7 @@ #include "session.h" #include +#include #include #include #include @@ -1100,7 +1101,7 @@ void Session::processBannedIPs(lt::ip_filter &filter) } } -void Session::adjustLimits(lt::settings_pack &settingsPack) +void Session::adjustLimits(lt::settings_pack &settingsPack) const { // Internally increase the queue limits to ensure that the magnet is started const int maxDownloads = maxActiveDownloads(); @@ -2667,10 +2668,10 @@ QString Session::networkInterface() const return m_networkInterface; } -void Session::setNetworkInterface(const QString &iface) +void Session::setNetworkInterface(const QString &interface) { - if (iface != networkInterface()) { - m_networkInterface = iface; + if (interface != networkInterface()) { + m_networkInterface = interface; configureListeningInterface(); } } @@ -3655,7 +3656,7 @@ void Session::handleTorrentTrackersRemoved(TorrentHandleImpl *const torrent, con for (const TrackerEntry &deletedTracker : deletedTrackers) LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name())); emit trackersRemoved(torrent, deletedTrackers); - if (torrent->trackers().size() == 0) + if (torrent->trackers().empty()) emit trackerlessStateChanged(torrent, true); emit trackersChanged(torrent); } @@ -4334,7 +4335,7 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle) const LoadTorrentParams params = m_loadingTorrents.take(nativeHandle.info_hash()); - TorrentHandleImpl *const torrent = new TorrentHandleImpl {this, nativeHandle, params}; + auto *const torrent = new TorrentHandleImpl {this, nativeHandle, params}; m_torrents.insert(torrent->hash(), torrent); const bool hasMetadata = torrent->hasMetadata(); @@ -4603,16 +4604,16 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) m_status.hasIncomingConnections = static_cast(stats[m_metricIndices.net.hasIncomingConnections]); - const auto ipOverheadDownload = stats[m_metricIndices.net.recvIPOverheadBytes]; - const auto ipOverheadUpload = stats[m_metricIndices.net.sentIPOverheadBytes]; - const auto totalDownload = stats[m_metricIndices.net.recvBytes] + ipOverheadDownload; - const auto totalUpload = stats[m_metricIndices.net.sentBytes] + ipOverheadUpload; - const auto totalPayloadDownload = stats[m_metricIndices.net.recvPayloadBytes]; - const auto totalPayloadUpload = stats[m_metricIndices.net.sentPayloadBytes]; - const auto trackerDownload = stats[m_metricIndices.net.recvTrackerBytes]; - const auto trackerUpload = stats[m_metricIndices.net.sentTrackerBytes]; - const auto dhtDownload = stats[m_metricIndices.dht.dhtBytesIn]; - const auto dhtUpload = stats[m_metricIndices.dht.dhtBytesOut]; + const int64_t ipOverheadDownload = stats[m_metricIndices.net.recvIPOverheadBytes]; + const int64_t ipOverheadUpload = stats[m_metricIndices.net.sentIPOverheadBytes]; + const int64_t totalDownload = stats[m_metricIndices.net.recvBytes] + ipOverheadDownload; + const int64_t totalUpload = stats[m_metricIndices.net.sentBytes] + ipOverheadUpload; + const int64_t totalPayloadDownload = stats[m_metricIndices.net.recvPayloadBytes]; + const int64_t totalPayloadUpload = stats[m_metricIndices.net.sentPayloadBytes]; + const int64_t trackerDownload = stats[m_metricIndices.net.recvTrackerBytes]; + const int64_t trackerUpload = stats[m_metricIndices.net.sentTrackerBytes]; + const int64_t dhtDownload = stats[m_metricIndices.dht.dhtBytesIn]; + const int64_t dhtUpload = stats[m_metricIndices.dht.dhtBytesOut]; auto calcRate = [interval](const quint64 previous, const quint64 current) { @@ -4648,13 +4649,13 @@ void Session::handleSessionStatsAlert(const lt::session_stats_alert *p) m_status.diskWriteQueue = stats[m_metricIndices.peer.numPeersDownDisk]; m_status.peersCount = stats[m_metricIndices.peer.numPeersConnected]; - const int numBlocksRead = stats[m_metricIndices.disk.numBlocksRead]; - const int numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits]; + const int64_t numBlocksRead = stats[m_metricIndices.disk.numBlocksRead]; + const int64_t numBlocksCacheHits = stats[m_metricIndices.disk.numBlocksCacheHits]; m_cacheStatus.totalUsedBuffers = stats[m_metricIndices.disk.diskBlocksInUse]; - m_cacheStatus.readRatio = static_cast(numBlocksCacheHits) / std::max(numBlocksCacheHits + numBlocksRead, 1); + m_cacheStatus.readRatio = static_cast(numBlocksCacheHits) / std::max(numBlocksCacheHits + numBlocksRead, 1); m_cacheStatus.jobQueueLength = stats[m_metricIndices.disk.queuedDiskJobs]; - const quint64 totalJobs = stats[m_metricIndices.disk.writeJobs] + stats[m_metricIndices.disk.readJobs] + const int64_t totalJobs = stats[m_metricIndices.disk.writeJobs] + stats[m_metricIndices.disk.readJobs] + stats[m_metricIndices.disk.hashJobs]; m_cacheStatus.averageJobTime = (totalJobs > 0) ? (stats[m_metricIndices.disk.diskJobTime] / totalJobs) : 0; diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 20f488d7e..0dae94349 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -570,7 +570,7 @@ namespace BitTorrent void loadLTSettings(lt::settings_pack &settingsPack); void configureNetworkInterfaces(lt::settings_pack &settingsPack); void configurePeerClasses(); - void adjustLimits(lt::settings_pack &settingsPack); + void adjustLimits(lt::settings_pack &settingsPack) const; void applyBandwidthLimits(lt::settings_pack &settingsPack) const; void initMetrics(); void adjustLimits();