Implement Peer ID Client column for Peers tab

PR #17940.
This commit is contained in:
Hanabishi
2022-11-06 09:21:31 +05:00
committed by GitHub
parent 99b7663fa9
commit 6a560016dd
7 changed files with 46 additions and 5 deletions

View File

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

View File

@@ -78,6 +78,7 @@ namespace BitTorrent
PeerAddress address() const;
QString client() const;
QString peerIdClient() const;
qreal progress() const;
int payloadUpSpeed() const;
int payloadDownSpeed() const;