Improve "info hash" handling

Define "torrent ID" concept, which is either a SHA1 hash for torrents of version 1,
or a SHA256 hash (truncated to SHA1 hash length) for torrents of version 2.
Add support for native libtorrent2 info hashes.
This commit is contained in:
Vladimir Golovnev (Glassez) 2021-03-05 12:43:58 +03:00
commit 561b597031
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
34 changed files with 463 additions and 320 deletions

View file

@ -77,10 +77,10 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
const bool isFirstTorrentPEXDisabled = torrents[0]->isPEXDisabled();
const bool isFirstTorrentLSDDisabled = torrents[0]->isLSDDisabled();
m_torrentHashes.reserve(torrents.size());
m_torrentIDs.reserve(torrents.size());
for (const BitTorrent::Torrent *torrent : torrents)
{
m_torrentHashes << torrent->hash();
m_torrentIDs << torrent->id();
if (allSameUpLimit)
{
if (qMax(0, torrent->uploadLimit()) != firstTorrentUpLimit)
@ -288,9 +288,9 @@ void TorrentOptionsDialog::accept()
}
const auto *session = BitTorrent::Session::instance();
for (const BitTorrent::InfoHash &hash : asConst(m_torrentHashes))
for (const BitTorrent::TorrentID &id : asConst(m_torrentIDs))
{
BitTorrent::Torrent *torrent = session->findTorrent(hash);
BitTorrent::Torrent *torrent = session->findTorrent(id);
if (!torrent) continue;
if (m_initialValues.upSpeedLimit != m_ui->spinUploadLimit->value())