diff --git a/src/create_torrent.cpp b/src/create_torrent.cpp index 1f94dbc85..0e306bd47 100644 --- a/src/create_torrent.cpp +++ b/src/create_torrent.cpp @@ -664,6 +664,9 @@ namespace libtorrent void create_torrent::add_tracker(string_view url, int const tier) { + auto i = std::find_if(m_urls.begin(), m_urls.end() + , [&url](announce_entry const& ae) { return ae.first == url.to_string(); }); + if (i != m_urls.end()) return; m_urls.push_back(announce_entry(url.to_string(), tier)); std::sort(m_urls.begin(), m_urls.end() diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 5bbcba528..9c9665e1b 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1347,6 +1347,7 @@ namespace libtorrent if (ec) return false; m_info_hash = p.info_hash; + m_urls.reserve(m_urls.size() + p.trackers.size()); for (auto const& url : p.trackers) m_urls.push_back(announce_entry(url)); @@ -1534,6 +1535,10 @@ namespace libtorrent void torrent_info::add_tracker(std::string const& url, int tier) { + auto i = std::find_if(m_urls.begin(), m_urls.end() + , [&url](announce_entry const& ae) { return ae.url == url; }); + if (i != m_urls.end()) return; + announce_entry e(url); e.tier = tier; e.source = announce_entry::source_client; diff --git a/test/test_create_torrent.cpp b/test/test_create_torrent.cpp index 7fcf33c57..7423d5bb4 100644 --- a/test/test_create_torrent.cpp +++ b/test/test_create_torrent.cpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/create_torrent.hpp" #include "libtorrent/bencode.hpp" #include "libtorrent/aux_/escape_string.hpp" // for convert_path_to_posix +#include "libtorrent/announce_entry.hpp" #include @@ -49,6 +50,10 @@ TORRENT_TEST(create_verbatim_torrent) lt::torrent_info info(test_torrent, sizeof(test_torrent) - 1); + info.add_tracker("http://test.com"); + info.add_tracker("http://test.com"); + TEST_EQUAL(info.trackers().size(), 1); + lt::create_torrent t(info); std::vector buffer;