Browse Source

Implement peer relevance column. Closes #1630.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
35e964f66d
  1. 5
      src/properties/peerlistdelegate.h
  2. 33
      src/properties/peerlistwidget.cpp
  3. 5
      src/properties/peerlistwidget.h
  4. 8
      src/properties/propertieswidget.cpp

5
src/properties/peerlistdelegate.h

@ -40,7 +40,7 @@ class PeerListDelegate: public QItemDelegate { @@ -40,7 +40,7 @@ class PeerListDelegate: public QItemDelegate {
public:
enum PeerListColumns {COUNTRY, IP, PORT, CONNECTION, FLAGS, CLIENT, PROGRESS, DOWN_SPEED, UP_SPEED,
TOT_DOWN, TOT_UP, IP_HIDDEN, COL_COUNT};
TOT_DOWN, TOT_UP, RELEVANCE, IP_HIDDEN, COL_COUNT};
public:
PeerListDelegate(QObject *parent) : QItemDelegate(parent) {}
@ -64,7 +64,8 @@ public: @@ -64,7 +64,8 @@ public:
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::friendlyUnit(speed)+tr("/s", "/second (i.e. per second)"));
break;
}
case PROGRESS:{
case PROGRESS:
case RELEVANCE:{
QItemDelegate::drawBackground(painter, opt, index);
qreal progress = index.data().toDouble();
QItemDelegate::drawDisplay(painter, opt, opt.rect, misc::accurateDoubleToString(progress*100.0, 1)+"%");

33
src/properties/peerlistwidget.cpp

@ -71,6 +71,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent): @@ -71,6 +71,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent):
m_listModel->setHeaderData(PeerListDelegate::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
m_listModel->setHeaderData(PeerListDelegate::TOT_DOWN, Qt::Horizontal, tr("Downloaded", "i.e: total data downloaded"));
m_listModel->setHeaderData(PeerListDelegate::TOT_UP, Qt::Horizontal, tr("Uploaded", "i.e: total data uploaded"));
m_listModel->setHeaderData(PeerListDelegate::RELEVANCE, Qt::Horizontal, tr("Relevance", "i.e: How relevant this peer is to us. How many pieces it has that we don't."));
// Proxy model to support sorting without actually altering the underlying model
m_proxyModel = new PeerListSortModel();
m_proxyModel->setDynamicSortFilter(true);
@ -327,6 +328,7 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso @@ -327,6 +328,7 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
if (!h.is_valid())
return;
boost::system::error_code ec;
libtorrent::torrent_status status = h.status(torrent_handle::query_pieces);
std::vector<peer_info> peers;
h.get_peer_info(peers);
QSet<QString> old_peers_set = m_peerItems.keys().toSet();
@ -341,14 +343,14 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso @@ -341,14 +343,14 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
QString peer_ip = misc::toQString(ip_str);
if (m_peerItems.contains(peer_ip)) {
// Update existing peer
updatePeer(peer_ip, peer);
updatePeer(peer_ip, status, peer);
old_peers_set.remove(peer_ip);
if (force_hostname_resolution && m_resolver) {
m_resolver->resolve(peer_ip);
}
} else {
// Add new peer
m_peerItems[peer_ip] = addPeer(peer_ip, peer);
m_peerItems[peer_ip] = addPeer(peer_ip, status, peer);
m_peerEndpoints[peer_ip] = peer.ip;
// Resolve peer host name is asked
if (m_resolver)
@ -366,7 +368,7 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso @@ -366,7 +368,7 @@ void PeerListWidget::loadPeers(const QTorrentHandle &h, bool force_hostname_reso
}
}
QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer) {
QStandardItem* PeerListWidget::addPeer(const QString& ip, const libtorrent::torrent_status &status, const peer_info& peer) {
int row = m_listModel->rowCount();
// Adding Peer to peer list
m_listModel->insertRow(row);
@ -395,10 +397,11 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer) @@ -395,10 +397,11 @@ QStandardItem* PeerListWidget::addPeer(const QString& ip, const peer_info& peer)
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), getPeerRelevance(status, peer));
return m_listModel->item(row, PeerListDelegate::IP);
}
void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) {
void PeerListWidget::updatePeer(const QString& ip, const libtorrent::torrent_status &status, const peer_info& peer) {
QStandardItem *item = m_peerItems.value(ip);
int row = item->row();
if (m_displayFlags) {
@ -422,6 +425,7 @@ void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) { @@ -422,6 +425,7 @@ void PeerListWidget::updatePeer(const QString& ip, const peer_info& peer) {
m_listModel->setData(m_listModel->index(row, PeerListDelegate::UP_SPEED), peer.payload_up_speed);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_DOWN), (qulonglong)peer.total_download);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::TOT_UP), (qulonglong)peer.total_upload);
m_listModel->setData(m_listModel->index(row, PeerListDelegate::RELEVANCE), getPeerRelevance(status, peer));
}
void PeerListWidget::handleResolved(const QString &ip, const QString &hostname) {
@ -582,3 +586,24 @@ void PeerListWidget::getFlags(const peer_info& peer, QString& flags, QString& to @@ -582,3 +586,24 @@ void PeerListWidget::getFlags(const peer_info& peer, QString& flags, QString& to
if (tooltip.endsWith(',', Qt::CaseInsensitive))
tooltip.chop(1);
}
double PeerListWidget::getPeerRelevance(const torrent_status& status, const libtorrent::peer_info &peer)
{
int localMissing = 0;
int remoteHaves = 0;
libtorrent::bitfield local = status.pieces;
libtorrent::bitfield remote = peer.pieces;
for (int i=0; i<local.size(); ++i) {
if (!local[i]) {
++localMissing;
if (remote[i])
++remoteHaves;
}
}
if (localMissing == 0)
return -1.0;
return (double)remoteHaves/localMissing;
}

5
src/properties/peerlistwidget.h

@ -66,8 +66,8 @@ public: @@ -66,8 +66,8 @@ public:
public slots:
void loadPeers(const QTorrentHandle &h, bool force_hostname_resolution = false);
QStandardItem* addPeer(const QString& ip, const libtorrent::peer_info& peer);
void updatePeer(const QString& ip, const libtorrent::peer_info& peer);
QStandardItem* addPeer(const QString& ip, const libtorrent::torrent_status &status, const libtorrent::peer_info& peer);
void updatePeer(const QString& ip, const libtorrent::torrent_status &status, const libtorrent::peer_info& peer);
void handleResolved(const QString &ip, const QString &hostname);
void updatePeerHostNameResolutionState();
void updatePeerCountryResolutionState();
@ -89,6 +89,7 @@ protected slots: @@ -89,6 +89,7 @@ protected slots:
private:
static QString getConnectionString(const libtorrent::peer_info &peer);
static void getFlags(const libtorrent::peer_info& peer, QString& flags, QString& tooltip);
double getPeerRelevance(const libtorrent::torrent_status &status, const libtorrent::peer_info &peer);
private:
QStandardItemModel *m_listModel;

8
src/properties/propertieswidget.cpp

@ -318,11 +318,12 @@ void PropertiesWidget::loadDynamicData() { @@ -318,11 +318,12 @@ void PropertiesWidget::loadDynamicData() {
// Refresh only if the torrent handle is valid and if visible
if (!h.is_valid() || main_window->getCurrentTabWidget() != transferList || state != VISIBLE) return;
try {
// Transfer infos
if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) {
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
| torrent_handle::query_distributed_copies
| torrent_handle::query_pieces);
// Transfer infos
if (stackedProperties->currentIndex() == PropTabBar::MAIN_TAB) {
wasted->setText(misc::friendlyUnit(status.total_failed_bytes+status.total_redundant_bytes));
upTotal->setText(misc::friendlyUnit(status.all_time_upload) + " ("+misc::friendlyUnit(status.total_payload_upload)+" "+tr("this session")+")");
dlTotal->setText(misc::friendlyUnit(status.all_time_download) + " ("+misc::friendlyUnit(status.total_payload_download)+" "+tr("this session")+")");
@ -382,6 +383,9 @@ void PropertiesWidget::loadDynamicData() { @@ -382,6 +383,9 @@ void PropertiesWidget::loadDynamicData() {
return;
}
if (stackedProperties->currentIndex() == PropTabBar::FILES_TAB) {
libtorrent::torrent_status status = h.status(torrent_handle::query_accurate_download_counters
| torrent_handle::query_distributed_copies
| torrent_handle::query_pieces);
// Files progress
if (h.is_valid() && status.has_metadata) {
qDebug("Updating priorities in files tab");

Loading…
Cancel
Save