From e36e500045a00e38e1f19988cdc1a6e0e3ac8e01 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 19 Nov 2009 15:43:00 +0000 Subject: [PATCH] - Added DHT to trackers list --- Changelog | 2 +- src/TransferListWidget.cpp | 2 +- src/bittorrent.cpp | 10 ++++++++ src/qtorrenthandle.cpp | 5 ++++ src/qtorrenthandle.h | 1 + src/trackerlist.h | 52 +++++++++++++++++++++++++++++++++++--- 6 files changed, 66 insertions(+), 6 deletions(-) diff --git a/Changelog b/Changelog index eb146c6ea..0105e226d 100644 --- a/Changelog +++ b/Changelog @@ -15,7 +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: Display the number of peers returned by each tracker & DHT - 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/TransferListWidget.cpp b/src/TransferListWidget.cpp index bb7975ff0..fd4bd8cd0 100644 --- a/src/TransferListWidget.cpp +++ b/src/TransferListWidget.cpp @@ -170,7 +170,7 @@ void TransferListWidget::addTorrent(QTorrentHandle& h) { } /*void TransferListWidget::setRowColor(int row, QColor color) { - unsigned int nbColumns = listModel->columnCount()-2; + unsigned int nbColumns = listModel->columnCount()-1; for(unsigned int i=0; isetData(listModel->index(row, i), QVariant(color), Qt::ForegroundRole); } diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 3abe18fe7..bc39e7fdc 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -1633,6 +1633,16 @@ void bittorrent::readAlerts() { trackersInfos[h.hash()] = trackers_data; qDebug("Received a tracker warning from %s: %s", p->url.c_str(), p->msg.c_str()); } + } else if (dht_reply_alert* p = dynamic_cast(a.get())) { + QTorrentHandle h(p->handle); + if(h.is_valid()){ + // Connection was successful now but there is a warning message + QHash trackers_data = trackersInfos.value(h.hash(), QHash()); + TrackerInfos data = trackers_data.value("dht", TrackerInfos("dht")); + data.num_peers = p->num_peers; + trackers_data.insert("dht", data); + trackersInfos[h.hash()] = trackers_data; + } } else if (portmap_error_alert* p = dynamic_cast(a.get())) { addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString(p->message().c_str())), QColor("red")); diff --git a/src/qtorrenthandle.cpp b/src/qtorrenthandle.cpp index 7b20c91f4..a9ed1559b 100644 --- a/src/qtorrenthandle.cpp +++ b/src/qtorrenthandle.cpp @@ -386,6 +386,11 @@ bool QTorrentHandle::resolve_countries() const { return h.resolve_countries(); } +bool QTorrentHandle::priv() const { + Q_ASSERT(h.is_valid()); + return h.get_torrent_info().priv(); +} + // // Setters // diff --git a/src/qtorrenthandle.h b/src/qtorrenthandle.h index 968aa0939..e08b26adc 100644 --- a/src/qtorrenthandle.h +++ b/src/qtorrenthandle.h @@ -121,6 +121,7 @@ class QTorrentHandle { QString creation_date() const; void get_peer_info(std::vector&) const; bool resolve_countries() const; + bool priv() const; // // Setters diff --git a/src/trackerlist.h b/src/trackerlist.h index 8b1cfada4..779455bd1 100644 --- a/src/trackerlist.h +++ b/src/trackerlist.h @@ -38,12 +38,14 @@ #include #include #include +#include #include "propertieswidget.h" #include "trackersadditiondlg.h" #include "misc.h" #include "bittorrent.h" enum TrackerListColumn {COL_URL, COL_STATUS, COL_PEERS, COL_MSG}; +#define NB_STICKY_ITEM 1 class TrackerList: public QTreeWidget { Q_OBJECT @@ -51,6 +53,7 @@ class TrackerList: public QTreeWidget { private: PropertiesWidget *properties; QHash tracker_items; + QTreeWidgetItem* dht_item; public: TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) { @@ -69,6 +72,9 @@ public: header << tr("Peers"); header << tr("Message"); setHeaderItem(new QTreeWidgetItem(header)); + dht_item = new QTreeWidgetItem(QStringList(tr("[DHT]"))); + insertTopLevelItem(0, dht_item); + setRowColor(0, QColor("grey")); loadSettings(); } @@ -76,19 +82,57 @@ public: saveSettings(); } +protected: + QList getSelectedTrackerItems() const { + QList selected_items = selectedItems(); + QList selected_trackers; + foreach(QTreeWidgetItem *item, selectedItems()) { + if(indexOfTopLevelItem(item) >= NB_STICKY_ITEM) { // Ignore STICKY ITEMS + selected_trackers << item; + } + } + return selected_trackers; + } + public slots: + void setRowColor(int row, QColor color) { + unsigned int nbColumns = columnCount(); + QTreeWidgetItem *item = topLevelItem(row); + for(unsigned int i=0; isetData(i, Qt::ForegroundRole, color); + } + } + void clear() { qDeleteAll(tracker_items.values()); tracker_items.clear(); + dht_item->setText(COL_PEERS, ""); + dht_item->setText(COL_STATUS, ""); + dht_item->setText(COL_MSG, ""); + } + + void loadStickyItems(const QTorrentHandle &h, QHash trackers_data) { + // load DHT information + if(properties->getBTSession()->isDHTEnabled() && !h.priv()) { + dht_item->setText(COL_STATUS, tr("Working")); + } else { + dht_item->setText(COL_STATUS, tr("Disabled")); + } + dht_item->setText(COL_PEERS, QString::number(trackers_data.value("dht", TrackerInfos("dht")).num_peers)); + if(h.priv()) { + dht_item->setText(COL_MSG, tr("This torrent is private")); + } } void loadTrackers() { - QStringList old_trackers_urls = tracker_items.keys(); // Load trackers from torrent handle QTorrentHandle h = properties->getCurrentTorrent(); if(!h.is_valid()) return; QHash trackers_data = properties->getBTSession()->getTrackersInfo(h.hash()); + loadStickyItems(h, trackers_data); + // Load actual trackers information + QStringList old_trackers_urls = tracker_items.keys(); std::vector trackers = h.trackers(); std::vector::iterator it; for(it = trackers.begin(); it != trackers.end(); it++) { @@ -151,7 +195,7 @@ public slots: clear(); return; } - QList selected_items = selectedItems(); + QList selected_items = getSelectedTrackerItems(); if(selected_items.isEmpty()) return; QStringList urls_to_remove; foreach(QTreeWidgetItem *item, selected_items){ @@ -181,12 +225,12 @@ public slots: } void showTrackerListMenu(QPoint) { - QList selected_items = selectedItems(); + QList selected_items = getSelectedTrackerItems(); QMenu menu; // Add actions QAction *addAct = menu.addAction(QIcon(":/Icons/oxygen/list-add.png"), tr("Add a new tracker")); QAction *delAct = 0; - if(!selectedItems().isEmpty()) { + if(!getSelectedTrackerItems().isEmpty()) { delAct = menu.addAction(QIcon(":/Icons/oxygen/list-remove.png"), "Remove tracker"); } QAction *act = menu.exec(QCursor::pos());