Browse Source

Improve tracker entries handling

adaptive-webui-19844
Vladimir Golovnev (Glassez) 4 years ago
parent
commit
7a8c05dc7c
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 2
      src/base/bittorrent/magneturi.cpp
  2. 6
      src/base/bittorrent/session.cpp
  3. 2
      src/base/bittorrent/session.h
  4. 2
      src/base/bittorrent/torrent.h
  5. 128
      src/base/bittorrent/torrentimpl.cpp
  6. 2
      src/base/bittorrent/torrentinfo.cpp
  7. 2
      src/base/bittorrent/torrentinfo.h
  8. 132
      src/base/bittorrent/trackerentry.cpp
  9. 43
      src/base/bittorrent/trackerentry.h
  10. 40
      src/gui/properties/trackerlistwidget.cpp
  11. 4
      src/gui/properties/trackersadditiondialog.cpp
  12. 8
      src/gui/trackerentriesdialog.cpp
  13. 2
      src/gui/trackerentriesdialog.h
  14. 8
      src/gui/transferlistfilterswidget.cpp
  15. 2
      src/gui/transferlistfilterswidget.h
  16. 2
      src/webui/api/synccontroller.cpp
  17. 24
      src/webui/api/torrentscontroller.cpp

2
src/base/bittorrent/magneturi.cpp

@ -78,7 +78,7 @@ MagnetUri::MagnetUri(const QString &source)
m_trackers.reserve(m_addTorrentParams.trackers.size()); m_trackers.reserve(m_addTorrentParams.trackers.size());
for (const std::string &tracker : m_addTorrentParams.trackers) for (const std::string &tracker : m_addTorrentParams.trackers)
m_trackers.append(lt::announce_entry {tracker}); m_trackers.append({QString::fromStdString(tracker)});
m_urlSeeds.reserve(m_addTorrentParams.url_seeds.size()); m_urlSeeds.reserve(m_addTorrentParams.url_seeds.size());
for (const std::string &urlSeed : m_addTorrentParams.url_seeds) for (const std::string &urlSeed : m_addTorrentParams.url_seeds)

6
src/base/bittorrent/session.cpp

@ -1604,7 +1604,7 @@ void Session::populateAdditionalTrackers()
{ {
tracker = tracker.trimmed(); tracker = tracker.trimmed();
if (!tracker.isEmpty()) if (!tracker.isEmpty())
m_additionalTrackerList << tracker.toString(); m_additionalTrackerList.append({tracker.toString()});
} }
} }
@ -3809,7 +3809,7 @@ void Session::handleTorrentTrackersAdded(TorrentImpl *const torrent, const QVect
torrent->saveResumeData(); torrent->saveResumeData();
for (const TrackerEntry &newTracker : newTrackers) for (const TrackerEntry &newTracker : newTrackers)
LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name())); LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url, torrent->name()));
emit trackersAdded(torrent, newTrackers); emit trackersAdded(torrent, newTrackers);
if (torrent->trackers().size() == newTrackers.size()) if (torrent->trackers().size() == newTrackers.size())
emit trackerlessStateChanged(torrent, false); emit trackerlessStateChanged(torrent, false);
@ -3821,7 +3821,7 @@ void Session::handleTorrentTrackersRemoved(TorrentImpl *const torrent, const QVe
torrent->saveResumeData(); torrent->saveResumeData();
for (const TrackerEntry &deletedTracker : deletedTrackers) for (const TrackerEntry &deletedTracker : deletedTrackers)
LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name())); LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url, torrent->name()));
emit trackersRemoved(torrent, deletedTrackers); emit trackersRemoved(torrent, deletedTrackers);
if (torrent->trackers().empty()) if (torrent->trackers().empty())
emit trackerlessStateChanged(torrent, true); emit trackerlessStateChanged(torrent, true);

2
src/base/bittorrent/session.h

@ -99,8 +99,8 @@ namespace BitTorrent
class Torrent; class Torrent;
class TorrentImpl; class TorrentImpl;
class Tracker; class Tracker;
class TrackerEntry;
struct LoadTorrentParams; struct LoadTorrentParams;
struct TrackerEntry;
enum class MoveStorageMode; enum class MoveStorageMode;

2
src/base/bittorrent/torrent.h

