diff --git a/Changelog b/Changelog index aa289dfed..b09eca395 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 & DHT + - FEATURE: Display the number of peers returned by each tracker & DHT/PeX/LSD - FEATURE: Global upload/download speeds can be capped from status bar (µTorrent behavior) - FEATURE: Added option to download first and last piece of a torrent main file first (for preview) - FEATURE: Dropped Qt 4.3 support (Qt >= 4.4 is now required) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index c94e0118f..fe54fe763 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -966,6 +966,10 @@ bool Bittorrent::isDHTEnabled() const{ return DHTEnabled; } +bool Bittorrent::isLSDEnabled() const{ + return LSDEnabled; +} + void Bittorrent::enableUPnP(bool b) { if(b) { if(!UPnPEnabled) { @@ -1537,16 +1541,6 @@ 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/bittorrent.h b/src/bittorrent.h index 583c9cd86..39bd20080 100644 --- a/src/bittorrent.h +++ b/src/bittorrent.h @@ -121,6 +121,7 @@ public: std::vector getTorrents() const; bool isFilePreviewPossible(QString fileHash) const; bool isDHTEnabled() const; + bool isLSDEnabled() const; float getPayloadDownloadRate() const; float getPayloadUploadRate() const; session_status getSessionStatus() const; diff --git a/src/trackerlist.h b/src/trackerlist.h index 779455bd1..a1ee78749 100644 --- a/src/trackerlist.h +++ b/src/trackerlist.h @@ -45,7 +45,7 @@ #include "bittorrent.h" enum TrackerListColumn {COL_URL, COL_STATUS, COL_PEERS, COL_MSG}; -#define NB_STICKY_ITEM 1 +#define NB_STICKY_ITEM 3 class TrackerList: public QTreeWidget { Q_OBJECT @@ -54,6 +54,8 @@ private: PropertiesWidget *properties; QHash tracker_items; QTreeWidgetItem* dht_item; + QTreeWidgetItem* pex_item; + QTreeWidgetItem* lsd_item; public: TrackerList(PropertiesWidget *properties): QTreeWidget(), properties(properties) { @@ -75,6 +77,12 @@ public: dht_item = new QTreeWidgetItem(QStringList(tr("[DHT]"))); insertTopLevelItem(0, dht_item); setRowColor(0, QColor("grey")); + pex_item = new QTreeWidgetItem(QStringList(tr("[PeX]"))); + insertTopLevelItem(1, pex_item); + setRowColor(1, QColor("grey")); + lsd_item = new QTreeWidgetItem(QStringList(tr("[LSD]"))); + insertTopLevelItem(2, lsd_item); + setRowColor(2, QColor("grey")); loadSettings(); } @@ -110,28 +118,57 @@ public slots: dht_item->setText(COL_PEERS, ""); dht_item->setText(COL_STATUS, ""); dht_item->setText(COL_MSG, ""); + pex_item->setText(COL_PEERS, ""); + pex_item->setText(COL_STATUS, ""); + pex_item->setText(COL_MSG, ""); + lsd_item->setText(COL_PEERS, ""); + lsd_item->setText(COL_STATUS, ""); + lsd_item->setText(COL_MSG, ""); } - void loadStickyItems(const QTorrentHandle &h, QHash trackers_data) { + void loadStickyItems(const QTorrentHandle &h) { + // XXX: libtorrent should provide this info... + // Count peers from DHT, LSD, PeX + uint nb_dht=0, nb_lsd=0, nb_pex=0; + std::vector peers; + h.get_peer_info(peers); + std::vector::iterator it; + for(it=peers.begin(); it!=peers.end(); it++) { + if(it->source & peer_info::dht) + ++nb_dht; + if(it->source & peer_info::lsd) + ++nb_lsd; + if(it->source & peer_info::pex) + ++nb_pex; + } // 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)); + dht_item->setText(COL_PEERS, QString::number(nb_dht)); if(h.priv()) { dht_item->setText(COL_MSG, tr("This torrent is private")); } + // Load PeX Information + pex_item->setText(COL_STATUS, tr("Working")); + pex_item->setText(COL_PEERS, QString::number(nb_pex)); + // Load LSD Information + if(properties->getBTSession()->isLSDEnabled()) + lsd_item->setText(COL_STATUS, tr("Working")); + else + lsd_item->setText(COL_STATUS, tr("Disabled")); + lsd_item->setText(COL_PEERS, QString::number(nb_lsd)); } void loadTrackers() { // 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); + loadStickyItems(h); // Load actual trackers information + QHash trackers_data = properties->getBTSession()->getTrackersInfo(h.hash()); QStringList old_trackers_urls = tracker_items.keys(); std::vector trackers = h.trackers(); std::vector::iterator it;