Prevent duplicate url (#1231)
prevent creating torrents with duplicate trackers as well as adding duplicate trackers to torrent_info
This commit is contained in:
parent
5f04103a9d
commit
91845aa6c8
|
@ -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()
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 <cstring>
|
||||
|
||||
|
@ -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<char> buffer;
|
||||
|
|
Loading…
Reference in New Issue