@ -45,8 +45,8 @@ namespace BitTorrent
class InfoHash; class InfoHash;
class PeerInfo; class PeerInfo;
class TorrentInfo; class TorrentInfo;
class TrackerEntry;
struct PeerAddress; struct PeerAddress;
struct TrackerEntry;
enum class TorrentOperatingMode enum class TorrentOperatingMode
{ {

128
src/base/bittorrent/torrentimpl.cpp

@ -47,6 +47,10 @@
#include <libtorrent/version.hpp> #include <libtorrent/version.hpp>
#include <libtorrent/write_resume_data.hpp> #include <libtorrent/write_resume_data.hpp>
#if (LIBTORRENT_VERSION_NUM >= 20000)
#include <libtorrent/info_hash.hpp>
#endif
#include <QBitArray> #include <QBitArray>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
@ -96,6 +100,114 @@ namespace
entryList.emplace_back(setValue.toStdString()); entryList.emplace_back(setValue.toStdString());
return entryList; return entryList;
} }
lt::announce_entry makeNativeAnnouncerEntry(const QString &url, const int tier)
{
lt::announce_entry entry {url.toStdString()};
entry.tier = tier;
return entry;
}
#if (LIBTORRENT_VERSION_NUM >= 20000)
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry, const lt::info_hash_t &hashes)
#else
TrackerEntry fromNativeAnnouncerEntry(const lt::announce_entry &nativeEntry)
#endif
{
TrackerEntry trackerEntry {QString::fromStdString(nativeEntry.url), nativeEntry.tier};
int numUpdating = 0;
int numWorking = 0;
int numNotContacted = 0;
#if (LIBTORRENT_VERSION_NUM >= 20000)
const int numEndpoints = nativeEntry.endpoints.size() * ((hashes.has_v1() && hashes.has_v2()) ? 2 : 1);
trackerEntry.endpoints.reserve(numEndpoints);
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
{
for (const auto protocolVersion : {lt::protocol_version::V1, lt::protocol_version::V2})
{
if (hashes.has(protocolVersion))
{
const lt::announce_infohash &infoHash = endpoint.info_hashes[protocolVersion];
TrackerEntry::EndpointStats trackerEndpoint;
trackerEndpoint.protocolVersion = (protocolVersion == lt::protocol_version::V1) ? 1 : 2;
trackerEndpoint.numSeeds = infoHash.scrape_complete;
trackerEndpoint.numLeeches = infoHash.scrape_incomplete;
trackerEndpoint.numDownloaded = infoHash.scrape_downloaded;
if (infoHash.updating)
{
trackerEndpoint.status = TrackerEntry::Updating;
++numUpdating;
}
else if (infoHash.fails > 0)
{
trackerEndpoint.status = TrackerEntry::NotWorking;
}
else if (nativeEntry.verified)
{
trackerEndpoint.status = TrackerEntry::Working;
++numWorking;
}
else
{
trackerEndpoint.status = TrackerEntry::NotContacted;
++numNotContacted;
}
trackerEntry.endpoints.append(trackerEndpoint);
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, infoHash.scrape_complete);
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, infoHash.scrape_incomplete);
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, infoHash.scrape_downloaded);
}
}
}
#else
trackerEntry.endpoints.reserve(nativeEntry.endpoints.size());
for (const lt::announce_endpoint &endpoint : nativeEntry.endpoints)
{
TrackerEntry::EndpointStats trackerEndpoint;
trackerEndpoint.numSeeds = endpoint.scrape_complete;
trackerEndpoint.numLeeches = endpoint.scrape_incomplete;
trackerEndpoint.numDownloaded = endpoint.scrape_downloaded;
if (endpoint.updating)
{
trackerEndpoint.status = TrackerEntry::Updating;
++numUpdating;
}
else if (endpoint.fails > 0)
{
trackerEndpoint.status = TrackerEntry::NotWorking;
}
else if (nativeEntry.verified)
{
trackerEndpoint.status = TrackerEntry::Working;
++numWorking;
}
else
{
trackerEndpoint.status = TrackerEntry::NotContacted;
++numNotContacted;
}
trackerEntry.endpoints.append(trackerEndpoint);
trackerEntry.numSeeds = std::max(trackerEntry.numSeeds, endpoint.scrape_complete);
trackerEntry.numLeeches = std::max(trackerEntry.numLeeches, endpoint.scrape_incomplete);
trackerEntry.numDownloaded = std::max(trackerEntry.numDownloaded, endpoint.scrape_downloaded);
}
#endif
if (numUpdating > 0)
trackerEntry.status = TrackerEntry::Updating;
else if (numWorking > 0)
trackerEntry.status = TrackerEntry::Working;
else if (numNotContacted > 0)
trackerEntry.status = TrackerEntry::NotContacted;
else
trackerEntry.status = TrackerEntry::NotWorking;
return trackerEntry;
}
} }
// TorrentImpl // TorrentImpl
@ -311,7 +423,11 @@ QVector<TrackerEntry> TorrentImpl::trackers() const
entries.reserve(nativeTrackers.size()); entries.reserve(nativeTrackers.size());
for (const lt::announce_entry &tracker : nativeTrackers) for (const lt::announce_entry &tracker : nativeTrackers)
entries << tracker; #if (LIBTORRENT_VERSION_NUM >= 20000)
entries << fromNativeAnnouncerEntry(tracker, m_nativeHandle.info_hashes());
#else
entries << fromNativeAnnouncerEntry(tracker);
#endif
return entries; return entries;
} }
@ -325,7 +441,7 @@ void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers)
{ {
QSet<TrackerEntry> currentTrackers; QSet<TrackerEntry> currentTrackers;
for (const lt::announce_entry &entry : m_nativeHandle.trackers()) for (const lt::announce_entry &entry : m_nativeHandle.trackers())
currentTrackers << entry; currentTrackers.insert({QString::fromStdString(entry.url), entry.tier});
QVector<TrackerEntry> newTrackers; QVector<TrackerEntry> newTrackers;
newTrackers.reserve(trackers.size()); newTrackers.reserve(trackers.size());
@ -334,7 +450,7 @@ void TorrentImpl::addTrackers(const QVector<TrackerEntry> &trackers)
{ {
if (!currentTrackers.contains(tracker)) if (!currentTrackers.contains(tracker))
{ {
m_nativeHandle.add_tracker(tracker.nativeEntry()); m_nativeHandle.add_tracker(makeNativeAnnouncerEntry(tracker.url, tracker.tier));
newTrackers << tracker; newTrackers << tracker;
} }
} }
@ -355,7 +471,7 @@ void TorrentImpl::replaceTrackers(const QVector<TrackerEntry> &trackers)
for (const TrackerEntry &tracker : trackers) for (const TrackerEntry &tracker : trackers)
{ {
nativeTrackers.emplace_back(tracker.nativeEntry()); nativeTrackers.emplace_back(makeNativeAnnouncerEntry(tracker.url, tracker.tier));
if (!currentTrackers.removeOne(tracker)) if (!currentTrackers.removeOne(tracker))
newTrackers << tracker; newTrackers << tracker;
@ -1496,9 +1612,9 @@ void TorrentImpl::handleTrackerErrorAlert(const lt::tracker_error_alert *p)
const QVector<TrackerEntry> trackerList = trackers(); const QVector<TrackerEntry> trackerList = trackers();
const auto iter = std::find_if(trackerList.cbegin(), trackerList.cend(), [&trackerUrl](const TrackerEntry &entry) const auto iter = std::find_if(trackerList.cbegin(), trackerList.cend(), [&trackerUrl](const TrackerEntry &entry)
{ {
return (entry.url() == trackerUrl); return (entry.url == trackerUrl);
}); });
if ((iter != trackerList.cend()) && (iter->status() == TrackerEntry::NotWorking)) if ((iter != trackerList.cend()) && (iter->status == TrackerEntry::NotWorking))
m_session->handleTorrentTrackerError(this, trackerUrl); m_session->handleTorrentTrackerError(this, trackerUrl);
} }

2
src/base/bittorrent/torrentinfo.cpp

@ -302,7 +302,7 @@ QVector<TrackerEntry> TorrentInfo::trackers() const
ret.reserve(trackers.size()); ret.reserve(trackers.size());
for (const lt::announce_entry &tracker : trackers) for (const lt::announce_entry &tracker : trackers)
ret.append(tracker); ret.append({QString::fromStdString(tracker.url)});
return ret; return ret;
} }

