Merge pull request #8068 from thalieht/readableFlags

Make peer information flags in peerlist more readable
This commit is contained in:
sledgehammer999 2017-12-23 19:33:19 +02:00 committed by GitHub
commit b11c33b2d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -273,18 +273,20 @@ qreal PeerInfo::relevance() const
void PeerInfo::determineFlags() void PeerInfo::determineFlags()
{ {
QStringList flagsDescriptionList;
if (isInteresting()) { if (isInteresting()) {
// d = Your client wants to download, but peer doesn't want to send (interested and choked) // d = Your client wants to download, but peer doesn't want to send (interested and choked)
if (isRemoteChocked()) { if (isRemoteChocked()) {
m_flags += "d "; m_flags += "d ";
m_flagsDescription += tr("interested(local) and choked(peer)"); flagsDescriptionList += "d = "
m_flagsDescription += ", "; + tr("Interested(local) and Choked(peer)");
} }
else { else {
// D = Currently downloading (interested and not choked) // D = Currently downloading (interested and not choked)
m_flags += "D "; m_flags += "D ";
m_flagsDescription += tr("interested(local) and unchoked(peer)"); flagsDescriptionList += "D = "
m_flagsDescription += ", "; + tr("interested(local) and unchoked(peer)");
} }
} }
@ -292,97 +294,95 @@ void PeerInfo::determineFlags()
// u = Peer wants your client to upload, but your client doesn't want to (interested and choked) // u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
if (isChocked()) { if (isChocked()) {
m_flags += "u "; m_flags += "u ";
m_flagsDescription += tr("interested(peer) and choked(local)"); flagsDescriptionList += "u = "
m_flagsDescription += ", "; + tr("interested(peer) and choked(local)");
} }
else { else {
// U = Currently uploading (interested and not choked) // U = Currently uploading (interested and not choked)
m_flags += "U "; m_flags += "U ";
m_flagsDescription += tr("interested(peer) and unchoked(local)"); flagsDescriptionList += "U = "
m_flagsDescription += ", "; + tr("interested(peer) and unchoked(local)");
} }
} }
// O = Optimistic unchoke // O = Optimistic unchoke
if (optimisticUnchoke()) { if (optimisticUnchoke()) {
m_flags += "O "; m_flags += "O ";
m_flagsDescription += tr("optimistic unchoke"); flagsDescriptionList += "O = "
m_flagsDescription += ", "; + tr("optimistic unchoke");
} }
// S = Peer is snubbed // S = Peer is snubbed
if (isSnubbed()) { if (isSnubbed()) {
m_flags += "S "; m_flags += "S ";
m_flagsDescription += tr("peer snubbed"); flagsDescriptionList += "S = "
m_flagsDescription += ", "; + tr("peer snubbed");
} }
// I = Peer is an incoming connection // I = Peer is an incoming connection
if (!isLocalConnection()) { if (!isLocalConnection()) {
m_flags += "I "; m_flags += "I ";
m_flagsDescription += tr("incoming connection"); flagsDescriptionList += "I = "
m_flagsDescription += ", "; + tr("incoming connection");
} }
// K = Peer is unchoking your client, but your client is not interested // K = Peer is unchoking your client, but your client is not interested
if (!isRemoteChocked() && !isInteresting()) { if (!isRemoteChocked() && !isInteresting()) {
m_flags += "K "; m_flags += "K ";
m_flagsDescription += tr("not interested(local) and unchoked(peer)"); flagsDescriptionList += "K = "
m_flagsDescription += ", "; + tr("not interested(local) and unchoked(peer)");
} }
// ? = Your client unchoked the peer but the peer is not interested // ? = Your client unchoked the peer but the peer is not interested
if (!isChocked() && !isRemoteInterested()) { if (!isChocked() && !isRemoteInterested()) {
m_flags += "? "; m_flags += "? ";
m_flagsDescription += tr("not interested(peer) and unchoked(local)"); flagsDescriptionList += "? = "
m_flagsDescription += ", "; + tr("not interested(peer) and unchoked(local)");
} }
// X = Peer was included in peerlists obtained through Peer Exchange (PEX) // X = Peer was included in peerlists obtained through Peer Exchange (PEX)
if (fromPeX()) { if (fromPeX()) {
m_flags += "X "; m_flags += "X ";
m_flagsDescription += tr("peer from PEX"); flagsDescriptionList += "X = "
m_flagsDescription += ", "; + tr("peer from PEX");
} }
// H = Peer was obtained through DHT // H = Peer was obtained through DHT
if (fromDHT()) { if (fromDHT()) {
m_flags += "H "; m_flags += "H ";
m_flagsDescription += tr("peer from DHT"); flagsDescriptionList += "H = "
m_flagsDescription += ", "; + tr("peer from DHT");
} }
// E = Peer is using Protocol Encryption (all traffic) // E = Peer is using Protocol Encryption (all traffic)
if (isRC4Encrypted()) { if (isRC4Encrypted()) {
m_flags += "E "; m_flags += "E ";
m_flagsDescription += tr("encrypted traffic"); flagsDescriptionList += "E = "
m_flagsDescription += ", "; + tr("encrypted traffic");
} }
// e = Peer is using Protocol Encryption (handshake) // e = Peer is using Protocol Encryption (handshake)
if (isPlaintextEncrypted()) { if (isPlaintextEncrypted()) {
m_flags += "e "; m_flags += "e ";
m_flagsDescription += tr("encrypted handshake"); flagsDescriptionList += "e = "
m_flagsDescription += ", "; + tr("encrypted handshake");
} }
// P = Peer is using uTorrent uTP // P = Peer is using uTorrent uTP
if (useUTPSocket()) { if (useUTPSocket()) {
m_flags += "P "; m_flags += "P ";
m_flagsDescription += QString::fromUtf8(C_UTP); flagsDescriptionList += "P = "
m_flagsDescription += ", "; + QString::fromUtf8(C_UTP);
} }
// L = Peer is local // L = Peer is local
if (fromLSD()) { if (fromLSD()) {
m_flags += "L"; m_flags += "L";
m_flagsDescription += tr("peer from LSD"); flagsDescriptionList += "L = "
+ tr("peer from LSD");
} }
m_flags = m_flags.trimmed(); m_flags = m_flags.trimmed();
m_flagsDescription = m_flagsDescription.trimmed(); m_flagsDescription = flagsDescriptionList.join('\n');
if (m_flagsDescription.endsWith(',', Qt::CaseInsensitive))
m_flagsDescription.chop(1);
} }
QString PeerInfo::flags() const QString PeerInfo::flags() const