fix unit test web server for tracker announces

This commit is contained in:
Arvid Norberg 2013-10-07 00:33:55 +00:00
parent c99f0c120a
commit d90f7336b1
3 changed files with 14 additions and 10 deletions

View File

@ -832,14 +832,14 @@ void on_udp_receive(error_code const& ec, size_t bytes_transferred, udp::endpoin
case 1: // announce
fprintf(stderr, "%s: UDP announce\n", time_now_string());
++g_udp_tracker_requests;
fprintf(stderr, "%s: UDP announce [%d]\n", time_now_string(), int(g_udp_tracker_requests));
ptr = buffer;
detail::write_uint32(1, ptr); // action = announce
detail::write_uint32(transaction_id, ptr); // transaction_id
detail::write_uint32(1800, ptr); // interval
detail::write_uint32(1, ptr); // incomplete
detail::write_uint32(1, ptr); // complete
++g_udp_tracker_requests;
// 0 peers
sock->send_to(asio::buffer(buffer, 20), *from, 0, e);
if (e) fprintf(stderr, "%s: send_to failed. ERROR: %s\n", time_now_string(), e.message().c_str());
@ -1299,7 +1299,6 @@ void web_server_thread(int* port, bool ssl, bool chunked)
}
std::string path = p.path();
fprintf(stderr, "%s: %s\n", time_now_string(), path.c_str());
std::vector<char> file_buf;
if (path.substr(0, 4) == "http")
@ -1314,6 +1313,8 @@ void web_server_thread(int* port, bool ssl, bool chunked)
path = path.substr(1);
}
fprintf(stderr, "%s: [HTTP] %s\n", time_now_string(), path.c_str());
if (path == "redirect")
{
extra_header[0] = "Location: /test_file\r\n";
@ -1335,7 +1336,7 @@ void web_server_thread(int* port, bool ssl, bool chunked)
break;
}
if (path.substr(0, 9) == "announce")
if (path.substr(0, 8) == "announce")
{
fprintf(stderr, "%s\n", path.c_str());
entry announce;
@ -1346,11 +1347,12 @@ void web_server_thread(int* port, bool ssl, bool chunked)
std::vector<char> buf;
bencode(std::back_inserter(buf), announce);
++g_http_tracker_requests;
fprintf(stderr, "[HTTP]: announce [%d]\n", int(g_http_tracker_requests));
send_response(s, ec, 200, "OK", extra_header, buf.size());
write(s, boost::asio::buffer(&buf[0], buf.size()), boost::asio::transfer_all(), ec);
if (ec)
fprintf(stderr, "*** send failed: %s\n", ec.message().c_str());
fprintf(stderr, "[HTTP] *** send response failed: %s\n", ec.message().c_str());
}
if (filename(path).substr(0, 5) == "seed?")

View File

@ -80,12 +80,14 @@ int test_main()
addp.save_path = "tmp1_tracker";
torrent_handle h = s->add_torrent(addp);
for (int i = 0; i < 100; ++i)
for (int i = 0; i < 50; ++i)
{
print_alerts(*s, "s");
test_sleep(100);
// fprintf(stderr, "udp_announces: %d http_announces: %d\n", int(g_udp_tracker_requests), int(g_http_tracker_requests));
if (g_udp_tracker_requests == prev_udp_announces + 1
&& g_http_tracker_requests == prev_http_announces + 1) break;
&& g_http_tracker_requests == prev_http_announces + 1)
break;
}
// we should have announced to the tracker by now
@ -145,10 +147,10 @@ int test_main()
addp.save_path = "tmp2_tracker";
h = s->add_torrent(addp);
for (int i = 0; i < 10; ++i)
for (int i = 0; i < 50; ++i)
{
print_alerts(*s, "s");
test_sleep(1000);
test_sleep(100);
if (g_udp_tracker_requests == prev_udp_announces + 1) break;
}

View File

@ -257,7 +257,7 @@ for branch_name in revs:
.passed { background-color: #6f8 }
.failed { background-color: #f68 }
table { border: 0; border-collapse: collapse; display: inline-block; }
th { font-size: 15pt; }
th { font-size: 15pt; width: 18em; }
td { border: 0; border-spacing: 0px; padding: 1px 0px 0px 1px; }
</style>
</head><body>''' % (p, toolset, branch_name)