diff --git a/src/settings_pack.cpp b/src/settings_pack.cpp index 9fca8b244..991cc53a9 100644 --- a/src/settings_pack.cpp +++ b/src/settings_pack.cpp @@ -41,11 +41,19 @@ POSSIBILITY OF SUCH DAMAGE. namespace { + template + bool compare_first(std::pair const& lhs + , std::pair const& rhs) + { + return lhs.first < rhs.first; + } + template void insort_replace(std::vector >& c, std::pair const& v) { typedef std::vector > container_t; - typename container_t::iterator i = std::lower_bound(c.begin(), c.end(), v); + typename container_t::iterator i = std::lower_bound(c.begin(), c.end(), v + , &compare_first); if (i != c.end() && i->first == v.first) i->second = v.second; else c.insert(i, v); } @@ -669,21 +677,24 @@ namespace libtorrent { std::pair v(name, std::string()); std::vector >::const_iterator i = - std::lower_bound(m_strings.begin(), m_strings.end(), v); + std::lower_bound(m_strings.begin(), m_strings.end(), v + , &compare_first); return i != m_strings.end() && i->first == name; } case int_type_base: { std::pair v(name, 0); std::vector >::const_iterator i = - std::lower_bound(m_ints.begin(), m_ints.end(), v); + std::lower_bound(m_ints.begin(), m_ints.end(), v + , &compare_first); return i != m_ints.end() && i->first == name; } case bool_type_base: { std::pair v(name, false); std::vector >::const_iterator i = - std::lower_bound(m_bools.begin(), m_bools.end(), v); + std::lower_bound(m_bools.begin(), m_bools.end(), v + , &compare_first); return i != m_bools.end() && i->first == name; } } @@ -698,7 +709,8 @@ namespace libtorrent std::pair v(name, std::string()); std::vector >::const_iterator i - = std::lower_bound(m_strings.begin(), m_strings.end(), v); + = std::lower_bound(m_strings.begin(), m_strings.end(), v + , &compare_first); if (i != m_strings.end() && i->first == name) return i->second; return std::string(); } @@ -710,7 +722,8 @@ namespace libtorrent std::pair v(name, 0); std::vector >::const_iterator i - = std::lower_bound(m_ints.begin(), m_ints.end(), v); + = std::lower_bound(m_ints.begin(), m_ints.end(), v + , &compare_first); if (i != m_ints.end() && i->first == name) return i->second; return 0; } @@ -722,7 +735,8 @@ namespace libtorrent std::pair v(name, false); std::vector >::const_iterator i - = std::lower_bound(m_bools.begin(), m_bools.end(), v); + = std::lower_bound(m_bools.begin(), m_bools.end(), v + , &compare_first); if (i != m_bools.end() && i->first == name) return i->second; return false; } diff --git a/test/setup_transfer.cpp b/test/setup_transfer.cpp index 6f3c37b20..21dba8c67 100644 --- a/test/setup_transfer.cpp +++ b/test/setup_transfer.cpp @@ -704,15 +704,21 @@ setup_transfer(lt::session* ses1, lt::session* ses2, lt::session* ses3 std::generate(&pid[0], &pid[0] + 20, random_byte); pack.set_str(settings_pack::peer_fingerprint, pid.to_string()); ses1->apply_settings(pack); + TORRENT_ASSERT(ses1->id() == pid); std::generate(&pid[0], &pid[0] + 20, random_byte); + TORRENT_ASSERT(ses1->id() != pid); pack.set_str(settings_pack::peer_fingerprint, pid.to_string()); ses2->apply_settings(pack); + TORRENT_ASSERT(ses2->id() == pid); if (ses3) { std::generate(&pid[0], &pid[0] + 20, random_byte); + TORRENT_ASSERT(ses1->id() != pid); + TORRENT_ASSERT(ses2->id() != pid); pack.set_str(settings_pack::peer_fingerprint, pid.to_string()); ses3->apply_settings(pack); + TORRENT_ASSERT(ses3->id() == pid); } TORRENT_ASSERT(ses1->id() != ses2->id()); diff --git a/test/test_settings_pack.cpp b/test/test_settings_pack.cpp index 5132e5bbb..0e91e57b2 100644 --- a/test/test_settings_pack.cpp +++ b/test/test_settings_pack.cpp @@ -79,6 +79,14 @@ int test_main() TEST_NAME(peer_turnover_interval); TEST_NAME(mmap_cache); + settings_pack p; + p.set_str(settings_pack::peer_fingerprint, "abc"); + p.set_str(settings_pack::peer_fingerprint, "cde"); + p.set_str(settings_pack::peer_fingerprint, "efg"); + p.set_str(settings_pack::peer_fingerprint, "hij"); + + TEST_EQUAL(p.get_str(settings_pack::peer_fingerprint), "hij"); + return 0; } diff --git a/test/web_seed_suite.cpp b/test/web_seed_suite.cpp index 235acf962..62cd31fe7 100644 --- a/test/web_seed_suite.cpp +++ b/test/web_seed_suite.cpp @@ -395,6 +395,10 @@ int EXPORT run_http_suite(int proxy, char const* protocol, bool test_url_seed pack.set_str(settings_pack::listen_interfaces, "0.0.0.0:51000"); pack.set_int(settings_pack::max_retry_port_bind, 1000); pack.set_int(settings_pack::alert_mask, ~(alert::progress_notification | alert::stats_notification)); + pack.set_bool(settings_pack::enable_lsd, false); + pack.set_bool(settings_pack::enable_natpmp, false); + pack.set_bool(settings_pack::enable_upnp, false); + pack.set_bool(settings_pack::enable_dht, false); libtorrent::session ses(pack, 0); test_transfer(ses, torrent_file, proxy, port, protocol, test_url_seed