diff --git a/src/base/addtorrentmanager.cpp b/src/base/addtorrentmanager.cpp index 14332098a..bce47d6ab 100644 --- a/src/base/addtorrentmanager.cpp +++ b/src/base/addtorrentmanager.cpp @@ -29,6 +29,7 @@ #include "addtorrentmanager.h" +#include "base/bittorrent/addtorrenterror.h" #include "base/bittorrent/infohash.h" #include "base/bittorrent/session.h" #include "base/bittorrent/torrentdescriptor.h" @@ -185,8 +186,8 @@ void AddTorrentManager::handleDuplicateTorrent(const QString &source message = tr("Trackers are merged from new source"); } - LogMsg(tr("Detected an attempt to add a duplicate torrent. Source: %1. Existing torrent: %2. Result: %3") - .arg(source, existingTorrent->name(), message)); + LogMsg(tr("Detected an attempt to add a duplicate torrent. Source: %1. Existing torrent: \"%2\". Torrent infohash: %3. Result: %4") + .arg(source, existingTorrent->name(), existingTorrent->infoHash().toString(), message)); emit addTorrentFailed(source, {BitTorrent::AddTorrentError::DuplicateTorrent, message}); } diff --git a/src/base/addtorrentmanager.h b/src/base/addtorrentmanager.h index 0621be7a2..c0044be65 100644 --- a/src/base/addtorrentmanager.h +++ b/src/base/addtorrentmanager.h @@ -35,7 +35,6 @@ #include #include "base/applicationcomponent.h" -#include "base/bittorrent/addtorrenterror.h" #include "base/bittorrent/addtorrentparams.h" #include "base/torrentfileguard.h" @@ -45,6 +44,7 @@ namespace BitTorrent class Session; class Torrent; class TorrentDescriptor; + struct AddTorrentError; } namespace Net diff --git a/src/base/bittorrent/infohash.cpp b/src/base/bittorrent/infohash.cpp index c4b514e8c..e4df6c619 100644 --- a/src/base/bittorrent/infohash.cpp +++ b/src/base/bittorrent/infohash.cpp @@ -29,6 +29,9 @@ #include "infohash.h" #include +#include + +#include "base/global.h" const int TorrentIDTypeId = qRegisterMetaType(); @@ -86,6 +89,28 @@ BitTorrent::TorrentID BitTorrent::InfoHash::toTorrentID() const #endif } +QString BitTorrent::InfoHash::toString() const +{ + // Returns a string that is suitable for logging purpose + + QString ret; + ret.reserve(40 + 64 + 2); // v1 hash length + v2 hash length + comma + + const SHA1Hash v1Hash = v1(); + const bool v1IsValid = v1Hash.isValid(); + if (v1IsValid) + ret += v1Hash.toString(); + + if (const SHA256Hash v2Hash = v2(); v2Hash.isValid()) + { + if (v1IsValid) + ret += u", "; + ret += v2Hash.toString(); + } + + return ret; +} + BitTorrent::InfoHash::operator WrappedType() const { return m_nativeHash; diff --git a/src/base/bittorrent/infohash.h b/src/base/bittorrent/infohash.h index d870e0fd2..2153c104f 100644 --- a/src/base/bittorrent/infohash.h +++ b/src/base/bittorrent/infohash.h @@ -36,6 +36,8 @@ #include "base/digest32.h" +class QString; + using SHA1Hash = Digest32<160>; using SHA256Hash = Digest32<256>; @@ -79,6 +81,8 @@ namespace BitTorrent SHA256Hash v2() const; TorrentID toTorrentID() const; + QString toString() const; + operator WrappedType() const; private: diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index 9c4922c4e..6e290fa1b 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -2790,8 +2790,8 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr if (!isMergeTrackersEnabled()) { const QString message = tr("Merging of trackers is disabled"); - LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: %1. Result: %2") - .arg(torrent->name(), message)); + LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3") + .arg(torrent->name(), torrent->infoHash().toString(), message)); emit addTorrentFailed(infoHash, {AddTorrentError::DuplicateTorrent, message}); return false; } @@ -2800,8 +2800,8 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr if (isPrivate) { const QString message = tr("Trackers cannot be merged because it is a private torrent"); - LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: %1. Result: %2") - .arg(torrent->name(), message)); + LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3") + .arg(torrent->name(), torrent->infoHash().toString(), message)); emit addTorrentFailed(infoHash, {AddTorrentError::DuplicateTorrent, message}); return false; } @@ -2811,8 +2811,8 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr torrent->addUrlSeeds(source.urlSeeds()); const QString message = tr("Trackers are merged from new source"); - LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: %1. Result: %2") - .arg(torrent->name(), message)); + LogMsg(tr("Detected an attempt to add a duplicate torrent. Existing torrent: \"%1\". Torrent infohash: %2. Result: %3") + .arg(torrent->name(), torrent->infoHash().toString(), message)); emit addTorrentFailed(infoHash, {AddTorrentError::DuplicateTorrent, message}); return false; } diff --git a/src/base/rss/rss_autodownloader.cpp b/src/base/rss/rss_autodownloader.cpp index c40218457..294e3289e 100644 --- a/src/base/rss/rss_autodownloader.cpp +++ b/src/base/rss/rss_autodownloader.cpp @@ -43,6 +43,7 @@ #include "base/addtorrentmanager.h" #include "base/asyncfilestorage.h" +#include "base/bittorrent/addtorrenterror.h" #include "base/bittorrent/session.h" #include "base/bittorrent/torrentdescriptor.h" #include "base/global.h" diff --git a/src/base/rss/rss_autodownloader.h b/src/base/rss/rss_autodownloader.h index dcd752bcf..02b52231a 100644 --- a/src/base/rss/rss_autodownloader.h +++ b/src/base/rss/rss_autodownloader.h @@ -37,7 +37,6 @@ #include #include "base/applicationcomponent.h" -#include "base/bittorrent/addtorrenterror.h" #include "base/exceptions.h" #include "base/settingvalue.h" #include "base/utils/thread.h" @@ -48,6 +47,11 @@ class Application; class AsyncFileStorage; struct ProcessingJob; +namespace BitTorrent +{ + struct AddTorrentError; +} + namespace RSS { class Article; diff --git a/src/gui/guiaddtorrentmanager.cpp b/src/gui/guiaddtorrentmanager.cpp index 9bcff9863..5ed945383 100644 --- a/src/gui/guiaddtorrentmanager.cpp +++ b/src/gui/guiaddtorrentmanager.cpp @@ -33,7 +33,6 @@ #include "base/bittorrent/session.h" #include "base/bittorrent/torrentdescriptor.h" -#include "base/logger.h" #include "base/net/downloadmanager.h" #include "base/preferences.h" #include "base/torrentfileguard.h"