mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-22 22:33:34 -07:00
Avoid using QDateTime for announce timestamps
This commit is contained in:
parent
15ea836bb9
commit
1cc202e4ee
6 changed files with 35 additions and 36 deletions
|
@ -58,6 +58,7 @@
|
|||
#include <libtorrent/session_status.hpp>
|
||||
#include <libtorrent/torrent_info.hpp>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDeadlineTimer>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
@ -106,6 +107,7 @@
|
|||
#include "torrentimpl.h"
|
||||
#include "tracker.h"
|
||||
#include "trackerentry.h"
|
||||
#include "trackerentrystatus.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
using namespace BitTorrent;
|
||||
|
@ -5515,7 +5517,7 @@ void SessionImpl::readAlerts()
|
|||
// cache current datetime of Qt and libtorrent clocks in order
|
||||
// to optimize conversion of time points from lt to Qt clocks
|
||||
m_ltNow = lt::clock_type::now();
|
||||
m_qNow = QDateTime::currentDateTime();
|
||||
m_currentSecsSinceEpoch = QDateTime::currentSecsSinceEpoch();
|
||||
|
||||
const std::vector<lt::alert *> alerts = getPendingAlerts();
|
||||
|
||||
|
@ -6396,8 +6398,8 @@ void SessionImpl::handleRemovedTorrent(const TorrentID &torrentID, const QString
|
|||
m_removingTorrents.erase(removingTorrentDataIter);
|
||||
}
|
||||
|
||||
QDateTime SessionImpl::fromLTTimePoint32(const lt::time_point32 &timePoint) const
|
||||
qint64 SessionImpl::toSecsSinceEpoch(const lt::time_point32 &timePoint) const
|
||||
{
|
||||
const auto secsSinceNow = lt::duration_cast<lt::seconds>(timePoint - m_ltNow + lt::milliseconds(500)).count();
|
||||
return m_qNow.addSecs(secsSinceNow);
|
||||
return m_currentSecsSinceEpoch + secsSinceNow;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,6 @@
|
|||
#include <libtorrent/torrent_handle.hpp>
|
||||
|
||||
#include <QtContainerFwd>
|
||||
#include <QDateTime>
|
||||
#include <QElapsedTimer>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
|
@ -55,7 +54,6 @@
|
|||
#include "session.h"
|
||||
#include "sessionstatus.h"
|
||||
#include "torrentinfo.h"
|
||||
#include "trackerentrystatus.h"
|
||||
|
||||
class QString;
|
||||
class QTimer;
|
||||
|
@ -479,7 +477,7 @@ namespace BitTorrent
|
|||
void addMappedPorts(const QSet<quint16> &ports);
|
||||
void removeMappedPorts(const QSet<quint16> &ports);
|
||||
|
||||
QDateTime fromLTTimePoint32(const lt::time_point32 &timePoint) const;
|
||||
qint64 toSecsSinceEpoch(const lt::time_point32 &timePoint) const;
|
||||
|
||||
template <typename Func>
|
||||
void invoke(Func &&func)
|
||||
|
@ -832,7 +830,7 @@ namespace BitTorrent
|
|||
|
||||
QList<TorrentImpl *> m_pendingFinishedTorrents;
|
||||
|
||||
QDateTime m_qNow;
|
||||
qint64 m_currentSecsSinceEpoch = 0;
|
||||
lt::clock_type::time_point m_ltNow;
|
||||
|
||||
friend void Session::initInstance();
|
||||
|
|
|
@ -106,10 +106,10 @@ namespace
|
|||
return endpointName;
|
||||
}
|
||||
|
||||
template <typename FromLTTimePoint32Func>
|
||||
template <typename ToSecsSinceEpochFunc>
|
||||
void updateTrackerEntryStatus(TrackerEntryStatus &trackerEntryStatus, const lt::announce_entry &nativeEntry
|
||||
, const QSet<int> &btProtocols, const QHash<lt::tcp::endpoint, QMap<int, int>> &updateInfo
|
||||
, const FromLTTimePoint32Func &fromLTTimePoint32)
|
||||
, const ToSecsSinceEpochFunc &toSecsSinceEpoch)
|
||||
{
|
||||
Q_ASSERT(trackerEntryStatus.url == QString::fromStdString(nativeEntry.url));
|
||||
|
||||
|
@ -146,8 +146,8 @@ namespace
|
|||
trackerEndpointStatus.numSeeds = ltAnnounceInfo.scrape_complete;
|
||||
trackerEndpointStatus.numLeeches = ltAnnounceInfo.scrape_incomplete;
|
||||
trackerEndpointStatus.numDownloaded = ltAnnounceInfo.scrape_downloaded;
|
||||
trackerEndpointStatus.nextAnnounceTime = fromLTTimePoint32(ltAnnounceInfo.next_announce);
|
||||
trackerEndpointStatus.minAnnounceTime = fromLTTimePoint32(ltAnnounceInfo.min_announce);
|
||||
trackerEndpointStatus.nextAnnounceTime = toSecsSinceEpoch(ltAnnounceInfo.next_announce);
|
||||
trackerEndpointStatus.minAnnounceTime = toSecsSinceEpoch(ltAnnounceInfo.min_announce);
|
||||
|
||||
if (ltAnnounceInfo.updating)
|
||||
{
|
||||
|
@ -238,8 +238,8 @@ namespace
|
|||
trackerEntryStatus.numSeeds = -1;
|
||||
trackerEntryStatus.numLeeches = -1;
|
||||
trackerEntryStatus.numDownloaded = -1;
|
||||
trackerEntryStatus.nextAnnounceTime = QDateTime();
|
||||
trackerEntryStatus.minAnnounceTime = QDateTime();
|
||||
trackerEntryStatus.nextAnnounceTime = 0;
|
||||
trackerEntryStatus.minAnnounceTime = 0;
|
||||
trackerEntryStatus.message.clear();
|
||||
|
||||
for (const TrackerEndpointStatus &endpointStatus : asConst(trackerEntryStatus.endpoints))
|
||||
|
@ -251,7 +251,7 @@ namespace
|
|||
|
||||
if (endpointStatus.state == trackerEntryStatus.state)
|
||||
{
|
||||
if (!trackerEntryStatus.nextAnnounceTime.isValid() || (trackerEntryStatus.nextAnnounceTime > endpointStatus.nextAnnounceTime))
|
||||
if ((trackerEntryStatus.nextAnnounceTime <= 0) || (trackerEntryStatus.nextAnnounceTime > endpointStatus.nextAnnounceTime))
|
||||
{
|
||||
trackerEntryStatus.nextAnnounceTime = endpointStatus.nextAnnounceTime;
|
||||
trackerEntryStatus.minAnnounceTime = endpointStatus.minAnnounceTime;
|
||||
|
@ -1774,11 +1774,11 @@ TrackerEntryStatus TorrentImpl::updateTrackerEntryStatus(const lt::announce_entr
|
|||
const QSet<int> btProtocols {1};
|
||||
#endif
|
||||
|
||||
const auto fromLTTimePoint32 = [this](const lt::time_point32 &timePoint)
|
||||
const auto toSecsSinceEpoch = [this](const lt::time_point32 &timePoint)
|
||||
{
|
||||
return m_session->fromLTTimePoint32(timePoint);
|
||||
return m_session->toSecsSinceEpoch(timePoint);
|
||||
};
|
||||
::updateTrackerEntryStatus(*it, announceEntry, btProtocols, updateInfo, fromLTTimePoint32);
|
||||
::updateTrackerEntryStatus(*it, announceEntry, btProtocols, updateInfo, toSecsSinceEpoch);
|
||||
|
||||
return *it;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2015-2024 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
|
||||
|
@ -28,7 +28,6 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
|
||||
|
@ -59,8 +58,8 @@ namespace BitTorrent
|
|||
int numLeeches = -1;
|
||||
int numDownloaded = -1;
|
||||
|
||||
QDateTime nextAnnounceTime {};
|
||||
QDateTime minAnnounceTime {};
|
||||
qint64 nextAnnounceTime = 0;
|
||||
qint64 minAnnounceTime = 0;
|
||||
};
|
||||
|
||||
struct TrackerEntryStatus
|
||||
|
@ -76,8 +75,8 @@ namespace BitTorrent
|
|||
int numLeeches = -1;
|
||||
int numDownloaded = -1;
|
||||
|
||||
QDateTime nextAnnounceTime {};
|
||||
QDateTime minAnnounceTime {};
|
||||
qint64 nextAnnounceTime = 0;
|
||||
qint64 minAnnounceTime = 0;
|
||||
|
||||
QHash<std::pair<QString, int>, TrackerEndpointStatus> endpoints {};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -40,6 +40,7 @@
|
|||
#include <boost/multi_index/tag.hpp>
|
||||
|
||||
#include <QColor>
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
#include <QPointer>
|
||||
#include <QScopeGuard>
|
||||
|
@ -141,12 +142,12 @@ struct TrackerListModel::Item final
|
|||
int numLeeches = -1;
|
||||
int numDownloaded = -1;
|
||||
|
||||
QDateTime nextAnnounceTime {};
|
||||
QDateTime minAnnounceTime {};
|
||||
qint64 nextAnnounceTime = 0;
|
||||
qint64 minAnnounceTime = 0;
|
||||
|
||||
qint64 secsToNextAnnounce = 0;
|
||||
qint64 secsToMinAnnounce = 0;
|
||||
QDateTime announceTimestamp;
|
||||
qint64 announceTimestamp = 0;
|
||||
|
||||
std::weak_ptr<Item> parentItem {};
|
||||
|
||||
|
@ -211,7 +212,7 @@ void TrackerListModel::Item::fillFrom(const BitTorrent::TrackerEntryStatus &trac
|
|||
minAnnounceTime = trackerEntryStatus.minAnnounceTime;
|
||||
secsToNextAnnounce = 0;
|
||||
secsToMinAnnounce = 0;
|
||||
announceTimestamp = QDateTime();
|
||||
announceTimestamp = 0;
|
||||
}
|
||||
|
||||
void TrackerListModel::Item::fillFrom(const BitTorrent::TrackerEndpointStatus &endpointStatus)
|
||||
|
@ -230,7 +231,7 @@ void TrackerListModel::Item::fillFrom(const BitTorrent::TrackerEndpointStatus &e
|
|||
minAnnounceTime = endpointStatus.minAnnounceTime;
|
||||
secsToNextAnnounce = 0;
|
||||
secsToMinAnnounce = 0;
|
||||
announceTimestamp = QDateTime();
|
||||
announceTimestamp = 0;
|
||||
}
|
||||
|
||||
TrackerListModel::TrackerListModel(BitTorrent::Session *btSession, QObject *parent)
|
||||
|
@ -369,7 +370,7 @@ void TrackerListModel::populate()
|
|||
for (const BitTorrent::TrackerEntryStatus &status : trackers)
|
||||
addTrackerItem(status);
|
||||
|
||||
m_announceTimestamp = QDateTime::currentDateTime();
|
||||
m_announceTimestamp = QDateTime::currentSecsSinceEpoch();
|
||||
m_announceRefreshTimer->start(ANNOUNCE_TIME_REFRESH_INTERVAL);
|
||||
}
|
||||
|
||||
|
@ -448,7 +449,7 @@ void TrackerListModel::refreshAnnounceTimes()
|
|||
if (!m_torrent)
|
||||
return;
|
||||
|
||||
m_announceTimestamp = QDateTime::currentDateTime();
|
||||
m_announceTimestamp = QDateTime::currentSecsSinceEpoch();
|
||||
emit dataChanged(index(0, COL_NEXT_ANNOUNCE), index((rowCount() - 1), COL_MIN_ANNOUNCE));
|
||||
for (int i = 0; i < rowCount(); ++i)
|
||||
{
|
||||
|
@ -545,8 +546,8 @@ QVariant TrackerListModel::data(const QModelIndex &index, const int role) const
|
|||
|
||||
if (itemPtr->announceTimestamp != m_announceTimestamp)
|
||||
{
|
||||
itemPtr->secsToNextAnnounce = std::max<qint64>(0, m_announceTimestamp.secsTo(itemPtr->nextAnnounceTime));
|
||||
itemPtr->secsToMinAnnounce = std::max<qint64>(0, m_announceTimestamp.secsTo(itemPtr->minAnnounceTime));
|
||||
itemPtr->secsToNextAnnounce = std::max<qint64>(0, (itemPtr->nextAnnounceTime - m_announceTimestamp));
|
||||
itemPtr->secsToMinAnnounce = std::max<qint64>(0, (itemPtr->minAnnounceTime - m_announceTimestamp));
|
||||
itemPtr->announceTimestamp = m_announceTimestamp;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2023 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2023-2024 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include <QtContainerFwd>
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "base/bittorrent/trackerentrystatus.h"
|
||||
|
||||
|
@ -115,6 +114,6 @@ private:
|
|||
class Items;
|
||||
std::unique_ptr<Items> m_items;
|
||||
|
||||
QDateTime m_announceTimestamp;
|
||||
qint64 m_announceTimestamp = 0;
|
||||
QTimer *m_announceRefreshTimer = nullptr;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue