- FEATURE: Display the number of peers returned by each tracker

This commit is contained in:
Christophe Dumez 2009-11-19 15:04:43 +00:00
parent 484a75ad64
commit e2b8aeafa6
4 changed files with 51 additions and 17 deletions

View file

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

View file

@ -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<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
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<QString, QString> errors = trackersErrors.value(h.hash(), QHash<QString, QString>());
errors.remove(misc::toQString(p->url));
trackersErrors[h.hash()] = errors;
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
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<tracker_warning_alert*>(a.get())) {
QTorrentHandle h(p->handle);
if(h.is_valid()){
// Connection was successful now. Remove possible old errors
QHash<QString, QString> errors = trackersErrors.value(h.hash(), QHash<QString, QString>());
errors[misc::toQString(p->url)] = misc::toQString(p->msg);
trackersErrors[h.hash()] = errors;
// Connection was successful now but there is a warning message
QHash<QString, TrackerInfos> trackers_data = trackersInfos.value(h.hash(), QHash<QString, TrackerInfos>());
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<QString, QString> bittorrent::getTrackersErrors(QString hash) const{
return trackersErrors.value(hash, QHash<QString, QString>());
QHash<QString, TrackerInfos> bittorrent::getTrackersInfo(QString hash) const{
return trackersInfos.value(hash, QHash<QString, TrackerInfos>());
}
int bittorrent::getListenPort() const{

View file

@ -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<QTimer> timerAlerts;
QHash<QString, QString> savepath_fromurl;
QHash<QString, QHash<QString, QString> > trackersErrors;
QHash<QString, QHash<QString, TrackerInfos> > trackersInfos;
// Ratio
QPointer<QTimer> BigRatioTimer;
// HTTP
@ -110,7 +129,7 @@ public:
int getListenPort() const;
float getRealRatio(QString hash) const;
session* getSession() const;
QHash<QString, QString> getTrackersErrors(QString hash) const;
QHash<QString, TrackerInfos> getTrackersInfo(QString hash) const;
bool has_filtered_files(QString hash) const;
bool hasActiveTorrents() const;
bool isQueueingEnabled() const;

View file

@ -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<QString, QString> errors = properties->getBTSession()->getTrackersErrors(h.hash());
QHash<QString, TrackerInfos> trackers_data = properties->getBTSession()->getTrackersInfo(h.hash());
std::vector<announce_entry> trackers = h.trackers();
std::vector<announce_entry>::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) {