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
parent 4da4fb0676
commit 561b597031
34 changed files with 463 additions and 320 deletions

View File

@@ -218,6 +218,11 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
, m_session(session)
, m_nativeSession(nativeSession)
, m_nativeHandle(nativeHandle)
#if (LIBTORRENT_VERSION_NUM >= 20000)
, m_infoHash(m_nativeHandle.info_hashes())
#else
, m_infoHash(m_nativeHandle.info_hash())
#endif
, m_name(params.name)
, m_savePath(Utils::Fs::toNativePath(params.savePath))
, m_category(params.category)
@@ -235,7 +240,6 @@ TorrentImpl::TorrentImpl(Session *session, lt::session *nativeSession
if (m_useAutoTMM)
m_savePath = Utils::Fs::toNativePath(m_session->categorySavePath(m_category));
m_hash = InfoHash {m_nativeHandle.info_hash()};
if (m_ltAddTorrentParams.ti)
{
// Initialize it only if torrent is added with metadata.
@@ -280,9 +284,9 @@ bool TorrentImpl::isValid() const
return m_nativeHandle.is_valid();
}
InfoHash TorrentImpl::hash() const
InfoHash TorrentImpl::infoHash() const
{
return m_hash;
return m_infoHash;
}
QString TorrentImpl::name() const
@@ -297,7 +301,7 @@ QString TorrentImpl::name() const
if (!name.isEmpty())
return name;
return m_hash.toString();
return id().toString();
}
QDateTime TorrentImpl::creationDate() const