- Added DHT to trackers list

This commit is contained in:
Christophe Dumez 2009-11-19 15:43:00 +00:00
parent e2b8aeafa6
commit e36e500045
6 changed files with 66 additions and 6 deletions

View file

@ -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)

View file

@ -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; i<nbColumns; ++i) {
listModel->setData(listModel->index(row, i), QVariant(color), Qt::ForegroundRole);
}

View file

@ -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<dht_reply_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
// Connection was successful now but there is a warning message
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
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<portmap_error_alert*>(a.get())) {
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(QString(p->message().c_str())), QColor("red"));

View file

@ -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
//

View file

@ -121,6 +121,7 @@ class QTorrentHandle {
QString creation_date() const;
void get_peer_info(std::vector<peer_info>&) const;
bool resolve_countries() const;
bool priv() const;
//
// Setters

View file

@ -38,12 +38,14 @@
#include <QSettings>
#include <QHash>
#include <QAction>
#include <QColor>
#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<QString, QTreeWidgetItem*> 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<QTreeWidgetItem*> getSelectedTrackerItems() const {
QList<QTreeWidgetItem*> selected_items = selectedItems();
QList<QTreeWidgetItem*> 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; i<nbColumns; ++i) {
item->setData(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<QString, TrackerInfos> 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<QString, TrackerInfos> trackers_data = properties->getBTSession()->getTrackersInfo(h.hash());
loadStickyItems(h, trackers_data);
// Load actual trackers information
QStringList old_trackers_urls = tracker_items.keys();
std::vector<announce_entry> trackers = h.trackers();
std::vector<announce_entry>::iterator it;
for(it = trackers.begin(); it != trackers.end(); it++) {
@ -151,7 +195,7 @@ public slots:
clear();
return;
}
QList<QTreeWidgetItem *> selected_items = selectedItems();
QList<QTreeWidgetItem *> 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<QTreeWidgetItem*> selected_items = selectedItems();
QList<QTreeWidgetItem*> 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());