windows fix for ip-voter test

This commit is contained in:
Arvid Norberg 2013-01-06 19:53:17 +00:00
parent d8c2228ff3
commit 5b638c3c9e
3 changed files with 22 additions and 10 deletions

View File

@ -41,7 +41,7 @@ namespace libtorrent
{ {
// this is an object that keeps the state for a single external IP // this is an object that keeps the state for a single external IP
// based on peoples votes // based on peoples votes
struct ip_voter struct TORRENT_EXTRA_EXPORT ip_voter
{ {
// returns true if a different IP is the top vote now // returns true if a different IP is the top vote now
// i.e. we changed our idea of what our external IP is // i.e. we changed our idea of what our external IP is

View File

@ -832,7 +832,7 @@ namespace libtorrent
(*m_torrent->session().m_logger) << time_now_string() (*m_torrent->session().m_logger) << time_now_string()
<< " *** FOUND CONNECTION CANDIDATE [" << " *** FOUND CONNECTION CANDIDATE ["
" ip: " << m_peers[candidate]->ip() << " 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) << " rank: " << m_peers[candidate]->rank(external, external_port) <<
" external: " << external.external_address(m_peers[candidate]->address()) << " external: " << external.external_address(m_peers[candidate]->address()) <<
" t: " << (session_time - m_peers[candidate]->last_connected) << " t: " << (session_time - m_peers[candidate]->last_connected) <<

View File

@ -550,8 +550,10 @@ int test_main()
// test a single malicious node // test a single malicious node
// adds 50 legitimate responses from different peers // adds 50 legitimate responses from different peers
// and 50 malicious responses from the same peer // and 50 malicious responses from the same peer
address real_external = address_v4::from_string("5.5.5.5"); address real_external = address_v4::from_string("5.5.5.5", ec);
address malicious = address_v4::from_string("4.4.4.4"); TEST_CHECK(!ec);
address malicious = address_v4::from_string("4.4.4.4", ec);
TEST_CHECK(!ec);
for (int i = 0; i < 50; ++i) for (int i = 0; i < 50; ++i)
{ {
ipv1.cast_vote(real_external, aux::session_impl::source_dht, rand_v4()); ipv1.cast_vote(real_external, aux::session_impl::source_dht, rand_v4());
@ -564,17 +566,27 @@ int test_main()
// test a single malicious node // test a single malicious node
// adds 50 legitimate responses from different peers // adds 50 legitimate responses from different peers
// and 50 consistent malicious responses from the same peer // and 50 consistent malicious responses from the same peer
address real_external1 = address_v4::from_string("5.5.5.5"); address real_external1 = address_v4::from_string("5.5.5.5", ec);
address real_external2 = address_v6::from_string("2f80::1"); TEST_CHECK(!ec);
malicious = address_v4::from_string("4.4.4.4"); address real_external2;
address malicious_external = address_v4::from_string("3.3.3.3"); 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) for (int i = 0; i < 50; ++i)
{ {
ipv2.cast_vote(real_external1, aux::session_impl::source_dht, rand_v4()); ipv2.cast_vote(real_external1, aux::session_impl::source_dht, rand_v4());
if (supports_ipv6())
ipv2.cast_vote(real_external2, aux::session_impl::source_dht, rand_v6()); ipv2.cast_vote(real_external2, aux::session_impl::source_dht, rand_v6());
ipv2.cast_vote(malicious_external, aux::session_impl::source_dht, malicious); 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_v4()) == real_external1);
if (supports_ipv6())
TEST_CHECK(ipv2.external_address(rand_v6()) == real_external2); TEST_CHECK(ipv2.external_address(rand_v6()) == real_external2);
// test bloom_filter // test bloom_filter