mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-10 17:35:00 -06:00
committed by
GitHub
parent
f68bc3fef9
commit
c45dfb6662
@@ -518,7 +518,7 @@ namespace BitTorrent
|
||||
void torrentTagRemoved(Torrent *torrent, const Tag &tag);
|
||||
void trackerError(Torrent *torrent, const QString &tracker);
|
||||
void trackersAdded(Torrent *torrent, const QList<TrackerEntry> &trackers);
|
||||
void trackersChanged(Torrent *torrent);
|
||||
void trackersReset(Torrent *torrent, const QList<TrackerEntryStatus> &oldEntries, const QList<TrackerEntry> &newEntries);
|
||||
void trackersRemoved(Torrent *torrent, const QStringList &trackers);
|
||||
void trackerSuccess(Torrent *torrent, const QString &tracker);
|
||||
void trackerWarning(Torrent *torrent, const QString &tracker);
|
||||
|
||||
@@ -5279,9 +5279,9 @@ void SessionImpl::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const
|
||||
emit trackersRemoved(torrent, deletedTrackers);
|
||||
}
|
||||
|
||||
void SessionImpl::handleTorrentTrackersChanged(TorrentImpl *const torrent)
|
||||
void SessionImpl::handleTorrentTrackersReset(TorrentImpl *const torrent, const QList<TrackerEntryStatus> &oldEntries, const QList<TrackerEntry> &newEntries)
|
||||
{
|
||||
emit trackersChanged(torrent);
|
||||
emit trackersReset(torrent, oldEntries, newEntries);
|
||||
}
|
||||
|
||||
void SessionImpl::handleTorrentUrlSeedsAdded(TorrentImpl *const torrent, const QList<QUrl> &newUrlSeeds)
|
||||
|
||||
@@ -474,7 +474,7 @@ namespace BitTorrent
|
||||
void handleTorrentFinished(TorrentImpl *torrent);
|
||||
void handleTorrentTrackersAdded(TorrentImpl *torrent, const QList<TrackerEntry> &newTrackers);
|
||||
void handleTorrentTrackersRemoved(TorrentImpl *torrent, const QStringList &deletedTrackers);
|
||||
void handleTorrentTrackersChanged(TorrentImpl *torrent);
|
||||
void handleTorrentTrackersReset(TorrentImpl *torrent, const QList<TrackerEntryStatus> &oldEntries, const QList<TrackerEntry> &newEntries);
|
||||
void handleTorrentUrlSeedsAdded(TorrentImpl *torrent, const QList<QUrl> &newUrlSeeds);
|
||||
void handleTorrentUrlSeedsRemoved(TorrentImpl *torrent, const QList<QUrl> &urlSeeds);
|
||||
void handleTorrentResumeDataReady(TorrentImpl *torrent, LoadTorrentParams data);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "base/pathfwd.h"
|
||||
#include "base/tagset.h"
|
||||
#include "sharelimitaction.h"
|
||||
#include "torrentannouncestatus.h"
|
||||
#include "torrentcontenthandler.h"
|
||||
|
||||
class QBitArray;
|
||||
@@ -290,6 +291,7 @@ namespace BitTorrent
|
||||
virtual int connectionsCount() const = 0;
|
||||
virtual int connectionsLimit() const = 0;
|
||||
virtual qlonglong nextAnnounce() const = 0;
|
||||
virtual TorrentAnnounceStatus announceStatus() const = 0;
|
||||
|
||||
virtual void setName(const QString &name) = 0;
|
||||
virtual void setSequentialDownload(bool enable) = 0;
|
||||
|
||||
47
src/base/bittorrent/torrentannouncestatus.h
Normal file
47
src/base/bittorrent/torrentannouncestatus.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2025 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QFlags>
|
||||
|
||||
namespace BitTorrent
|
||||
{
|
||||
enum class TorrentAnnounceStatusFlag
|
||||
{
|
||||
HasNoProblem = 0,
|
||||
|
||||
HasWarning = 1,
|
||||
HasTrackerError = 2,
|
||||
HasOtherError = 4
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(TorrentAnnounceStatus, TorrentAnnounceStatusFlag);
|
||||
}
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BitTorrent::TorrentAnnounceStatus);
|
||||
@@ -718,9 +718,9 @@ void TorrentImpl::replaceTrackers(QList<TrackerEntry> trackers)
|
||||
|
||||
std::vector<lt::announce_entry> nativeTrackers;
|
||||
nativeTrackers.reserve(trackers.size());
|
||||
m_trackerEntryStatuses.clear();
|
||||
const auto oldEntries = std::exchange(m_trackerEntryStatuses, {});
|
||||
|
||||
for (const TrackerEntry &tracker : trackers)
|
||||
for (const TrackerEntry &tracker : asConst(trackers))
|
||||
{
|
||||
nativeTrackers.emplace_back(makeNativeAnnounceEntry(tracker.url, tracker.tier));
|
||||
m_trackerEntryStatuses.append({tracker.url, tracker.tier});
|
||||
@@ -734,7 +734,7 @@ void TorrentImpl::replaceTrackers(QList<TrackerEntry> trackers)
|
||||
clearPeers();
|
||||
|
||||
deferredRequestResumeData();
|
||||
m_session->handleTorrentTrackersChanged(this);
|
||||
m_session->handleTorrentTrackersReset(this, oldEntries, trackers);
|
||||
}
|
||||
|
||||
QList<QUrl> TorrentImpl::urlSeeds() const
|
||||
@@ -1557,6 +1557,46 @@ qlonglong TorrentImpl::nextAnnounce() const
|
||||
return lt::total_seconds(m_nativeStatus.next_announce);
|
||||
}
|
||||
|
||||
TorrentAnnounceStatus TorrentImpl::announceStatus() const
|
||||
{
|
||||
if (m_announceStatus)
|
||||
return *m_announceStatus;
|
||||
|
||||
TorrentAnnounceStatus announceStatus = TorrentAnnounceStatusFlag::HasNoProblem;
|
||||
for (const TrackerEntryStatus &trackerEntryStatus : asConst(m_trackerEntryStatuses))
|
||||
{
|
||||
switch (trackerEntryStatus.state)
|
||||
{
|
||||
case BitTorrent::TrackerEndpointState::Working:
|
||||
if (!announceStatus.testFlag(TorrentAnnounceStatusFlag::HasWarning))
|
||||
{
|
||||
const bool hasWarningMessage = std::ranges::any_of(trackerEntryStatus.endpoints
|
||||
, [](const TrackerEndpointStatus &endpointEntry)
|
||||
{
|
||||
return !endpointEntry.message.isEmpty() && (endpointEntry.state == BitTorrent::TrackerEndpointState::Working);
|
||||
});
|
||||
announceStatus.setFlag(TorrentAnnounceStatusFlag::HasWarning, hasWarningMessage);
|
||||
}
|
||||
break;
|
||||
|
||||
case BitTorrent::TrackerEndpointState::NotWorking:
|
||||
case BitTorrent::TrackerEndpointState::Unreachable:
|
||||
announceStatus.setFlag(TorrentAnnounceStatusFlag::HasOtherError);
|
||||
break;
|
||||
|
||||
case BitTorrent::TrackerEndpointState::TrackerError:
|
||||
announceStatus.setFlag(TorrentAnnounceStatusFlag::HasTrackerError);
|
||||
break;
|
||||
|
||||
case BitTorrent::TrackerEndpointState::NotContacted:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
m_announceStatus = announceStatus;
|
||||
return *m_announceStatus;
|
||||
}
|
||||
|
||||
qreal TorrentImpl::popularity() const
|
||||
{
|
||||
// in order to produce floating-point numbers using `std::chrono::duration_cast`,
|
||||
@@ -1743,6 +1783,7 @@ TrackerEntryStatus TorrentImpl::updateTrackerEntryStatus(const lt::announce_entr
|
||||
#endif
|
||||
|
||||
::updateTrackerEntryStatus(*it, announceEntry, btProtocols, updateInfo);
|
||||
m_announceStatus.reset();
|
||||
|
||||
return *it;
|
||||
}
|
||||
@@ -1758,6 +1799,8 @@ void TorrentImpl::resetTrackerEntryStatuses()
|
||||
status.url = tempUrl;
|
||||
status.tier = tempTier;
|
||||
}
|
||||
|
||||
m_announceStatus = TorrentAnnounceStatusFlag::HasNoProblem;
|
||||
}
|
||||
|
||||
std::shared_ptr<const libtorrent::torrent_info> TorrentImpl::nativeTorrentInfo() const
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Bittorrent Client using Qt and libtorrent.
|
||||
* Copyright (C) 2015-2023 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2015-2025 Vladimir Golovnev <glassez@yandex.ru>
|
||||
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
@@ -217,6 +217,7 @@ namespace BitTorrent
|
||||
int connectionsCount() const override;
|
||||
int connectionsLimit() const override;
|
||||
qlonglong nextAnnounce() const override;
|
||||
TorrentAnnounceStatus announceStatus() const override;
|
||||
|
||||
void setName(const QString &name) override;
|
||||
void setSequentialDownload(bool enable) override;
|
||||
@@ -349,6 +350,7 @@ namespace BitTorrent
|
||||
MaintenanceJob m_maintenanceJob = MaintenanceJob::None;
|
||||
|
||||
QList<TrackerEntryStatus> m_trackerEntryStatuses;
|
||||
mutable std::optional<TorrentAnnounceStatus> m_announceStatus;
|
||||
QList<QUrl> m_urlSeeds;
|
||||
FileErrorInfo m_lastFileError;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user