make test_privacy more reliable
This commit is contained in:
parent
223154b1f1
commit
2943bd4d7d
|
@ -1672,6 +1672,7 @@ namespace aux {
|
||||||
session_log("failed to get peer name \"%s\": %s"
|
session_log("failed to get peer name \"%s\": %s"
|
||||||
, device.c_str(), ec.message().c_str());
|
, device.c_str(), ec.message().c_str());
|
||||||
#endif
|
#endif
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1963,7 +1964,8 @@ retry:
|
||||||
m_alerts.post_alert(listen_succeeded_alert(m_listen_interface, listen_succeeded_alert::udp));
|
m_alerts.post_alert(listen_succeeded_alert(m_listen_interface, listen_succeeded_alert::udp));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_settings.get_int(settings_pack::peer_tos) != 0) {
|
if (m_settings.get_int(settings_pack::peer_tos) != 0)
|
||||||
|
{
|
||||||
update_peer_tos();
|
update_peer_tos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ void udp_socket::send_hostname(char const* hostname, int port
|
||||||
{
|
{
|
||||||
// send udp packets through SOCKS5 server
|
// send udp packets through SOCKS5 server
|
||||||
wrap(hostname, port, p, len, ec);
|
wrap(hostname, port, p, len, ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function is only supported when we're using a proxy
|
// this function is only supported when we're using a proxy
|
||||||
|
|
|
@ -481,14 +481,15 @@ namespace libtorrent
|
||||||
{
|
{
|
||||||
#if defined TORRENT_LOGGING
|
#if defined TORRENT_LOGGING
|
||||||
boost::shared_ptr<request_callback> cb = requester();
|
boost::shared_ptr<request_callback> cb = requester();
|
||||||
if (cb)
|
|
||||||
{
|
|
||||||
char hex_ih[41];
|
|
||||||
to_hex((char const*)&tracker_req().info_hash[0], 20, hex_ih);
|
|
||||||
cb->debug_log("==> UDP_TRACKER_CONNECT [%s]", hex_ih);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (m_abort) return;
|
|
||||||
|
if (m_abort)
|
||||||
|
{
|
||||||
|
#if defined TORRENT_LOGGING
|
||||||
|
if (cb) cb->debug_log("==> UDP_TRACKER_CONNECT [ skipped, m_abort ]");
|
||||||
|
#endif
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
char buf[16];
|
char buf[16];
|
||||||
char* ptr = buf;
|
char* ptr = buf;
|
||||||
|
@ -504,20 +505,41 @@ namespace libtorrent
|
||||||
error_code ec;
|
error_code ec;
|
||||||
if (!m_hostname.empty())
|
if (!m_hostname.empty())
|
||||||
{
|
{
|
||||||
m_man.udp_socket().send_hostname(m_hostname.c_str(), m_target.port(), buf, 16, ec);
|
m_man.udp_socket().send_hostname(m_hostname.c_str()
|
||||||
|
, m_target.port(), buf, 16, ec);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_man.udp_socket().send(m_target, buf, 16, ec);
|
m_man.udp_socket().send(m_target, buf, 16, ec);
|
||||||
|
|
||||||
}
|
}
|
||||||
m_state = action_connect;
|
|
||||||
sent_bytes(16 + 28); // assuming UDP/IP header
|
|
||||||
++m_attempts;
|
++m_attempts;
|
||||||
if (ec)
|
if (ec)
|
||||||
{
|
{
|
||||||
|
#if defined TORRENT_LOGGING
|
||||||
|
if (cb) cb->debug_log("==> UDP_TRACKER_CONNECT [ failed: %s ]"
|
||||||
|
, ec.message().c_str());
|
||||||
|
#endif
|
||||||
fail(ec);
|
fail(ec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined TORRENT_LOGGING
|
||||||
|
if (cb)
|
||||||
|
{
|
||||||
|
char hex_ih[41];
|
||||||
|
to_hex((char const*)&tracker_req().info_hash[0], 20, hex_ih);
|
||||||
|
cb->debug_log("==> UDP_TRACKER_CONNECT [ to: %s ih: %s]"
|
||||||
|
, m_hostname.empty()
|
||||||
|
? print_endpoint(m_target).c_str()
|
||||||
|
: (m_hostname + ":" + to_string(m_target.port()).elems).c_str()
|
||||||
|
, hex_ih);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_state = action_connect;
|
||||||
|
sent_bytes(16 + 28); // assuming UDP/IP header
|
||||||
}
|
}
|
||||||
|
|
||||||
void udp_tracker_connection::send_udp_scrape()
|
void udp_tracker_connection::send_udp_scrape()
|
||||||
|
@ -743,7 +765,8 @@ namespace libtorrent
|
||||||
|
|
||||||
if (!m_hostname.empty())
|
if (!m_hostname.empty())
|
||||||
{
|
{
|
||||||
m_man.udp_socket().send_hostname(m_hostname.c_str(), m_target.port(), buf, out - buf, ec);
|
m_man.udp_socket().send_hostname(m_hostname.c_str()
|
||||||
|
, m_target.port(), buf, out - buf, ec);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,6 +75,7 @@ enum flags_t
|
||||||
expect_udp_reject = 16,
|
expect_udp_reject = 16,
|
||||||
expect_dht_msg = 32,
|
expect_dht_msg = 32,
|
||||||
expect_peer_connection = 64,
|
expect_peer_connection = 64,
|
||||||
|
expect_possible_udp_connection = 128,
|
||||||
};
|
};
|
||||||
|
|
||||||
session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
||||||
|
@ -111,9 +112,10 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
||||||
|
|
||||||
// since multiple sessions may exist simultaneously (because of the
|
// since multiple sessions may exist simultaneously (because of the
|
||||||
// pipelining of the tests) they actually need to use different ports
|
// pipelining of the tests) they actually need to use different ports
|
||||||
static int listen_port = 48875;
|
static int listen_port = 10000 + random() % 50000;
|
||||||
char iface[200];
|
char iface[200];
|
||||||
snprintf(iface, sizeof(iface), "127.0.0.1:%d", listen_port++);
|
snprintf(iface, sizeof(iface), "127.0.0.1:%d", listen_port);
|
||||||
|
listen_port += (random() % 10) + 1;
|
||||||
sett.set_str(settings_pack::listen_interfaces, iface);
|
sett.set_str(settings_pack::listen_interfaces, iface);
|
||||||
sett.set_bool(settings_pack::enable_dht, true);
|
sett.set_bool(settings_pack::enable_dht, true);
|
||||||
|
|
||||||
|
@ -180,7 +182,17 @@ session_proxy test_proxy(settings_pack::proxy_type_t proxy_type, int flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// we should have announced to the tracker by now
|
// we should have announced to the tracker by now
|
||||||
TEST_EQUAL(num_udp_announces(), prev_udp_announces + bool(flags & expect_udp_connection));
|
if (flags & expect_possible_udp_connection)
|
||||||
|
{
|
||||||
|
// this flag is true if we may fail open, but also might not have had
|
||||||
|
// enough time to fail yet
|
||||||
|
TEST_CHECK(num_udp_announces() == prev_udp_announces
|
||||||
|
|| num_udp_announces() == prev_udp_announces + 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TEST_EQUAL(num_udp_announces(), prev_udp_announces + bool(flags & expect_udp_connection));
|
||||||
|
}
|
||||||
if (flags & expect_dht_msg)
|
if (flags & expect_dht_msg)
|
||||||
{
|
{
|
||||||
TEST_CHECK(num_dht_hits() > 0);
|
TEST_CHECK(num_dht_hits() > 0);
|
||||||
|
@ -224,8 +236,8 @@ int test_main()
|
||||||
// or if the proxy doesn't support UDP
|
// or if the proxy doesn't support UDP
|
||||||
pr[0] = test_proxy(settings_pack::none, expect_udp_connection | expect_http_connection | expect_dht_msg | expect_peer_connection);
|
pr[0] = test_proxy(settings_pack::none, expect_udp_connection | expect_http_connection | expect_dht_msg | expect_peer_connection);
|
||||||
pr[1] = test_proxy(settings_pack::socks4, expect_udp_connection | expect_dht_msg);
|
pr[1] = test_proxy(settings_pack::socks4, expect_udp_connection | expect_dht_msg);
|
||||||
pr[2] = test_proxy(settings_pack::socks5, expect_udp_connection | expect_dht_msg);
|
pr[2] = test_proxy(settings_pack::socks5, expect_possible_udp_connection | expect_dht_msg);
|
||||||
pr[3] = test_proxy(settings_pack::socks5_pw, expect_udp_connection | expect_dht_msg);
|
pr[3] = test_proxy(settings_pack::socks5_pw,expect_possible_udp_connection | expect_dht_msg);
|
||||||
pr[4] = test_proxy(settings_pack::http, expect_udp_connection | expect_dht_msg);
|
pr[4] = test_proxy(settings_pack::http, expect_udp_connection | expect_dht_msg);
|
||||||
pr[5] = test_proxy(settings_pack::http_pw, expect_udp_connection | expect_dht_msg);
|
pr[5] = test_proxy(settings_pack::http_pw, expect_udp_connection | expect_dht_msg);
|
||||||
pr[6] = test_proxy(settings_pack::i2p_proxy, expect_udp_connection | expect_dht_msg);
|
pr[6] = test_proxy(settings_pack::i2p_proxy, expect_udp_connection | expect_dht_msg);
|
||||||
|
|
|
@ -198,7 +198,7 @@ int test_main()
|
||||||
// TODO: test parse peers6
|
// TODO: test parse peers6
|
||||||
// TODO: test parse tracker-id
|
// TODO: test parse tracker-id
|
||||||
// TODO: test parse failure-reason
|
// TODO: test parse failure-reason
|
||||||
// TODO: test all failure paths
|
// TODO: test all failure paths, including
|
||||||
// invalid bencoding
|
// invalid bencoding
|
||||||
// not a dictionary
|
// not a dictionary
|
||||||
// no files entry in scrape response
|
// no files entry in scrape response
|
||||||
|
|
Loading…
Reference in New Issue