From e2b8aeafa6d74a1d480c2e4e932d9a8078fb4b76 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 19 Nov 2009 15:04:43 +0000 Subject: [PATCH] - FEATURE: Display the number of peers returned by each tracker --- Changelog | 1 + src/bittorrent.cpp | 34 +++++++++++++++++++++++----------- src/bittorrent.h | 23 +++++++++++++++++++++-- src/trackerlist.h | 10 ++++++---- 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/Changelog b/Changelog index e76cca7ad..eb146c6ea 100644 --- a/Changelog +++ b/Changelog @@ -15,6 +15,7 @@ - FEATURE: Display total amounts transferred in status bar - FEATURE: Announce to all trackers specified for a torrent (µTorrent behavior) - FEATURE: Display trackers status as well as error/warning messages + - FEATURE: Display the number of peers returned by each tracker - FEATURE: Global upload/download speeds can be capped from status bar (µTorrent behavior) - FEATURE: Dropped Qt 4.3 support (Qt >= 4.4 is now required) - FEATURE: Added per-torrent super seeding mode (libtorrent >= v0.15 only) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index d4d66d320..3abe18fe7 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -578,7 +578,7 @@ void bittorrent::deleteTorrent(QString hash, bool delete_local_files) { } TorrentPersistentData::deletePersistentData(hash); // Remove tracker errors - trackersErrors.remove(hash); + trackersInfos.remove(hash); if(delete_local_files) addConsoleMessage(tr("'%1' was removed from transfer list and hard disk.", "'xxx.avi' was removed...").arg(fileName)); else @@ -1597,7 +1597,12 @@ void bittorrent::readAlerts() { // Authentication if(p->status_code != 401) { qDebug("Received a tracker error for %s: %s", p->url.c_str(), p->msg.c_str()); - trackersErrors[h.hash()][misc::toQString(p->url)] = misc::toQString(p->message()); + QString tracker_url = misc::toQString(p->url); + QHash trackers_data = trackersInfos.value(h.hash(), QHash()); + TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); + data.last_message = misc::toQString(p->msg); + trackers_data.insert(tracker_url, data); + trackersInfos[h.hash()] = trackers_data; } else { emit trackerAuthenticationRequired(h); } @@ -1608,17 +1613,24 @@ void bittorrent::readAlerts() { if(h.is_valid()){ qDebug("Received a tracker reply from %s", p->url.c_str()); // Connection was successful now. Remove possible old errors - QHash errors = trackersErrors.value(h.hash(), QHash()); - errors.remove(misc::toQString(p->url)); - trackersErrors[h.hash()] = errors; + QHash trackers_data = trackersInfos.value(h.hash(), QHash()); + QString tracker_url = misc::toQString(p->url); + TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); + data.last_message = ""; // Reset error/warning message + data.num_peers = p->num_peers; + trackers_data.insert(tracker_url, data); + trackersInfos[h.hash()] = trackers_data; } } else if (tracker_warning_alert* p = dynamic_cast(a.get())) { QTorrentHandle h(p->handle); if(h.is_valid()){ - // Connection was successful now. Remove possible old errors - QHash errors = trackersErrors.value(h.hash(), QHash()); - errors[misc::toQString(p->url)] = misc::toQString(p->msg); - trackersErrors[h.hash()] = errors; + // Connection was successful now but there is a warning message + QHash trackers_data = trackersInfos.value(h.hash(), QHash()); + QString tracker_url = misc::toQString(p->url); + TrackerInfos data = trackers_data.value(tracker_url, TrackerInfos(tracker_url)); + data.last_message = misc::toQString(p->msg); // Store warning message + trackers_data.insert(tracker_url, data); + trackersInfos[h.hash()] = trackers_data; qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str()); } } @@ -1673,8 +1685,8 @@ void bittorrent::readAlerts() { } } -QHash bittorrent::getTrackersErrors(QString hash) const{ - return trackersErrors.value(hash, QHash()); +QHash bittorrent::getTrackersInfo(QString hash) const{ + return trackersInfos.value(hash, QHash()); } int bittorrent::getListenPort() const{ diff --git a/src/bittorrent.h b/src/bittorrent.h index 4dcb65e5a..c6f0628e2 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -50,6 +50,25 @@ class FileSystemWatcher; class FilterParserThread; class HttpServer; +class TrackerInfos { +public: + QString name_or_url; + QString last_message; + unsigned long num_peers; + + //TrackerInfos() {} + TrackerInfos(const TrackerInfos &b) { + qDebug("TrackerInfos copy contructor called"); + name_or_url = b.name_or_url; + Q_ASSERT(!name_or_url.isEmpty()); + last_message = b.last_message; + qDebug("Copied message: %s", last_message.toLocal8Bit().data()); + num_peers = b.num_peers; + } + TrackerInfos(QString name_or_url): name_or_url(name_or_url), last_message(""), num_peers(0) { + } +}; + class bittorrent : public QObject { Q_OBJECT @@ -58,7 +77,7 @@ private: session *s; QPointer timerAlerts; QHash savepath_fromurl; - QHash > trackersErrors; + QHash > trackersInfos; // Ratio QPointer BigRatioTimer; // HTTP @@ -110,7 +129,7 @@ public: int getListenPort() const; float getRealRatio(QString hash) const; session* getSession() const; - QHash getTrackersErrors(QString hash) const; + QHash getTrackersInfo(QString hash) const; bool has_filtered_files(QString hash) const; bool hasActiveTorrents() const; bool isQueueingEnabled() const; diff --git a/src/trackerlist.h b/src/trackerlist.h index 9adae4b87..8b1cfada4 100644 --- a/src/trackerlist.h +++ b/src/trackerlist.h @@ -43,7 +43,7 @@ #include "misc.h" #include "bittorrent.h" -enum TrackerListColumn {COL_URL, COL_STATUS, COL_MSG}; +enum TrackerListColumn {COL_URL, COL_STATUS, COL_PEERS, COL_MSG}; class TrackerList: public QTreeWidget { Q_OBJECT @@ -66,6 +66,7 @@ public: QStringList header; header << tr("URL"); header << tr("Status"); + header << tr("Peers"); header << tr("Message"); setHeaderItem(new QTreeWidgetItem(header)); loadSettings(); @@ -87,7 +88,7 @@ public slots: // Load trackers from torrent handle QTorrentHandle h = properties->getCurrentTorrent(); if(!h.is_valid()) return; - QHash errors = properties->getBTSession()->getTrackersErrors(h.hash()); + QHash trackers_data = properties->getBTSession()->getTrackersInfo(h.hash()); std::vector trackers = h.trackers(); std::vector::iterator it; for(it = trackers.begin(); it != trackers.end(); it++) { @@ -105,7 +106,7 @@ public slots: if((*it).verified) { item->setText(COL_STATUS, tr("Working")); } else { - if((*it).updating) { + if((*it).updating && (*it).fails == 0) { item->setText(COL_STATUS, tr("Updating...")); } else { if((*it).fails > 0) { @@ -115,7 +116,8 @@ public slots: } } } - item->setText(COL_MSG, errors.value(tracker_url, "")); + item->setText(COL_PEERS, QString::number(trackers_data.value(tracker_url, TrackerInfos(tracker_url)).num_peers)); + item->setText(COL_MSG, trackers_data.value(tracker_url, TrackerInfos(tracker_url)).last_message); } // Remove old trackers foreach(const QString &tracker, old_trackers_urls) {