Browse Source

Add additional trackers without extra blocking call

adaptive-webui-19844
Vladimir Golovnev (Glassez) 3 years ago
parent
commit
35fcf39fc8
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 18
      src/base/bittorrent/session.cpp
  2. 12
      src/base/bittorrent/torrentimpl.cpp

18
src/base/bittorrent/session.cpp

@ -2310,6 +2310,17 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source @@ -2310,6 +2310,17 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
for (int i = 0; i < addTorrentParams.filePriorities.size(); ++i)
p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = LT::toNative(addTorrentParams.filePriorities[i]);
if (isAddTrackersEnabled() && !torrentInfo.isPrivate())
{
p.trackers.reserve(static_cast<std::size_t>(m_additionalTrackerList.size()));
p.tracker_tiers.reserve(static_cast<std::size_t>(m_additionalTrackerList.size()));
for (const TrackerEntry &trackerEntry : asConst(m_additionalTrackerList))
{
p.trackers.push_back(trackerEntry.url.toStdString());
p.tracker_tiers.push_back(trackerEntry.tier);
}
}
p.ti = torrentInfo.nativeInfo();
}
else
@ -4899,7 +4910,7 @@ void Session::createTorrent(const lt::torrent_handle &nativeHandle) @@ -4899,7 +4910,7 @@ void Session::createTorrent(const lt::torrent_handle &nativeHandle)
const LoadTorrentParams params = m_loadingTorrents.take(torrentID);
auto *const torrent = new TorrentImpl {this, m_nativeSession, nativeHandle, params};
auto *const torrent = new TorrentImpl(this, m_nativeSession, nativeHandle, params);
m_torrents.insert(torrent->id(), torrent);
const bool hasMetadata = torrent->hasMetadata();
@ -4918,14 +4929,13 @@ void Session::createTorrent(const lt::torrent_handle &nativeHandle) @@ -4918,14 +4929,13 @@ void Session::createTorrent(const lt::torrent_handle &nativeHandle)
exportTorrentFile(torrentInfo, torrentExportDirectory(), torrent->name());
}
}
if (isAddTrackersEnabled() && !torrent->isPrivate())
torrent->addTrackers(m_additionalTrackerList);
}
if (((torrent->ratioLimit() >= 0) || (torrent->seedingTimeLimit() >= 0))
&& !m_seedingLimitTimer->isActive())
{
m_seedingLimitTimer->start();
}
// Send torrent addition signal
emit torrentLoaded(torrent);

12
src/base/bittorrent/torrentimpl.cpp

@ -1470,18 +1470,18 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled) @@ -1470,18 +1470,18 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled)
// Updating file priorities is an async operation in libtorrent, when we just updated it and immediately query it
// we might get the old/wrong values, so we rely on `updatedFilePrio` in this case.
for (int index = 0; index < m_filePriorities.size(); ++index)
for (int fileIndex = 0; fileIndex < m_filePriorities.size(); ++fileIndex)
{
const DownloadPriority filePrio = m_filePriorities[index];
const DownloadPriority filePrio = m_filePriorities[fileIndex];
if (filePrio <= DownloadPriority::Ignored)
continue;
// Determine the priority to set
const lt::download_priority_t piecePrio = LT::toNative(enabled ? DownloadPriority::Maximum : filePrio);
const TorrentInfo::PieceRange pieceRange = m_torrentInfo.filePieces(index);
const TorrentInfo::PieceRange pieceRange = m_torrentInfo.filePieces(fileIndex);
// worst case: AVI index = 1% of total file size (at the end of the file)
const int numPieces = std::ceil(fileSize(index) * 0.01 / pieceLength());
const int numPieces = std::ceil(fileSize(fileIndex) * 0.01 / pieceLength());
for (int i = 0; i < numPieces; ++i)
{
piecePriorities[pieceRange.first() + i] = piecePrio;
@ -1490,8 +1490,8 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled) @@ -1490,8 +1490,8 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled)
const int firstPiece = pieceRange.first() + numPieces;
const int lastPiece = pieceRange.last() - numPieces;
for (int index = firstPiece; index <= lastPiece; ++index)
piecePriorities[index] = LT::toNative(filePrio);
for (int pieceIndex = firstPiece; pieceIndex <= lastPiece; ++pieceIndex)
piecePriorities[pieceIndex] = LT::toNative(filePrio);
}
m_nativeHandle.prioritize_pieces(piecePriorities);

Loading…
Cancel
Save