From 5b638c3c9e6f27250548bbbf5ab8b87d5a480480 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 6 Jan 2013 19:53:17 +0000 Subject: [PATCH] windows fix for ip-voter test --- include/libtorrent/ip_voter.hpp | 2 +- src/policy.cpp | 2 +- test/test_primitives.cpp | 28 ++++++++++++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/libtorrent/ip_voter.hpp b/include/libtorrent/ip_voter.hpp index 261d05ac8..99cb73818 100644 --- a/include/libtorrent/ip_voter.hpp +++ b/include/libtorrent/ip_voter.hpp @@ -41,7 +41,7 @@ namespace libtorrent { // this is an object that keeps the state for a single external IP // based on peoples votes - struct ip_voter + struct TORRENT_EXTRA_EXPORT ip_voter { // returns true if a different IP is the top vote now // i.e. we changed our idea of what our external IP is diff --git a/src/policy.cpp b/src/policy.cpp index 0f6f53b9b..14407e875 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -832,7 +832,7 @@ namespace libtorrent (*m_torrent->session().m_logger) << time_now_string() << " *** FOUND CONNECTION CANDIDATE [" " ip: " << m_peers[candidate]->ip() << - " d: " << cidr_distance(external.address(m_peers[candidate]->address()), m_peers[candidate]->address()) << + " d: " << cidr_distance(external.external_address(m_peers[candidate]->address()), m_peers[candidate]->address()) << " rank: " << m_peers[candidate]->rank(external, external_port) << " external: " << external.external_address(m_peers[candidate]->address()) << " t: " << (session_time - m_peers[candidate]->last_connected) << diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp index b647dc9bd..2466f8293 100644 --- a/test/test_primitives.cpp +++ b/test/test_primitives.cpp @@ -550,8 +550,10 @@ int test_main() // test a single malicious node // adds 50 legitimate responses from different peers // and 50 malicious responses from the same peer - address real_external = address_v4::from_string("5.5.5.5"); - address malicious = address_v4::from_string("4.4.4.4"); + address real_external = address_v4::from_string("5.5.5.5", ec); + TEST_CHECK(!ec); + address malicious = address_v4::from_string("4.4.4.4", ec); + TEST_CHECK(!ec); for (int i = 0; i < 50; ++i) { ipv1.cast_vote(real_external, aux::session_impl::source_dht, rand_v4()); @@ -564,18 +566,28 @@ int test_main() // test a single malicious node // adds 50 legitimate responses from different peers // and 50 consistent malicious responses from the same peer - address real_external1 = address_v4::from_string("5.5.5.5"); - address real_external2 = address_v6::from_string("2f80::1"); - malicious = address_v4::from_string("4.4.4.4"); - address malicious_external = address_v4::from_string("3.3.3.3"); + address real_external1 = address_v4::from_string("5.5.5.5", ec); + TEST_CHECK(!ec); + address real_external2; + if (supports_ipv6()) + { + real_external2 = address_v6::from_string("2f80::", ec); + TEST_CHECK(!ec); + } + malicious = address_v4::from_string("4.4.4.4", ec); + TEST_CHECK(!ec); + address malicious_external = address_v4::from_string("3.3.3.3", ec); + TEST_CHECK(!ec); for (int i = 0; i < 50; ++i) { ipv2.cast_vote(real_external1, aux::session_impl::source_dht, rand_v4()); - ipv2.cast_vote(real_external2, aux::session_impl::source_dht, rand_v6()); + if (supports_ipv6()) + ipv2.cast_vote(real_external2, aux::session_impl::source_dht, rand_v6()); ipv2.cast_vote(malicious_external, aux::session_impl::source_dht, malicious); } TEST_CHECK(ipv2.external_address(rand_v4()) == real_external1); - TEST_CHECK(ipv2.external_address(rand_v6()) == real_external2); + if (supports_ipv6()) + TEST_CHECK(ipv2.external_address(rand_v6()) == real_external2); // test bloom_filter bloom_filter<32> filter;