mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
Use cached SessionStatus and CacheStatus
This commit is contained in:
@@ -89,8 +89,6 @@ SOURCES += \
|
||||
$$PWD/net/private/geoipdatabase.cpp \
|
||||
$$PWD/bittorrent/infohash.cpp \
|
||||
$$PWD/bittorrent/session.cpp \
|
||||
$$PWD/bittorrent/sessionstatus.cpp \
|
||||
$$PWD/bittorrent/cachestatus.cpp \
|
||||
$$PWD/bittorrent/magneturi.cpp \
|
||||
$$PWD/bittorrent/torrentinfo.cpp \
|
||||
$$PWD/bittorrent/torrenthandle.cpp \
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include <libtorrent/version.hpp>
|
||||
#include "cachestatus.h"
|
||||
|
||||
using namespace BitTorrent;
|
||||
|
||||
CacheStatus::CacheStatus(const libtorrent::cache_status &nativeStatus)
|
||||
: m_nativeStatus(nativeStatus)
|
||||
{
|
||||
}
|
||||
|
||||
int CacheStatus::totalUsedBuffers() const
|
||||
{
|
||||
return m_nativeStatus.total_used_buffers;
|
||||
}
|
||||
|
||||
qreal CacheStatus::readRatio() const
|
||||
{
|
||||
if (m_nativeStatus.blocks_read > 0)
|
||||
return (static_cast<qreal>(m_nativeStatus.blocks_read_hit) / m_nativeStatus.blocks_read);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CacheStatus::jobQueueLength() const
|
||||
{
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
return m_nativeStatus.job_queue_length;
|
||||
#else
|
||||
return m_nativeStatus.queued_jobs;
|
||||
#endif
|
||||
}
|
||||
|
||||
int CacheStatus::averageJobTime() const
|
||||
{
|
||||
return m_nativeStatus.average_job_time;
|
||||
}
|
||||
|
||||
qlonglong CacheStatus::queuedBytes() const
|
||||
{
|
||||
return m_nativeStatus.queued_bytes;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2015, 2017 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -30,23 +30,16 @@
|
||||
#define BITTORRENT_CACHESTATUS_H
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <libtorrent/disk_io_thread.hpp>
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
class CacheStatus
|
||||
struct CacheStatus
|
||||
{
|
||||
public:
|
||||
CacheStatus(const libtorrent::cache_status &nativeStatus);
|
||||
|
||||
int totalUsedBuffers() const;
|
||||
qreal readRatio() const;
|
||||
int jobQueueLength() const;
|
||||
int averageJobTime() const;
|
||||
qlonglong queuedBytes() const;
|
||||
|
||||
private:
|
||||
libtorrent::cache_status m_nativeStatus;
|
||||
quint64 totalUsedBuffers = 0;
|
||||
quint64 jobQueueLength = 0;
|
||||
quint64 averageJobTime = 0;
|
||||
quint64 queuedBytes = 0;
|
||||
qreal readRatio = 0.0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -45,13 +45,13 @@ quint64 Statistics::getAlltimeUL() const
|
||||
|
||||
void Statistics::gather()
|
||||
{
|
||||
SessionStatus ss = m_session->status();
|
||||
if (ss.totalDownload() > m_sessionDL) {
|
||||
m_sessionDL = ss.totalDownload();
|
||||
const SessionStatus &ss = m_session->status();
|
||||
if (ss.totalDownload > m_sessionDL) {
|
||||
m_sessionDL = ss.totalDownload;
|
||||
m_dirty = true;
|
||||
}
|
||||
if (ss.totalUpload() > m_sessionUL) {
|
||||
m_sessionUL = ss.totalUpload();
|
||||
if (ss.totalUpload > m_sessionUL) {
|
||||
m_sessionUL = ss.totalUpload;
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
#include <libtorrent/bdecode.hpp>
|
||||
#endif
|
||||
#include <libtorrent/bencode.hpp>
|
||||
#include <libtorrent/disk_io_thread.hpp>
|
||||
#include <libtorrent/error_code.hpp>
|
||||
#include <libtorrent/extensions/ut_metadata.hpp>
|
||||
#include <libtorrent/extensions/ut_pex.hpp>
|
||||
@@ -63,6 +64,7 @@
|
||||
#endif
|
||||
#include <libtorrent/magnet_uri.hpp>
|
||||
#include <libtorrent/session.hpp>
|
||||
#include <libtorrent/session_status.hpp>
|
||||
#include <libtorrent/torrent_info.hpp>
|
||||
|
||||
#include "base/logger.h"
|
||||
@@ -79,13 +81,11 @@
|
||||
#include "base/utils/fs.h"
|
||||
#include "base/utils/random.h"
|
||||
#include "base/utils/string.h"
|
||||
#include "cachestatus.h"
|
||||
#include "magneturi.h"
|
||||
#include "private/filterparserthread.h"
|
||||
#include "private/statistics.h"
|
||||
#include "private/bandwidthscheduler.h"
|
||||
#include "private/resumedatasavingmanager.h"
|
||||
#include "sessionstatus.h"
|
||||
#include "torrenthandle.h"
|
||||
#include "tracker.h"
|
||||
#include "trackerentry.h"
|
||||
@@ -3088,14 +3088,14 @@ void Session::recursiveTorrentDownload(const InfoHash &hash)
|
||||
}
|
||||
}
|
||||
|
||||
SessionStatus Session::status() const
|
||||
const SessionStatus &Session::status() const
|
||||
{
|
||||
return m_nativeSession->status();
|
||||
return m_status;
|
||||
}
|
||||
|
||||
CacheStatus Session::cacheStatus() const
|
||||
const CacheStatus &Session::cacheStatus() const
|
||||
{
|
||||
return m_nativeSession->get_cache_status();
|
||||
return m_cacheStatus;
|
||||
}
|
||||
|
||||
// Will resume torrents in backup directory
|
||||
@@ -3581,8 +3581,50 @@ void Session::handleExternalIPAlert(libt::external_ip_alert *p)
|
||||
Logger::instance()->addMessage(tr("External IP: %1", "e.g. External IP: 192.168.0.1").arg(p->external_address.to_string(ec).c_str()), Log::INFO);
|
||||
}
|
||||
|
||||
void Session::updateStats()
|
||||
{
|
||||
libt::session_status ss = m_nativeSession->status();
|
||||
m_status.hasIncomingConnections = ss.has_incoming_connections;
|
||||
m_status.payloadDownloadRate = ss.payload_download_rate;
|
||||
m_status.payloadUploadRate = ss.payload_upload_rate;
|
||||
m_status.downloadRate = ss.download_rate;
|
||||
m_status.uploadRate = ss.upload_rate;
|
||||
m_status.ipOverheadDownloadRate = ss.ip_overhead_download_rate;
|
||||
m_status.ipOverheadUploadRate = ss.ip_overhead_upload_rate;
|
||||
m_status.dhtDownloadRate = ss.dht_download_rate;
|
||||
m_status.dhtUploadRate = ss.dht_upload_rate;
|
||||
m_status.trackerDownloadRate = ss.tracker_download_rate;
|
||||
m_status.trackerUploadRate = ss.tracker_upload_rate;
|
||||
m_status.totalDownload = ss.total_download;
|
||||
m_status.totalUpload = ss.total_upload;
|
||||
m_status.totalPayloadDownload = ss.total_payload_download;
|
||||
m_status.totalPayloadUpload = ss.total_payload_upload;
|
||||
m_status.totalWasted = ss.total_redundant_bytes + ss.total_failed_bytes;
|
||||
m_status.diskReadQueue = ss.disk_read_queue;
|
||||
m_status.diskWriteQueue = ss.disk_write_queue;
|
||||
m_status.dhtNodes = ss.dht_nodes;
|
||||
m_status.peersCount = ss.num_peers;
|
||||
|
||||
libt::cache_status cs = m_nativeSession->get_cache_status();
|
||||
m_cacheStatus.totalUsedBuffers = cs.total_used_buffers;
|
||||
m_cacheStatus.readRatio = cs.blocks_read > 0
|
||||
? static_cast<qreal>(cs.blocks_read_hit) / cs.blocks_read
|
||||
: -1;
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
m_cacheStatus.jobQueueLength = cs.job_queue_length;
|
||||
#else
|
||||
m_cacheStatus.jobQueueLength = cs.queued_jobs;
|
||||
#endif
|
||||
m_cacheStatus.averageJobTime = cs.average_job_time;
|
||||
m_cacheStatus.queuedBytes = cs.queued_bytes;
|
||||
|
||||
emit statsUpdated();
|
||||
}
|
||||
|
||||
void Session::handleStateUpdateAlert(libt::state_update_alert *p)
|
||||
{
|
||||
updateStats();
|
||||
|
||||
foreach (const libt::torrent_status &status, p->status) {
|
||||
TorrentHandle *const torrent = m_torrents.value(status.info_hash);
|
||||
if (torrent)
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
#include "base/tristatebool.h"
|
||||
#include "base/types.h"
|
||||
#include "addtorrentparams.h"
|
||||
#include "cachestatus.h"
|
||||
#include "sessionstatus.h"
|
||||
#include "torrentinfo.h"
|
||||
|
||||
namespace libtorrent
|
||||
@@ -56,15 +58,12 @@ namespace libtorrent
|
||||
class session;
|
||||
struct torrent_handle;
|
||||
class entry;
|
||||
struct add_torrent_params;
|
||||
struct ip_filter;
|
||||
struct pe_settings;
|
||||
#if LIBTORRENT_VERSION_NUM < 10100
|
||||
struct session_settings;
|
||||
#else
|
||||
struct settings_pack;
|
||||
#endif
|
||||
struct session_status;
|
||||
|
||||
class alert;
|
||||
struct torrent_alert;
|
||||
@@ -127,8 +126,6 @@ enum TorrentExportFolder
|
||||
namespace BitTorrent
|
||||
{
|
||||
class InfoHash;
|
||||
class CacheStatus;
|
||||
class SessionStatus;
|
||||
class TorrentHandle;
|
||||
class Tracker;
|
||||
class MagnetUri;
|
||||
@@ -324,8 +321,8 @@ namespace BitTorrent
|
||||
TorrentStatusReport torrentStatusReport() const;
|
||||
bool hasActiveTorrents() const;
|
||||
bool hasUnfinishedTorrents() const;
|
||||
SessionStatus status() const;
|
||||
CacheStatus cacheStatus() const;
|
||||
const SessionStatus &status() const;
|
||||
const CacheStatus &cacheStatus() const;
|
||||
quint64 getAlltimeDL() const;
|
||||
quint64 getAlltimeUL() const;
|
||||
bool isListening() const;
|
||||
@@ -371,6 +368,7 @@ namespace BitTorrent
|
||||
void handleTorrentTrackerAuthenticationRequired(TorrentHandle *const torrent, const QString &trackerUrl);
|
||||
|
||||
signals:
|
||||
void statsUpdated();
|
||||
void torrentsUpdated();
|
||||
void addTorrentFailed(const QString &error);
|
||||
void torrentAdded(BitTorrent::TorrentHandle *const torrent);
|
||||
@@ -485,6 +483,8 @@ namespace BitTorrent
|
||||
#endif
|
||||
void getPendingAlerts(std::vector<libtorrent::alert *> &out, ulong time = 0);
|
||||
|
||||
void updateStats();
|
||||
|
||||
// BitTorrent
|
||||
libtorrent::session *m_nativeSession;
|
||||
|
||||
@@ -600,6 +600,9 @@ namespace BitTorrent
|
||||
std::vector<libtorrent::alert *> m_alerts;
|
||||
#endif
|
||||
|
||||
SessionStatus m_status;
|
||||
CacheStatus m_cacheStatus;
|
||||
|
||||
QNetworkConfigurationManager m_networkManager;
|
||||
|
||||
static Session *m_instance;
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give permission to
|
||||
* link this program with the OpenSSL project's "OpenSSL" library (or with
|
||||
* modified versions of it that use the same license as the "OpenSSL" library),
|
||||
* and distribute the linked executables. You must obey the GNU General Public
|
||||
* License in all respects for all of the code used other than "OpenSSL". If you
|
||||
* modify file(s), you may extend this exception to your version of the file(s),
|
||||
* but you are not obligated to do so. If you do not wish to do so, delete this
|
||||
* exception statement from your version.
|
||||
*/
|
||||
|
||||
#include "sessionstatus.h"
|
||||
|
||||
using namespace BitTorrent;
|
||||
|
||||
SessionStatus::SessionStatus(const libtorrent::session_status &nativeStatus)
|
||||
: m_nativeStatus(nativeStatus)
|
||||
{
|
||||
}
|
||||
|
||||
bool SessionStatus::hasIncomingConnections() const
|
||||
{
|
||||
return m_nativeStatus.has_incoming_connections;
|
||||
}
|
||||
|
||||
int SessionStatus::payloadDownloadRate() const
|
||||
{
|
||||
return m_nativeStatus.payload_download_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::payloadUploadRate() const
|
||||
{
|
||||
return m_nativeStatus.payload_upload_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::downloadRate() const
|
||||
{
|
||||
return m_nativeStatus.download_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::uploadRate() const
|
||||
{
|
||||
return m_nativeStatus.upload_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::ipOverheadDownloadRate() const
|
||||
{
|
||||
return m_nativeStatus.ip_overhead_download_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::ipOverheadUploadRate() const
|
||||
{
|
||||
return m_nativeStatus.ip_overhead_upload_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::dhtDownloadRate() const
|
||||
{
|
||||
return m_nativeStatus.dht_download_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::dhtUploadRate() const
|
||||
{
|
||||
return m_nativeStatus.dht_upload_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::trackerDownloadRate() const
|
||||
{
|
||||
return m_nativeStatus.tracker_download_rate;
|
||||
}
|
||||
|
||||
int SessionStatus::trackerUploadRate() const
|
||||
{
|
||||
return m_nativeStatus.tracker_upload_rate;
|
||||
}
|
||||
|
||||
qlonglong SessionStatus::totalDownload() const
|
||||
{
|
||||
return m_nativeStatus.total_download;
|
||||
}
|
||||
|
||||
qlonglong SessionStatus::totalUpload() const
|
||||
{
|
||||
return m_nativeStatus.total_upload;
|
||||
}
|
||||
|
||||
qlonglong SessionStatus::totalPayloadDownload() const
|
||||
{
|
||||
return m_nativeStatus.total_payload_download;
|
||||
}
|
||||
|
||||
qlonglong SessionStatus::totalPayloadUpload() const
|
||||
{
|
||||
return m_nativeStatus.total_payload_upload;
|
||||
}
|
||||
|
||||
qlonglong SessionStatus::totalWasted() const
|
||||
{
|
||||
return (m_nativeStatus.total_redundant_bytes + m_nativeStatus.total_failed_bytes);
|
||||
}
|
||||
|
||||
int SessionStatus::diskReadQueue() const
|
||||
{
|
||||
return m_nativeStatus.disk_read_queue;
|
||||
}
|
||||
|
||||
int SessionStatus::diskWriteQueue() const
|
||||
{
|
||||
return m_nativeStatus.disk_write_queue;
|
||||
}
|
||||
|
||||
int SessionStatus::dhtNodes() const
|
||||
{
|
||||
return m_nativeStatus.dht_nodes;
|
||||
}
|
||||
|
||||
int SessionStatus::peersCount() const
|
||||
{
|
||||
return m_nativeStatus.num_peers;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2015, 2017 Vladimir Golovnev <glassez@yandex.ru>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
@@ -29,50 +29,43 @@
|
||||
#ifndef BITTORRENT_SESSIONSTATUS_H
|
||||
#define BITTORRENT_SESSIONSTATUS_H
|
||||
|
||||
#include <libtorrent/session_status.hpp>
|
||||
#include <QtGlobal>
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
class SessionStatus
|
||||
struct SessionStatus
|
||||
{
|
||||
public:
|
||||
SessionStatus(const libtorrent::session_status &nativeStatus);
|
||||
bool hasIncomingConnections = false;
|
||||
|
||||
bool hasIncomingConnections() const;
|
||||
|
||||
// Return current download rate for the BT
|
||||
// Current download rate for the BT
|
||||
// session. Payload means that it only take into
|
||||
// account "useful" part of the rate
|
||||
int payloadDownloadRate() const;
|
||||
quint64 payloadDownloadRate = 0;
|
||||
|
||||
// Return current upload rate for the BT
|
||||
// Current upload rate for the BT
|
||||
// session. Payload means that it only take into
|
||||
// account "useful" part of the rate
|
||||
int payloadUploadRate() const;
|
||||
quint64 payloadUploadRate = 0;
|
||||
|
||||
// Additional download/upload rates
|
||||
int uploadRate() const;
|
||||
int downloadRate() const;
|
||||
int ipOverheadUploadRate() const;
|
||||
int ipOverheadDownloadRate() const;
|
||||
int dhtUploadRate() const;
|
||||
int dhtDownloadRate() const;
|
||||
int trackerUploadRate() const;
|
||||
int trackerDownloadRate() const;
|
||||
quint64 uploadRate = 0;
|
||||
quint64 downloadRate = 0;
|
||||
quint64 ipOverheadUploadRate = 0;
|
||||
quint64 ipOverheadDownloadRate = 0;
|
||||
quint64 dhtUploadRate = 0;
|
||||
quint64 dhtDownloadRate = 0;
|
||||
quint64 trackerUploadRate = 0;
|
||||
quint64 trackerDownloadRate = 0;
|
||||
|
||||
qlonglong totalDownload() const;
|
||||
qlonglong totalUpload() const;
|
||||
qlonglong totalPayloadDownload() const;
|
||||
qlonglong totalPayloadUpload() const;
|
||||
qlonglong totalWasted() const;
|
||||
int diskReadQueue() const;
|
||||
int diskWriteQueue() const;
|
||||
int dhtNodes() const;
|
||||
int peersCount() const;
|
||||
|
||||
private:
|
||||
libtorrent::session_status m_nativeStatus;
|
||||
quint64 totalDownload = 0;
|
||||
quint64 totalUpload = 0;
|
||||
quint64 totalPayloadDownload = 0;
|
||||
quint64 totalPayloadUpload = 0;
|
||||
quint64 totalWasted = 0;
|
||||
quint64 diskReadQueue = 0;
|
||||
quint64 diskWriteQueue = 0;
|
||||
quint64 dhtNodes = 0;
|
||||
quint64 peersCount = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user