Capitalize "peer flags" descriptions

And use a helper function to build the descriptions.
This commit is contained in:
Chocobo1 2021-04-18 03:17:40 +08:00
parent c7c7924d37
commit e38128119c
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C

View File

@ -257,123 +257,86 @@ qreal PeerInfo::relevance() const
void PeerInfo::determineFlags() void PeerInfo::determineFlags()
{ {
const auto updateFlags = [this](const QChar specifier, const QString &explanation)
{
m_flags += (specifier + QLatin1Char(' '));
m_flagsDescription += QString::fromLatin1("%1 = %2\n").arg(specifier, explanation);
};
if (isInteresting()) if (isInteresting())
{ {
// d = Your client wants to download, but peer doesn't want to send (interested and choked)
if (isRemoteChocked()) if (isRemoteChocked())
{ {
m_flags += "d "; // d = Your client wants to download, but peer doesn't want to send (interested and choked)
m_flagsDescription += ("d = " updateFlags(QLatin1Char('d'), tr("Interested (local) and choked (peer)"));
+ tr("Interested(local) and Choked(peer)") + '\n');
} }
else else
{ {
// D = Currently downloading (interested and not choked) // D = Currently downloading (interested and not choked)
m_flags += "D "; updateFlags(QLatin1Char('D'), tr("Interested (local) and unchoked (peer)"));
m_flagsDescription += ("D = "
+ tr("interested(local) and unchoked(peer)") + '\n');
} }
} }
if (isRemoteInterested()) if (isRemoteInterested())
{ {
// u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
if (isChocked()) if (isChocked())
{ {
m_flags += "u "; // u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
m_flagsDescription += ("u = " updateFlags(QLatin1Char('u'), tr("Interested (peer) and choked (local)"));
+ tr("interested(peer) and choked(local)") + '\n');
} }
else else
{ {
// U = Currently uploading (interested and not choked) // U = Currently uploading (interested and not choked)
m_flags += "U "; updateFlags(QLatin1Char('U'), tr("Interested (peer) and unchoked (local)"));
m_flagsDescription += ("U = "
+ tr("interested(peer) and unchoked(local)") + '\n');
} }
} }
// O = Optimistic unchoke // O = Optimistic unchoke
if (optimisticUnchoke()) if (optimisticUnchoke())
{ updateFlags(QLatin1Char('O'), tr("Optimistic unchoke"));
m_flags += "O ";
m_flagsDescription += ("O = " + tr("optimistic unchoke") + '\n');
}
// S = Peer is snubbed // S = Peer is snubbed
if (isSnubbed()) if (isSnubbed())
{ updateFlags(QLatin1Char('S'), tr("Peer snubbed"));
m_flags += "S ";
m_flagsDescription += ("S = " + tr("peer snubbed") + '\n');
}
// I = Peer is an incoming connection // I = Peer is an incoming connection
if (!isLocalConnection()) if (!isLocalConnection())
{ updateFlags(QLatin1Char('I'), tr("Incoming connection"));
m_flags += "I ";
m_flagsDescription += ("I = " + tr("incoming connection") + '\n');
}
// 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())
{ updateFlags(QLatin1Char('K'), tr("Not interested (local) and unchoked (peer)"));
m_flags += "K ";
m_flagsDescription += ("K = "
+ tr("not interested(local) and unchoked(peer)") + '\n');
}
// ? = 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())
{ updateFlags(QLatin1Char('?'), tr("Not interested (peer) and unchoked (local)"));
m_flags += "? ";
m_flagsDescription += ("? = "
+ tr("not interested(peer) and unchoked(local)") + '\n');
}
// 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())
{ updateFlags(QLatin1Char('X'), tr("Peer from PEX"));
m_flags += "X ";
m_flagsDescription += ("X = " + tr("peer from PEX") + '\n');
}
// H = Peer was obtained through DHT // H = Peer was obtained through DHT
if (fromDHT()) if (fromDHT())
{ updateFlags(QLatin1Char('H'), tr("Peer from DHT"));
m_flags += "H ";
m_flagsDescription += ("H = " + tr("peer from DHT") + '\n');
}
// E = Peer is using Protocol Encryption (all traffic) // E = Peer is using Protocol Encryption (all traffic)
if (isRC4Encrypted()) if (isRC4Encrypted())
{ updateFlags(QLatin1Char('E'), tr("Encrypted traffic"));
m_flags += "E ";
m_flagsDescription += ("E = " + tr("encrypted traffic") + '\n');
}
// e = Peer is using Protocol Encryption (handshake) // e = Peer is using Protocol Encryption (handshake)
if (isPlaintextEncrypted()) if (isPlaintextEncrypted())
{ updateFlags(QLatin1Char('e'), tr("Encrypted handshake"));
m_flags += "e ";
m_flagsDescription += ("e = " + tr("encrypted handshake") + '\n');
}
// P = Peer is using uTorrent uTP // P = Peer is using uTorrent uTP
if (useUTPSocket()) if (useUTPSocket())
{ updateFlags(QLatin1Char('P'), QString::fromUtf8(C_UTP));
m_flags += "P ";
m_flagsDescription += ("P = " + QString::fromUtf8(C_UTP) + '\n');
}
// L = Peer is local // L = Peer is local
if (fromLSD()) if (fromLSD())
{ updateFlags(QLatin1Char('L'), tr("Peer from LSD"));
m_flags += "L ";
m_flagsDescription += ("L = " + tr("peer from LSD") + '\n');
}
m_flags = m_flags.trimmed(); m_flags.chop(1);
m_flagsDescription = m_flagsDescription.trimmed(); m_flagsDescription.chop(1);
} }
QString PeerInfo::flags() const QString PeerInfo::flags() const