mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-23 08:48:07 -06:00
@@ -33,7 +33,7 @@
|
||||
|
||||
#include "base/bittorrent/infohash.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
#include "base/bittorrent/trackerentry.h"
|
||||
#include "base/bittorrent/trackerentrystatus.h"
|
||||
#include "base/path.h"
|
||||
#include "base/tagset.h"
|
||||
#include "base/utils/datetime.h"
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "base/bittorrent/sessionstatus.h"
|
||||
#include "base/bittorrent/torrent.h"
|
||||
#include "base/bittorrent/torrentinfo.h"
|
||||
#include "base/bittorrent/trackerentry.h"
|
||||
#include "base/bittorrent/trackerentrystatus.h"
|
||||
#include "base/global.h"
|
||||
#include "base/net/geoipmanager.h"
|
||||
#include "base/preferences.h"
|
||||
@@ -523,8 +523,8 @@ void SyncController::makeMaindataSnapshot()
|
||||
QVariantMap serializedTorrent = serialize(*torrent);
|
||||
serializedTorrent.remove(KEY_TORRENT_ID);
|
||||
|
||||
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
|
||||
m_knownTrackers[tracker.url].insert(torrentID);
|
||||
for (const BitTorrent::TrackerEntryStatus &status : asConst(torrent->trackers()))
|
||||
m_knownTrackers[status.url].insert(torrentID);
|
||||
|
||||
m_maindataSnapshot.torrents[torrentID.toString()] = serializedTorrent;
|
||||
}
|
||||
@@ -834,11 +834,11 @@ void SyncController::onTorrentAdded(BitTorrent::Torrent *torrent)
|
||||
m_removedTorrents.remove(torrentID);
|
||||
m_updatedTorrents.insert(torrentID);
|
||||
|
||||
for (const BitTorrent::TrackerEntry &trackerEntry : asConst(torrent->trackers()))
|
||||
for (const BitTorrent::TrackerEntryStatus &status : asConst(torrent->trackers()))
|
||||
{
|
||||
m_knownTrackers[trackerEntry.url].insert(torrentID);
|
||||
m_updatedTrackers.insert(trackerEntry.url);
|
||||
m_removedTrackers.remove(trackerEntry.url);
|
||||
m_knownTrackers[status.url].insert(torrentID);
|
||||
m_updatedTrackers.insert(status.url);
|
||||
m_removedTrackers.remove(status.url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -849,9 +849,9 @@ void SyncController::onTorrentAboutToBeRemoved(BitTorrent::Torrent *torrent)
|
||||
m_updatedTorrents.remove(torrentID);
|
||||
m_removedTorrents.insert(torrentID);
|
||||
|
||||
for (const BitTorrent::TrackerEntry &trackerEntry : asConst(torrent->trackers()))
|
||||
for (const BitTorrent::TrackerEntryStatus &status : asConst(torrent->trackers()))
|
||||
{
|
||||
auto iter = m_knownTrackers.find(trackerEntry.url);
|
||||
auto iter = m_knownTrackers.find(status.url);
|
||||
Q_ASSERT(iter != m_knownTrackers.end());
|
||||
if (iter == m_knownTrackers.end()) [[unlikely]]
|
||||
continue;
|
||||
@@ -861,12 +861,12 @@ void SyncController::onTorrentAboutToBeRemoved(BitTorrent::Torrent *torrent)
|
||||
if (torrentIDs.isEmpty())
|
||||
{
|
||||
m_knownTrackers.erase(iter);
|
||||
m_updatedTrackers.remove(trackerEntry.url);
|
||||
m_removedTrackers.insert(trackerEntry.url);
|
||||
m_updatedTrackers.remove(status.url);
|
||||
m_removedTrackers.insert(status.url);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_updatedTrackers.insert(trackerEntry.url);
|
||||
m_updatedTrackers.insert(status.url);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -922,11 +922,12 @@ void SyncController::onTorrentTrackersChanged(BitTorrent::Torrent *torrent)
|
||||
{
|
||||
using namespace BitTorrent;
|
||||
|
||||
const QVector<TrackerEntry> currentTrackerEntries = torrent->trackers();
|
||||
const QVector<TrackerEntryStatus> trackers = torrent->trackers();
|
||||
|
||||
QSet<QString> currentTrackers;
|
||||
currentTrackers.reserve(currentTrackerEntries.size());
|
||||
for (const TrackerEntry ¤tTrackerEntry : currentTrackerEntries)
|
||||
currentTrackers.insert(currentTrackerEntry.url);
|
||||
currentTrackers.reserve(trackers.size());
|
||||
for (const TrackerEntryStatus &status : trackers)
|
||||
currentTrackers.insert(status.url);
|
||||
|
||||
const TorrentID torrentID = torrent->id();
|
||||
Algorithm::removeIf(m_knownTrackers
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include "base/bittorrent/torrent.h"
|
||||
#include "base/bittorrent/torrentdescriptor.h"
|
||||
#include "base/bittorrent/trackerentry.h"
|
||||
#include "base/bittorrent/trackerentrystatus.h"
|
||||
#include "base/interfaces/iapplication.h"
|
||||
#include "base/global.h"
|
||||
#include "base/logger.h"
|
||||
@@ -194,7 +195,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
const int working = static_cast<int>(BitTorrent::TrackerEntryStatus::Working);
|
||||
const int working = static_cast<int>(BitTorrent::TrackerEndpointState::Working);
|
||||
const int disabled = 0;
|
||||
|
||||
const QString privateMsg {QCoreApplication::translate("TrackerListWidget", "This torrent is private")};
|
||||
@@ -500,16 +501,16 @@ void TorrentsController::trackersAction()
|
||||
|
||||
QJsonArray trackerList = getStickyTrackers(torrent);
|
||||
|
||||
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
|
||||
for (const BitTorrent::TrackerEntryStatus &tracker : asConst(torrent->trackers()))
|
||||
{
|
||||
const bool isNotWorking = (tracker.status == BitTorrent::TrackerEntryStatus::NotWorking)
|
||||
|| (tracker.status == BitTorrent::TrackerEntryStatus::TrackerError)
|
||||
|| (tracker.status == BitTorrent::TrackerEntryStatus::Unreachable);
|
||||
const bool isNotWorking = (tracker.state == BitTorrent::TrackerEndpointState::NotWorking)
|
||||
|| (tracker.state == BitTorrent::TrackerEndpointState::TrackerError)
|
||||
|| (tracker.state == BitTorrent::TrackerEndpointState::Unreachable);
|
||||
trackerList << QJsonObject
|
||||
{
|
||||
{KEY_TRACKER_URL, tracker.url},
|
||||
{KEY_TRACKER_TIER, tracker.tier},
|
||||
{KEY_TRACKER_STATUS, static_cast<int>((isNotWorking ? BitTorrent::TrackerEntryStatus::NotWorking : tracker.status))},
|
||||
{KEY_TRACKER_STATUS, static_cast<int>((isNotWorking ? BitTorrent::TrackerEndpointState::NotWorking : tracker.state))},
|
||||
{KEY_TRACKER_MSG, tracker.message},
|
||||
{KEY_TRACKER_PEERS_COUNT, tracker.numPeers},
|
||||
{KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds},
|
||||
@@ -800,7 +801,7 @@ void TorrentsController::addTrackersAction()
|
||||
if (!torrent)
|
||||
throw APIError(APIErrorType::NotFound);
|
||||
|
||||
const QVector<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(params()[u"urls"_s]);
|
||||
const QList<BitTorrent::TrackerEntry> entries = BitTorrent::parseTrackerEntries(params()[u"urls"_s]);
|
||||
torrent->addTrackers(entries);
|
||||
}
|
||||
|
||||
@@ -823,23 +824,35 @@ void TorrentsController::editTrackerAction()
|
||||
if (!newTrackerUrl.isValid())
|
||||
throw APIError(APIErrorType::BadParams, u"New tracker URL is invalid"_s);
|
||||
|
||||
QVector<BitTorrent::TrackerEntry> trackers = torrent->trackers();
|
||||
const QList<BitTorrent::TrackerEntryStatus> currentTrackers = torrent->trackers();
|
||||
QList<BitTorrent::TrackerEntry> entries;
|
||||
entries.reserve(currentTrackers.size());
|
||||
|
||||
bool match = false;
|
||||
for (BitTorrent::TrackerEntry &tracker : trackers)
|
||||
for (const BitTorrent::TrackerEntryStatus &tracker : currentTrackers)
|
||||
{
|
||||
const QUrl trackerUrl {tracker.url};
|
||||
|
||||
if (trackerUrl == newTrackerUrl)
|
||||
throw APIError(APIErrorType::Conflict, u"New tracker URL already exists"_s);
|
||||
|
||||
BitTorrent::TrackerEntry entry
|
||||
{
|
||||
.url = tracker.url,
|
||||
.tier = tracker.tier
|
||||
};
|
||||
|
||||
if (trackerUrl == origTrackerUrl)
|
||||
{
|
||||
match = true;
|
||||
tracker.url = newTrackerUrl.toString();
|
||||
entry.url = newTrackerUrl.toString();
|
||||
}
|
||||
entries.append(entry);
|
||||
}
|
||||
if (!match)
|
||||
throw APIError(APIErrorType::Conflict, u"Tracker not found"_s);
|
||||
|
||||
torrent->replaceTrackers(trackers);
|
||||
torrent->replaceTrackers(entries);
|
||||
|
||||
if (!torrent->isStopped())
|
||||
torrent->forceReannounce();
|
||||
|
||||
Reference in New Issue
Block a user