Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Peer ID Client column for Peers tab #17940

Merged
merged 10 commits into from
Nov 6, 2022
25 changes: 25 additions & 0 deletions src/base/bittorrent/peerinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,31 @@ QString PeerInfo::client() const
return QString::fromStdString(m_nativeInfo.client);
}

QString PeerInfo::peerIdClient() const
{
// when peer ID is not known yet it contains only zero bytes,
// do not create string in such case, return empty string instead
if (m_nativeInfo.pid.is_all_zeros())
return {};

QString result;

// interesting part of a typical peer ID is first 8 chars
for (int i = 0; i < 8; ++i)
{
const std::uint8_t c = m_nativeInfo.pid[i];

// ensure that the peer ID slice consists only of printable ASCII characters,
// this should filter out most of the improper IDs
if ((c < 32) || (c > 126))
return tr("Unknown");

result += QChar::fromLatin1(c);
}

return result;
}

qreal PeerInfo::progress() const
{
return m_nativeInfo.progress;
Expand Down
1 change: 1 addition & 0 deletions src/base/bittorrent/peerinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace BitTorrent

PeerAddress address() const;
QString client() const;
QString peerIdClient() const;
qreal progress() const;
int payloadUpSpeed() const;
int payloadDownSpeed() const;
Expand Down
17 changes: 14 additions & 3 deletions src/gui/properties/peerlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
, m_properties(parent)
{
// Load settings
loadSettings();
const bool columnLoaded = loadSettings();
glassez marked this conversation as resolved.
Show resolved Hide resolved
// Visual settings
setUniformRowHeights(true);
setRootIsDecorated(false);
Expand All @@ -109,6 +109,7 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
m_listModel->setHeaderData(PeerListColumns::FLAGS, Qt::Horizontal, tr("Flags"));
m_listModel->setHeaderData(PeerListColumns::CONNECTION, Qt::Horizontal, tr("Connection"));
m_listModel->setHeaderData(PeerListColumns::CLIENT, Qt::Horizontal, tr("Client", "i.e.: Client application"));
m_listModel->setHeaderData(PeerListColumns::PEERID_CLIENT, Qt::Horizontal, tr("Peer ID Client", "i.e.: Client resolved from Peer ID"));
m_listModel->setHeaderData(PeerListColumns::PROGRESS, Qt::Horizontal, tr("Progress", "i.e: % downloaded"));
m_listModel->setHeaderData(PeerListColumns::DOWN_SPEED, Qt::Horizontal, tr("Down Speed", "i.e: Download speed"));
m_listModel->setHeaderData(PeerListColumns::UP_SPEED, Qt::Horizontal, tr("Up Speed", "i.e: Upload speed"));
Expand All @@ -130,8 +131,16 @@ PeerListWidget::PeerListWidget(PropertiesWidget *parent)
m_proxyModel->setSourceModel(m_listModel);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
setModel(m_proxyModel);

hideColumn(PeerListColumns::IP_HIDDEN);
hideColumn(PeerListColumns::COL_COUNT);

// Default hidden columns
if (!columnLoaded)
HanabishiRecca marked this conversation as resolved.
Show resolved Hide resolved
{
hideColumn(PeerListColumns::PEERID_CLIENT);
}

m_resolveCountries = Preferences::instance()->resolvePeerCountries();
if (!m_resolveCountries)
hideColumn(PeerListColumns::COUNTRY);
Expand Down Expand Up @@ -371,9 +380,9 @@ void PeerListWidget::clear()
m_listModel->removeRows(0, nbrows);
}

void PeerListWidget::loadSettings()
bool PeerListWidget::loadSettings()
{
header()->restoreState(Preferences::instance()->getPeerListState());
return header()->restoreState(Preferences::instance()->getPeerListState());
}

void PeerListWidget::saveSettings() const
Expand Down Expand Up @@ -461,6 +470,8 @@ void PeerListWidget::updatePeer(const BitTorrent::Torrent *torrent, const BitTor
setModelData(row, PeerListColumns::FLAGS, peer.flags(), peer.flags(), {}, peer.flagsDescription());
const QString client = peer.client().toHtmlEscaped();
setModelData(row, PeerListColumns::CLIENT, client, client, {}, client);
const QString peerIdClient = peer.peerIdClient().toHtmlEscaped();
setModelData(row, PeerListColumns::PEERID_CLIENT, peerIdClient, peerIdClient);
setModelData(row, PeerListColumns::PROGRESS, (Utils::String::fromDouble(peer.progress() * 100, 1) + u'%'), peer.progress(), intDataTextAlignment);
const QString downSpeed = (hideValues && (peer.payloadDownSpeed() <= 0)) ? QString {} : Utils::Misc::friendlyUnit(peer.payloadDownSpeed(), true);
setModelData(row, PeerListColumns::DOWN_SPEED, downSpeed, peer.payloadDownSpeed(), intDataTextAlignment);
Expand Down
3 changes: 2 additions & 1 deletion src/gui/properties/peerlistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PeerListWidget final : public QTreeView
CONNECTION,
FLAGS,
CLIENT,
PEERID_CLIENT,
PROGRESS,
DOWN_SPEED,
UP_SPEED,
Expand All @@ -87,7 +88,7 @@ class PeerListWidget final : public QTreeView
void clear();

private slots:
void loadSettings();
bool loadSettings();
void saveSettings() const;
void displayColumnHeaderMenu();
void showPeerListMenu();
Expand Down
2 changes: 2 additions & 0 deletions src/webui/api/synccontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace

// Peer keys
const QString KEY_PEER_CLIENT = u"client"_qs;
const QString KEY_PEER_ID_CLIENT = u"peer_id_client"_qs;
const QString KEY_PEER_CONNECTION_TYPE = u"connection"_qs;
const QString KEY_PEER_COUNTRY = u"country"_qs;
const QString KEY_PEER_COUNTRY_CODE = u"country_code"_qs;
Expand Down Expand Up @@ -561,6 +562,7 @@ void SyncController::torrentPeersAction()
{KEY_PEER_IP, pi.address().ip.toString()},
{KEY_PEER_PORT, pi.address().port},
{KEY_PEER_CLIENT, pi.client()},
{KEY_PEER_ID_CLIENT, pi.peerIdClient()},
{KEY_PEER_PROGRESS, pi.progress()},
{KEY_PEER_DOWN_SPEED, pi.payloadDownSpeed()},
{KEY_PEER_UP_SPEED, pi.payloadUpSpeed()},
Expand Down
2 changes: 1 addition & 1 deletion src/webui/webapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include "base/utils/version.h"
#include "api/isessionmanager.h"

inline const Utils::Version<3, 2> API_VERSION {2, 8, 16};
inline const Utils::Version<3, 2> API_VERSION {2, 8, 17};

class APIController;
class AuthController;
Expand Down
1 change: 1 addition & 0 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,7 @@ window.qBittorrent.DynamicTable = (function() {
this.newColumn('connection', '', 'QBT_TR(Connection)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('flags', '', 'QBT_TR(Flags)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('client', '', 'QBT_TR(Client)QBT_TR[CONTEXT=PeerListWidget]', 140, true);
this.newColumn('peer_id_client', '', 'QBT_TR(Peer ID Client)QBT_TR[CONTEXT=PeerListWidget]', 60, false);
this.newColumn('progress', '', 'QBT_TR(Progress)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('dl_speed', '', 'QBT_TR(Down Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
this.newColumn('up_speed', '', 'QBT_TR(Up Speed)QBT_TR[CONTEXT=PeerListWidget]', 50, true);
Expand Down