|
|
@ -39,8 +39,8 @@ using namespace BitTorrent; |
|
|
|
|
|
|
|
|
|
|
|
PeerInfo::PeerInfo(const Torrent *torrent, const lt::peer_info &nativeInfo) |
|
|
|
PeerInfo::PeerInfo(const Torrent *torrent, const lt::peer_info &nativeInfo) |
|
|
|
: m_nativeInfo(nativeInfo) |
|
|
|
: m_nativeInfo(nativeInfo) |
|
|
|
|
|
|
|
, m_relevance(calcRelevance(torrent)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
calcRelevance(torrent); |
|
|
|
|
|
|
|
determineFlags(); |
|
|
|
determineFlags(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -226,28 +226,16 @@ QString PeerInfo::connectionType() const |
|
|
|
: QLatin1String {"Web"}; |
|
|
|
: QLatin1String {"Web"}; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PeerInfo::calcRelevance(const Torrent *torrent) |
|
|
|
qreal PeerInfo::calcRelevance(const Torrent *torrent) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
const QBitArray allPieces = torrent->pieces(); |
|
|
|
const QBitArray allPieces = torrent->pieces(); |
|
|
|
const QBitArray peerPieces = pieces(); |
|
|
|
const int localMissing = allPieces.count(false); |
|
|
|
|
|
|
|
if (localMissing <= 0) |
|
|
|
int localMissing = 0; |
|
|
|
return 0; |
|
|
|
int remoteHaves = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < allPieces.size(); ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!allPieces[i]) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
++localMissing; |
|
|
|
|
|
|
|
if (peerPieces[i]) |
|
|
|
|
|
|
|
++remoteHaves; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (localMissing == 0) |
|
|
|
const QBitArray peerPieces = pieces(); |
|
|
|
m_relevance = 0.0; |
|
|
|
const int remoteHaves = (peerPieces & (~allPieces)).count(true); |
|
|
|
else |
|
|
|
return static_cast<qreal>(remoteHaves) / localMissing; |
|
|
|
m_relevance = static_cast<qreal>(remoteHaves) / localMissing; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
qreal PeerInfo::relevance() const |
|
|
|
qreal PeerInfo::relevance() const |
|
|
|