mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-14 08:48:17 +00:00
Add torrent for preloading magnet asynchronously
This commit is contained in:
parent
0b70ccf9e9
commit
6aee7f95b7
@ -2832,21 +2832,8 @@ bool SessionImpl::downloadMetadata(const MagnetUri &magnetUri)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Adding torrent to libtorrent session
|
// Adding torrent to libtorrent session
|
||||||
lt::error_code ec;
|
m_nativeSession->async_add_torrent(p);
|
||||||
lt::torrent_handle torrentHandle = m_nativeSession->add_torrent(p, ec);
|
m_downloadedMetadata.insert(id, {});
|
||||||
if (ec)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// waiting for metadata...
|
|
||||||
m_downloadedMetadata.insert(id, torrentHandle);
|
|
||||||
if (infoHash.isHybrid())
|
|
||||||
{
|
|
||||||
// index hybrid magnet links by both v1 and v2 info hashes
|
|
||||||
const auto altID = TorrentID::fromSHA1Hash(infoHash.v1());
|
|
||||||
m_downloadedMetadata.insert(altID, torrentHandle);
|
|
||||||
}
|
|
||||||
++m_extraLimit;
|
|
||||||
adjustLimits();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -5066,18 +5053,36 @@ void SessionImpl::handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts)
|
|||||||
#else
|
#else
|
||||||
const InfoHash infoHash {(hasMetadata ? params.ti->info_hash() : params.info_hash)};
|
const InfoHash infoHash {(hasMetadata ? params.ti->info_hash() : params.info_hash)};
|
||||||
#endif
|
#endif
|
||||||
m_loadingTorrents.remove(TorrentID::fromInfoHash(infoHash));
|
if (const auto loadingTorrentsIter = m_loadingTorrents.find(TorrentID::fromInfoHash(infoHash))
|
||||||
|
; loadingTorrentsIter != m_loadingTorrents.end())
|
||||||
|
{
|
||||||
|
m_loadingTorrents.erase(loadingTorrentsIter);
|
||||||
|
}
|
||||||
|
else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(TorrentID::fromInfoHash(infoHash))
|
||||||
|
; downloadedMetadataIter != m_downloadedMetadata.end())
|
||||||
|
{
|
||||||
|
m_downloadedMetadata.erase(downloadedMetadataIter);
|
||||||
|
if (infoHash.isHybrid())
|
||||||
|
{
|
||||||
|
// index hybrid magnet links by both v1 and v2 info hashes
|
||||||
|
const auto altID = TorrentID::fromSHA1Hash(infoHash.v1());
|
||||||
|
m_downloadedMetadata.remove(altID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef QBT_USES_LIBTORRENT2
|
#ifdef QBT_USES_LIBTORRENT2
|
||||||
const auto torrentID = TorrentID::fromInfoHash(alert->handle.info_hashes());
|
const InfoHash infoHash {alert->handle.info_hashes()};
|
||||||
#else
|
#else
|
||||||
const auto torrentID = TorrentID::fromInfoHash(alert->handle.info_hash());
|
const InfoHash infoHash {alert->handle.info_hash()};
|
||||||
#endif
|
#endif
|
||||||
const auto loadingTorrentsIter = m_loadingTorrents.find(torrentID);
|
const auto torrentID = TorrentID::fromInfoHash(infoHash);
|
||||||
if (loadingTorrentsIter != m_loadingTorrents.end())
|
|
||||||
|
if (const auto loadingTorrentsIter = m_loadingTorrents.find(torrentID)
|
||||||
|
; loadingTorrentsIter != m_loadingTorrents.end())
|
||||||
{
|
{
|
||||||
LoadTorrentParams params = loadingTorrentsIter.value();
|
LoadTorrentParams params = loadingTorrentsIter.value();
|
||||||
m_loadingTorrents.erase(loadingTorrentsIter);
|
m_loadingTorrents.erase(loadingTorrentsIter);
|
||||||
@ -5085,6 +5090,20 @@ void SessionImpl::handleAddTorrentAlerts(const std::vector<lt::alert *> &alerts)
|
|||||||
Torrent *torrent = createTorrent(alert->handle, params);
|
Torrent *torrent = createTorrent(alert->handle, params);
|
||||||
loadedTorrents.append(torrent);
|
loadedTorrents.append(torrent);
|
||||||
}
|
}
|
||||||
|
else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(torrentID)
|
||||||
|
; downloadedMetadataIter != m_downloadedMetadata.end())
|
||||||
|
{
|
||||||
|
++m_extraLimit;
|
||||||
|
adjustLimits();
|
||||||
|
|
||||||
|
downloadedMetadataIter.value() = alert->handle;
|
||||||
|
if (infoHash.isHybrid())
|
||||||
|
{
|
||||||
|
// index hybrid magnet links by both v1 and v2 info hashes
|
||||||
|
const auto altID = TorrentID::fromSHA1Hash(infoHash.v1());
|
||||||
|
m_downloadedMetadata[altID] = alert->handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loadedTorrents.isEmpty())
|
if (!loadedTorrents.isEmpty())
|
||||||
|
Loading…
Reference in New Issue
Block a user