2
src/base/bittorrent/torrentinfo.h

@ -45,7 +45,7 @@ class QUrl;
namespace BitTorrent namespace BitTorrent
{ {
class InfoHash; class InfoHash;
class TrackerEntry; struct TrackerEntry;
class TorrentInfo final : public AbstractFileStorage class TorrentInfo final : public AbstractFileStorage
{ {

132
src/base/bittorrent/trackerentry.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2015, 2021 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -28,139 +28,15 @@
#include "trackerentry.h" #include "trackerentry.h"
#include <algorithm>
#include <libtorrent/version.hpp>
#include <QString>
#include <QUrl> #include <QUrl>
using namespace BitTorrent;
TrackerEntry::TrackerEntry(const QString &url)
: m_nativeEntry(url.toStdString())
{
}
TrackerEntry::TrackerEntry(const lt::announce_entry &nativeEntry)
: m_nativeEntry(nativeEntry)
{
}
QString TrackerEntry::url() const
{
return QString::fromStdString(nativeEntry().url);
}
int TrackerEntry::tier() const
{
return nativeEntry().tier;
}
TrackerEntry::Status TrackerEntry::status() const
{
const auto &endpoints = nativeEntry().endpoints;
const bool allFailed = !endpoints.empty() && std::all_of(endpoints.begin(), endpoints.end()
, [](const lt::announce_endpoint &endpoint)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
return std::all_of(endpoint.info_hashes.begin(), endpoint.info_hashes.end()
, [](const lt::announce_infohash &infohash)
{
return (infohash.fails > 0);
});
#else
return (endpoint.fails > 0);
#endif
});
if (allFailed)
return NotWorking;
const bool isUpdating = std::any_of(endpoints.begin(), endpoints.end()
, [](const lt::announce_endpoint &endpoint)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
return std::any_of(endpoint.info_hashes.begin(), endpoint.info_hashes.end()
, [](const lt::announce_infohash &infohash)
{
return infohash.updating;
});
#else
return endpoint.updating;
#endif
});
if (isUpdating)
return Updating;
if (!nativeEntry().verified)
return NotContacted;
return Working;
}
void TrackerEntry::setTier(const int value)
{
m_nativeEntry.tier = value;
}
int TrackerEntry::numSeeds() const
{
int value = -1;
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
for (const lt::announce_infohash &infoHash : endpoint.info_hashes)
value = std::max(value, infoHash.scrape_complete);
#else
value = std::max(value, endpoint.scrape_complete);
#endif
}
return value;
}
int TrackerEntry::numLeeches() const
{
int value = -1;
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
for (const lt::announce_infohash &infoHash : endpoint.info_hashes)
value = std::max(value, infoHash.scrape_incomplete);
#else
value = std::max(value, endpoint.scrape_incomplete);
#endif
}
return value;
}
int TrackerEntry::numDownloaded() const
{
int value = -1;
for (const lt::announce_endpoint &endpoint : nativeEntry().endpoints)
{
#if (LIBTORRENT_VERSION_NUM >= 20000)
for (const lt::announce_infohash &infoHash : endpoint.info_hashes)
value = std::max(value, infoHash.scrape_downloaded);
#else
value = std::max(value, endpoint.scrape_downloaded);
#endif
}
return value;
}
const lt::announce_entry &TrackerEntry::nativeEntry() const
{
return m_nativeEntry;
}
bool BitTorrent::operator==(const TrackerEntry &left, const TrackerEntry &right) bool BitTorrent::operator==(const TrackerEntry &left, const TrackerEntry &right)
{ {
return ((left.tier() == right.tier()) return ((left.tier == right.tier)
&& QUrl(left.url()) == QUrl(right.url())); && QUrl(left.url) == QUrl(right.url));
} }
uint BitTorrent::qHash(const TrackerEntry &key, const uint seed) uint BitTorrent::qHash(const TrackerEntry &key, const uint seed)
{ {
return (::qHash(key.url(), seed) ^ ::qHash(key.tier())); return (::qHash(key.url, seed) ^ ::qHash(key.tier));
} }

