Skip to content

Commit

Permalink
Apply "merge trackers" logic regardless of way the torrent is added
Browse files Browse the repository at this point in the history
PR #21299.
  • Loading branch information
glassez committed Sep 7, 2024
1 parent d4ccf30 commit 3e96048
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
33 changes: 32 additions & 1 deletion src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2711,8 +2711,39 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
if (m_loadingTorrents.contains(id) || (infoHash.isHybrid() && m_loadingTorrents.contains(altID)))
return false;

if (findTorrent(infoHash))
if (Torrent *torrent = findTorrent(infoHash))
{
// a duplicate torrent is being added

if (hasMetadata)
{
// Trying to set metadata to existing torrent in case if it has none
torrent->setMetadata(*source.info());
}

if (!isMergeTrackersEnabled())
{
LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: %1. Result: %2")
.arg(torrent->name(), tr("Merging of trackers is disabled")));
return false;
}

const bool isPrivate = torrent->isPrivate() || (hasMetadata && source.info()->isPrivate());
if (isPrivate)
{
LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: %1. Result: %2")
.arg(torrent->name(), tr("Trackers cannot be merged because it is a private torrent")));
return false;
}

// merge trackers and web seeds
torrent->addTrackers(source.trackers());
torrent->addUrlSeeds(source.urlSeeds());

LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: %1. Result: %2")
.arg(torrent->name(), tr("Trackers are merged from new source")));
return false;
}

// It looks illogical that we don't just use an existing handle,
// but as previous experience has shown, it actually creates unnecessary
Expand Down
1 change: 0 additions & 1 deletion src/base/net/smtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class QSslSocket;
#else
class QTcpSocket;
#endif
class QTextCodec;

namespace Net
{
Expand Down

0 comments on commit 3e96048

Please sign in to comment.