fix ipv6-off build

This commit is contained in:
Arvid Norberg 2013-06-16 00:59:29 +00:00
parent a1c4a9a146
commit 98b47c55c6
2 changed files with 10 additions and 0 deletions

View File

@ -119,7 +119,9 @@ namespace libtorrent
address external_ip::external_address(address const& ip) const address external_ip::external_address(address const& ip) const
{ {
address ext = m_vote_group[ip.is_v6()].external_address(); address ext = m_vote_group[ip.is_v6()].external_address();
#if TORRENT_USE_IPV6
if (ip.is_v6() && ext == address_v4()) return address_v6(); if (ip.is_v6() && ext == address_v4()) return address_v6();
#endif
return ext; return ext;
} }
} }

View File

@ -398,12 +398,14 @@ address rand_v4()
return address_v4((rand() << 16 | rand()) & 0xffffffff); return address_v4((rand() << 16 | rand()) & 0xffffffff);
} }
#if TORRENT_USE_IPV6
address rand_v6() address rand_v6()
{ {
address_v6::bytes_type bytes; address_v6::bytes_type bytes;
for (int i = 0; i < bytes.size(); ++i) bytes[i] = rand(); for (int i = 0; i < bytes.size(); ++i) bytes[i] = rand();
return address_v6(bytes); return address_v6(bytes);
} }
#endif
int test_main() int test_main()
{ {
@ -574,11 +576,13 @@ int test_main()
address real_external1 = address_v4::from_string("5.5.5.5", ec); address real_external1 = address_v4::from_string("5.5.5.5", ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
address real_external2; address real_external2;
#if TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
{ {
real_external2 = address_v6::from_string("2f80::", ec); real_external2 = address_v6::from_string("2f80::", ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
} }
#endif
malicious = address_v4::from_string("4.4.4.4", ec); malicious = address_v4::from_string("4.4.4.4", ec);
TEST_CHECK(!ec); TEST_CHECK(!ec);
address malicious_external = address_v4::from_string("3.3.3.3", ec); address malicious_external = address_v4::from_string("3.3.3.3", ec);
@ -586,13 +590,17 @@ int test_main()
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 TORRENT_USE_IPV6
if (supports_ipv6()) 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());
#endif
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 TORRENT_USE_IPV6
if (supports_ipv6()) if (supports_ipv6())
TEST_CHECK(ipv2.external_address(rand_v6()) == real_external2); TEST_CHECK(ipv2.external_address(rand_v6()) == real_external2);
#endif
// test bloom_filter // test bloom_filter
bloom_filter<32> filter; bloom_filter<32> filter;