43
src/base/bittorrent/trackerentry.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2015, 2021 Vladimir Golovnev <glassez@yandex.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -28,17 +28,14 @@
#pragma once #pragma once
#include <libtorrent/announce_entry.hpp>
#include <QtGlobal> #include <QtGlobal>
#include <QString>
class QString; #include <QVector>
namespace BitTorrent namespace BitTorrent
{ {
class TrackerEntry struct TrackerEntry
{ {
public:
enum Status enum Status
{ {
NotContacted = 1, NotContacted = 1,
@ -47,26 +44,26 @@ namespace BitTorrent
NotWorking = 4 NotWorking = 4
}; };
TrackerEntry() = default; struct EndpointStats
TrackerEntry(const QString &url); {
TrackerEntry(const lt::announce_entry &nativeEntry); int protocolVersion = 1;
TrackerEntry(const TrackerEntry &other) = default;
TrackerEntry &operator=(const TrackerEntry &other) = default;
QString url() const;
Status status() const;
int tier() const; Status status = NotContacted;
void setTier(int value); int numSeeds = -1;
int numLeeches = -1;
int numDownloaded = -1;
};
int numSeeds() const; QString url;
int numLeeches() const; int tier = 0;
int numDownloaded() const;
const lt::announce_entry &nativeEntry() const; QVector<EndpointStats> endpoints {};
private: // Deprecated fields
lt::announce_entry m_nativeEntry; Status status = NotContacted;
int numSeeds = -1;
int numLeeches = -1;
int numDownloaded = -1;
}; };
bool operator==(const TrackerEntry &left, const TrackerEntry &right); bool operator==(const TrackerEntry &left, const TrackerEntry &right);

40
src/gui/properties/trackerlistwidget.cpp

@ -205,9 +205,7 @@ void TrackerListWidget::moveSelectionUp()
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i)
{ {
const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
BitTorrent::TrackerEntry e(trackerURL); trackers.append({trackerURL, (i - NB_STICKY_ITEM)});
e.setTier(i - NB_STICKY_ITEM);
trackers.append(e);
} }
torrent->replaceTrackers(trackers); torrent->replaceTrackers(trackers);
@ -251,9 +249,7 @@ void TrackerListWidget::moveSelectionDown()
for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i) for (int i = NB_STICKY_ITEM; i < topLevelItemCount(); ++i)
{ {
const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString(); const QString trackerURL = topLevelItem(i)->data(COL_URL, Qt::DisplayRole).toString();
BitTorrent::TrackerEntry e(trackerURL); trackers.append({trackerURL, (i - NB_STICKY_ITEM)});
e.setTier(i - NB_STICKY_ITEM);
trackers.append(e);
} }
torrent->replaceTrackers(trackers); torrent->replaceTrackers(trackers);
@ -372,7 +368,7 @@ void TrackerListWidget::loadTrackers()
for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers())) for (const BitTorrent::TrackerEntry &entry : asConst(torrent->trackers()))
{ {
const QString trackerURL = entry.url(); const QString trackerURL = entry.url;
QTreeWidgetItem *item = m_trackerItems.value(trackerURL, nullptr); QTreeWidgetItem *item = m_trackerItems.value(trackerURL, nullptr);
if (!item) if (!item)
@ -387,11 +383,11 @@ void TrackerListWidget::loadTrackers()
oldTrackerURLs.removeOne(trackerURL); oldTrackerURLs.removeOne(trackerURL);
} }
item->setText(COL_TIER, QString::number(entry.tier())); item->setText(COL_TIER, QString::number(entry.tier));
const BitTorrent::TrackerInfo data = trackerData.value(trackerURL); const BitTorrent::TrackerInfo data = trackerData.value(trackerURL);
switch (entry.status()) switch (entry.status)
{ {
case BitTorrent::TrackerEntry::Working: case BitTorrent::TrackerEntry::Working:
item->setText(COL_STATUS, tr("Working")); item->setText(COL_STATUS, tr("Working"));
@ -412,14 +408,14 @@ void TrackerListWidget::loadTrackers()
} }
item->setText(COL_PEERS, QString::number(data.numPeers)); item->setText(COL_PEERS, QString::number(data.numPeers));
item->setText(COL_SEEDS, ((entry.numSeeds() > -1) item->setText(COL_SEEDS, ((entry.numSeeds > -1)
? QString::number(entry.numSeeds()) ? QString::number(entry.numSeeds)
: tr("N/A"))); : tr("N/A")));
item->setText(COL_LEECHES, ((entry.numLeeches() > -1) item->setText(COL_LEECHES, ((entry.numLeeches > -1)
? QString::number(entry.numLeeches()) ? QString::number(entry.numLeeches)
: tr("N/A"))); : tr("N/A")));
item->setText(COL_DOWNLOADED, ((entry.numDownloaded() > -1) item->setText(COL_DOWNLOADED, ((entry.numDownloaded > -1)
? QString::number(entry.numDownloaded()) ? QString::number(entry.numDownloaded)
: tr("N/A"))); : tr("N/A")));
const Qt::Alignment alignment = (Qt::AlignRight | Qt::AlignVCenter); const Qt::Alignment alignment = (Qt::AlignRight | Qt::AlignVCenter);
@ -443,7 +439,7 @@ void TrackerListWidget::askForTrackers()
QVector<BitTorrent::TrackerEntry> trackers; QVector<BitTorrent::TrackerEntry> trackers;
for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent))) for (const QString &tracker : asConst(TrackersAdditionDialog::askForTrackers(this, torrent)))
trackers << tracker; trackers.append({tracker});
torrent->addTrackers(trackers); torrent->addTrackers(trackers);
} }
@ -492,7 +488,7 @@ void TrackerListWidget::deleteSelectedTrackers()
for (const BitTorrent::TrackerEntry &entry : trackers) for (const BitTorrent::TrackerEntry &entry : trackers)
{ {
if (!urlsToRemove.contains(entry.url())) if (!urlsToRemove.contains(entry.url))
remainingTrackers.push_back(entry); remainingTrackers.push_back(entry);
} }
@ -529,18 +525,16 @@ void TrackerListWidget::editSelectedTracker()
bool match = false; bool match = false;
for (BitTorrent::TrackerEntry &entry : trackers) for (BitTorrent::TrackerEntry &entry : trackers)
{ {
if (newTrackerURL == QUrl(entry.url())) if (newTrackerURL == QUrl(entry.url))
{ {
QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists.")); QMessageBox::warning(this, tr("Tracker editing failed"), tr("The tracker URL already exists."));
return; return;
} }
if (!match && (trackerURL == QUrl(entry.url()))) if (!match && (trackerURL == QUrl(entry.url)))
{ {
match = true; match = true;
BitTorrent::TrackerEntry newEntry(newTrackerURL.toString()); entry.url = newTrackerURL.toString();
newEntry.setTier(entry.tier());
entry = newEntry;
} }
} }
@ -572,7 +566,7 @@ void TrackerListWidget::reannounceSelected()
// Trackers case // Trackers case
for (int i = 0; i < trackers.size(); ++i) for (int i = 0; i < trackers.size(); ++i)
{ {
if (item->text(COL_URL) == trackers[i].url()) if (item->text(COL_URL) == trackers[i].url)
{ {
torrent->forceReannounce(i); torrent->forceReannounce(i);
break; break;

4
src/gui/properties/trackersadditiondialog.cpp

@ -96,7 +96,7 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu
existingTrackers.reserve(trackersFromUser.size()); existingTrackers.reserve(trackersFromUser.size());
for (const QString &userURL : trackersFromUser) for (const QString &userURL : trackersFromUser)
{ {
const BitTorrent::TrackerEntry userTracker(userURL); const BitTorrent::TrackerEntry userTracker {userURL};
if (!existingTrackers.contains(userTracker)) if (!existingTrackers.contains(userTracker))
existingTrackers << userTracker; existingTrackers << userTracker;
} }
@ -113,7 +113,7 @@ void TrackersAdditionDialog::torrentListDownloadFinished(const Net::DownloadResu
const QString line = buffer.readLine().trimmed(); const QString line = buffer.readLine().trimmed();
if (line.isEmpty()) continue; if (line.isEmpty()) continue;
BitTorrent::TrackerEntry newTracker(line); BitTorrent::TrackerEntry newTracker {line};
if (!existingTrackers.contains(newTracker)) if (!existingTrackers.contains(newTracker))
{ {
m_ui->textEditTrackersList->insertPlainText(line + '\n'); m_ui->textEditTrackersList->insertPlainText(line + '\n');

8
src/gui/trackerentriesdialog.cpp

@ -66,8 +66,8 @@ void TrackerEntriesDialog::setTrackers(const QVector<BitTorrent::TrackerEntry> &
for (const BitTorrent::TrackerEntry &entry : trackers) for (const BitTorrent::TrackerEntry &entry : trackers)
{ {
tiers[entry.tier()] += (entry.url() + '\n'); tiers[entry.tier] += (entry.url + '\n');
maxTier = std::max(maxTier, entry.tier()); maxTier = std::max(maxTier, entry.tier);
} }
QString text = tiers.value(0); QString text = tiers.value(0);
@ -97,9 +97,7 @@ QVector<BitTorrent::TrackerEntry> TrackerEntriesDialog::trackers() const
continue; continue;
} }
BitTorrent::TrackerEntry entry {line.toString()}; entries.append({line.toString(), tier});
entry.setTier(tier);
entries.append(entry);
} }
return entries; return entries;

2
src/gui/trackerentriesdialog.h

@ -35,7 +35,7 @@
namespace BitTorrent namespace BitTorrent
{ {
class TrackerEntry; struct TrackerEntry;
} }
namespace Ui namespace Ui

8
src/gui/transferlistfilterswidget.cpp

@ -580,7 +580,7 @@ void TrackerFiltersList::handleNewTorrent(BitTorrent::Torrent *const torrent)
const BitTorrent::InfoHash hash {torrent->hash()}; const BitTorrent::InfoHash hash {torrent->hash()};
const QVector<BitTorrent::TrackerEntry> trackers {torrent->trackers()}; const QVector<BitTorrent::TrackerEntry> trackers {torrent->trackers()};
for (const BitTorrent::TrackerEntry &tracker : trackers) for (const BitTorrent::TrackerEntry &tracker : trackers)
addItem(tracker.url(), hash); addItem(tracker.url, hash);
// Check for trackerless torrent // Check for trackerless torrent
if (trackers.isEmpty()) if (trackers.isEmpty())
@ -594,7 +594,7 @@ void TrackerFiltersList::torrentAboutToBeDeleted(BitTorrent::Torrent *const torr
const BitTorrent::InfoHash hash {torrent->hash()}; const BitTorrent::InfoHash hash {torrent->hash()};
const QVector<BitTorrent::TrackerEntry> trackers {torrent->trackers()}; const QVector<BitTorrent::TrackerEntry> trackers {torrent->trackers()};
for (const BitTorrent::TrackerEntry &tracker : trackers) for (const BitTorrent::TrackerEntry &tracker : trackers)
removeItem(tracker.url(), hash); removeItem(tracker.url, hash);
// Check for trackerless torrent // Check for trackerless torrent
if (trackers.isEmpty()) if (trackers.isEmpty())
@ -743,13 +743,13 @@ void TransferListFiltersWidget::setDownloadTrackerFavicon(bool value)
void TransferListFiltersWidget::addTrackers(const BitTorrent::Torrent *torrent, const QVector<BitTorrent::TrackerEntry> &trackers) void TransferListFiltersWidget::addTrackers(const BitTorrent::Torrent *torrent, const QVector<BitTorrent::TrackerEntry> &trackers)
{ {
for (const BitTorrent::TrackerEntry &tracker : trackers) for (const BitTorrent::TrackerEntry &tracker : trackers)
m_trackerFilters->addItem(tracker.url(), torrent->hash()); m_trackerFilters->addItem(tracker.url, torrent->hash());
} }
void TransferListFiltersWidget::removeTrackers(const BitTorrent::Torrent *torrent, const QVector<BitTorrent::TrackerEntry> &trackers) void TransferListFiltersWidget::removeTrackers(const BitTorrent::Torrent *torrent, const QVector<BitTorrent::TrackerEntry> &trackers)
{ {
for (const BitTorrent::TrackerEntry &tracker : trackers) for (const BitTorrent::TrackerEntry &tracker : trackers)
m_trackerFilters->removeItem(tracker.url(), torrent->hash()); m_trackerFilters->removeItem(tracker.url, torrent->hash());
} }
void TransferListFiltersWidget::changeTrackerless(const BitTorrent::Torrent *torrent, const bool trackerless) void TransferListFiltersWidget::changeTrackerless(const BitTorrent::Torrent *torrent, const bool trackerless)

2
src/gui/transferlistfilterswidget.h

@ -41,7 +41,7 @@ namespace BitTorrent
{ {
class InfoHash; class InfoHash;
class Torrent; class Torrent;
class TrackerEntry; struct TrackerEntry;
} }
namespace Net namespace Net

2
src/webui/api/synccontroller.cpp

@ -488,7 +488,7 @@ void SyncController::maindataAction()
} }
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers())) for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
trackers[tracker.url()] << torrentHash.toString(); trackers[tracker.url] << torrentHash.toString();
torrents[torrentHash.toString()] = map; torrents[torrentHash.toString()] = map;
} }

