Browse Source

Fix peer count issue when tracker responds with zero figure

Sometimes tracker may respond with 0 for num_complete and num_incomplete and we should display that instead of deducing the peer count from peer list. We should only fallback to peer list if tracker does not respond with any information. In such cases num_incomplete and num_complete is set to -1 by libtorrent.

PR #17432.
adaptive-webui-19844
summer 2 years ago committed by GitHub
parent
commit
2071ec0c96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/base/bittorrent/torrent.h
  2. 18
      src/base/bittorrent/torrentimpl.cpp
  3. 2
      src/base/bittorrent/torrentimpl.h

2
src/base/bittorrent/torrent.h

@ -239,8 +239,6 @@ namespace BitTorrent @@ -239,8 +239,6 @@ namespace BitTorrent
virtual int totalSeedsCount() const = 0;
virtual int totalPeersCount() const = 0;
virtual int totalLeechersCount() const = 0;
virtual int completeCount() const = 0;
virtual int incompleteCount() const = 0;
virtual QDateTime lastSeenComplete() const = 0;
virtual QDateTime completedTime() const = 0;
virtual qlonglong timeSinceUpload() const = 0;

18
src/base/bittorrent/torrentimpl.cpp

@ -1153,30 +1153,18 @@ int TorrentImpl::leechsCount() const @@ -1153,30 +1153,18 @@ int TorrentImpl::leechsCount() const
int TorrentImpl::totalSeedsCount() const
{
return (m_nativeStatus.num_complete > 0) ? m_nativeStatus.num_complete : m_nativeStatus.list_seeds;
return (m_nativeStatus.num_complete > -1) ? m_nativeStatus.num_complete : m_nativeStatus.list_seeds;
}
int TorrentImpl::totalPeersCount() const
{
const int peers = m_nativeStatus.num_complete + m_nativeStatus.num_incomplete;
return (peers > 0) ? peers : m_nativeStatus.list_peers;
return (peers > -1) ? peers : m_nativeStatus.list_peers;
}
int TorrentImpl::totalLeechersCount() const
{
return (m_nativeStatus.num_incomplete > 0) ? m_nativeStatus.num_incomplete : (m_nativeStatus.list_peers - m_nativeStatus.list_seeds);
}
int TorrentImpl::completeCount() const
{
// additional info: https://github.com/qbittorrent/qBittorrent/pull/5300#issuecomment-267783646
return m_nativeStatus.num_complete;
}
int TorrentImpl::incompleteCount() const
{
// additional info: https://github.com/qbittorrent/qBittorrent/pull/5300#issuecomment-267783646
return m_nativeStatus.num_incomplete;
return (m_nativeStatus.num_incomplete > -1) ? m_nativeStatus.num_incomplete : (m_nativeStatus.list_peers - m_nativeStatus.list_seeds);
}
QDateTime TorrentImpl::lastSeenComplete() const

2
src/base/bittorrent/torrentimpl.h

@ -171,8 +171,6 @@ namespace BitTorrent @@ -171,8 +171,6 @@ namespace BitTorrent
int totalSeedsCount() const override;
int totalPeersCount() const override;
int totalLeechersCount() const override;
int completeCount() const override;
int incompleteCount() const override;
QDateTime lastSeenComplete() const override;
QDateTime completedTime() const override;
qlonglong timeSinceUpload() const override;

Loading…
Cancel
Save