forked from qbittorrent/qBittorrent
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
679 additions
and
370 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Bittorrent Client using Qt and libtorrent. | ||
* Copyright (C) 2015-2023 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2015-2024 Vladimir Golovnev <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -33,14 +33,16 @@ | |
#include "base/bittorrent/ltqbitarray.h" | ||
#include "base/net/geoipmanager.h" | ||
#include "base/unicodestrings.h" | ||
#include "base/utils/bytearray.h" | ||
#include "peeraddress.h" | ||
|
||
#ifdef QBT_USES_LIBTORRENT2 | ||
#include "base/utils/bytearray.h" | ||
#endif | ||
|
||
using namespace BitTorrent; | ||
|
||
PeerInfo::PeerInfo(const lt::peer_info &nativeInfo, const QBitArray &allPieces) | ||
PeerInfo::PeerInfo(const lt::peer_info &nativeInfo) | ||
: m_nativeInfo(nativeInfo) | ||
, m_relevance(calcRelevance(allPieces)) | ||
{ | ||
determineFlags(); | ||
} | ||
|
@@ -271,22 +273,6 @@ QString PeerInfo::connectionType() const | |
: u"Web"_s; | ||
} | ||
|
||
qreal PeerInfo::calcRelevance(const QBitArray &allPieces) const | ||
{ | ||
const int localMissing = allPieces.count(false); | ||
if (localMissing <= 0) | ||
return 0; | ||
|
||
const QBitArray peerPieces = pieces(); | ||
const int remoteHaves = (peerPieces & (~allPieces)).count(true); | ||
return static_cast<qreal>(remoteHaves) / localMissing; | ||
} | ||
|
||
qreal PeerInfo::relevance() const | ||
{ | ||
return m_relevance; | ||
} | ||
|
||
void PeerInfo::determineFlags() | ||
{ | ||
const auto updateFlags = [this](const QChar specifier, const QString &explanation) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Bittorrent Client using Qt and libtorrent. | ||
* Copyright (C) 2015-2023 Vladimir Golovnev <[email protected]> | ||
* Copyright (C) 2015-2024 Vladimir Golovnev <[email protected]> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
|
@@ -44,7 +44,7 @@ namespace BitTorrent | |
|
||
public: | ||
PeerInfo() = default; | ||
PeerInfo(const lt::peer_info &nativeInfo, const QBitArray &allPieces); | ||
explicit PeerInfo(const lt::peer_info &nativeInfo); | ||
|
||
bool fromDHT() const; | ||
bool fromPeX() const; | ||
|
@@ -86,18 +86,15 @@ namespace BitTorrent | |
qlonglong totalDownload() const; | ||
QBitArray pieces() const; | ||
QString connectionType() const; | ||
qreal relevance() const; | ||
QString flags() const; | ||
QString flagsDescription() const; | ||
QString country() const; | ||
int downloadingPieceIndex() const; | ||
|
||
private: | ||
qreal calcRelevance(const QBitArray &allPieces) const; | ||
void determineFlags(); | ||
|
||
lt::peer_info m_nativeInfo = {}; | ||
qreal m_relevance = 0; | ||
QString m_flags; | ||
QString m_flagsDescription; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.