24
src/webui/api/torrentscontroller.cpp

@ -453,18 +453,18 @@ void TorrentsController::trackersAction()
QHash<QString, BitTorrent::TrackerInfo> trackersData = torrent->trackerInfos(); QHash<QString, BitTorrent::TrackerInfo> trackersData = torrent->trackerInfos();
for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers())) for (const BitTorrent::TrackerEntry &tracker : asConst(torrent->trackers()))
{ {
const BitTorrent::TrackerInfo data = trackersData.value(tracker.url()); const BitTorrent::TrackerInfo data = trackersData.value(tracker.url);
trackerList << QJsonObject trackerList << QJsonObject
{ {
{KEY_TRACKER_URL, tracker.url()}, {KEY_TRACKER_URL, tracker.url},
{KEY_TRACKER_TIER, tracker.tier()}, {KEY_TRACKER_TIER, tracker.tier},
{KEY_TRACKER_STATUS, static_cast<int>(tracker.status())}, {KEY_TRACKER_STATUS, static_cast<int>(tracker.status)},
{KEY_TRACKER_PEERS_COUNT, data.numPeers}, {KEY_TRACKER_PEERS_COUNT, data.numPeers},
{KEY_TRACKER_MSG, data.lastMessage.trimmed()}, {KEY_TRACKER_MSG, data.lastMessage.trimmed()},
{KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds()}, {KEY_TRACKER_SEEDS_COUNT, tracker.numSeeds},
{KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches()}, {KEY_TRACKER_LEECHES_COUNT, tracker.numLeeches},
{KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded()} {KEY_TRACKER_DOWNLOADED_COUNT, tracker.numDownloaded}
}; };
} }
@ -694,7 +694,7 @@ void TorrentsController::addTrackersAction()
{ {
const QUrl url {urlStr.trimmed()}; const QUrl url {urlStr.trimmed()};
if (url.isValid()) if (url.isValid())
trackers << url.toString(); trackers.append({url.toString()});
} }
torrent->addTrackers(trackers); torrent->addTrackers(trackers);
} }
@ -722,15 +722,13 @@ void TorrentsController::editTrackerAction()
bool match = false; bool match = false;
for (BitTorrent::TrackerEntry &tracker : trackers) for (BitTorrent::TrackerEntry &tracker : trackers)
{ {
const QUrl trackerUrl(tracker.url()); const QUrl trackerUrl(tracker.url);
if (trackerUrl == newTrackerUrl) if (trackerUrl == newTrackerUrl)
throw APIError(APIErrorType::Conflict, "New tracker URL already exists"); throw APIError(APIErrorType::Conflict, "New tracker URL already exists");
if (trackerUrl == origTrackerUrl) if (trackerUrl == origTrackerUrl)
{ {
match = true; match = true;
BitTorrent::TrackerEntry newTracker(newTrackerUrl.toString()); tracker.url = newTrackerUrl.toString();
newTracker.setTier(tracker.tier());
tracker = newTracker;
} }
} }
if (!match) if (!match)
@ -758,7 +756,7 @@ void TorrentsController::removeTrackersAction()
remainingTrackers.reserve(trackers.size()); remainingTrackers.reserve(trackers.size());
for (const BitTorrent::TrackerEntry &entry : trackers) for (const BitTorrent::TrackerEntry &entry : trackers)
{ {
if (!urls.contains(entry.url())) if (!urls.contains(entry.url))
remainingTrackers.push_back(entry); remainingTrackers.push_back(entry);
} }

Loading…
Cancel
Save