fix issue where event=stopped announces wouldn't be sent when closing session

This commit is contained in:
Arvid Norberg 2011-09-17 21:15:42 +00:00
parent 52a0760e5b
commit 4e1af65fe0
8 changed files with 91 additions and 4 deletions

View File

@ -92,6 +92,7 @@
incoming connection
* added more detailed instrumentation of the disk I/O thread
* fix issue where event=stopped announces wouldn't be sent when closing session
* fix possible hang in file::readv() on windows
* fix CPU busy loop issue in tracker announce logic
* honor IOV_MAX when using writev and readv

View File

@ -75,7 +75,7 @@ namespace libtorrent
INVARIANT_CHECK;
TORRENT_ASSERT(priority >= 0);
TORRENT_ASSERT(priority < 2);
TORRENT_ASSERT(priority < 3);
entry* e = 0;
@ -86,6 +86,7 @@ namespace libtorrent
e = &m_queue.back();
break;
case 1:
case 2:
m_queue.push_front(entry());
e = &m_queue.front();
break;
@ -133,12 +134,18 @@ namespace libtorrent
m_timer.cancel(ec);
m_abort = true;
std::list<entry> to_keep;
while (!m_queue.empty())
{
// we don't want to call the timeout callback while we're locked
// since that is a recipie for dead-locks
entry e = m_queue.front();
m_queue.pop_front();
if (e.priority > 1)
{
to_keep.push_back(e);
continue;
}
if (e.connecting) --m_num_connecting;
l.unlock();
TORRENT_TRY {
@ -146,6 +153,8 @@ namespace libtorrent
} TORRENT_CATCH(std::exception&) {}
l.lock();
}
m_queue.swap(to_keep);
}
void connection_queue::limit(int limit)

View File

@ -145,7 +145,7 @@ void http_connection::get(std::string const& url, time_duration timeout, int pri
return;
}
TORRENT_ASSERT(prio >= 0 && prio < 2);
TORRENT_ASSERT(prio >= 0 && prio < 3);
bool ssl = false;
if (protocol == "https") ssl = true;
@ -212,7 +212,7 @@ void http_connection::start(std::string const& hostname, std::string const& port
#endif
)
{
TORRENT_ASSERT(prio >= 0 && prio < 2);
TORRENT_ASSERT(prio >= 0 && prio < 3);
m_redirects = handle_redirects;
if (ps) m_proxy = *ps;

View File

@ -227,7 +227,8 @@ namespace libtorrent
:settings.tracker_completion_timeout;
m_tracker_connection->get(url, seconds(timeout)
, 1, &m_ps, 5, settings.anonymous_mode ? "" : settings.user_agent
, tracker_req().event == tracker_request::stopped ? 2 : 1
, &m_ps, 5, settings.anonymous_mode ? "" : settings.user_agent
, bind_interface()
#if TORRENT_USE_I2P
, m_i2p_conn

View File

@ -32,6 +32,7 @@ test-suite libtorrent :
[ run test_storage.cpp ]
[ run test_upnp.cpp ]
[ run test_tracker.cpp ]
[ run test_web_seed.cpp ]
[ run test_bdecode_performance.cpp ]
[ run test_pe_crypto.cpp ]

View File

@ -445,6 +445,9 @@ int start_tracker()
return port;
}
int g_udp_tracker_requests = 0;
int g_http_tracker_requests = 0;
void on_udp_receive(error_code const& ec, size_t bytes_transferred, udp::endpoint const* from, char* buffer, udp::socket* sock)
{
if (ec)
@ -486,6 +489,7 @@ void on_udp_receive(error_code const& ec, size_t bytes_transferred, udp::endpoin
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);
break;
@ -974,6 +978,7 @@ void web_server_thread(int* port, bool ssl, bool chunked)
if (path.substr(0, 9) == "/announce")
{
fprintf(stderr, "%s\n", path.c_str());
entry announce;
announce["interval"] = 1800;
announce["complete"] = 1;
@ -981,6 +986,7 @@ void web_server_thread(int* port, bool ssl, bool chunked)
announce["peers"].string();
std::vector<char> buf;
bencode(std::back_inserter(buf), announce);
++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);

View File

@ -52,6 +52,9 @@ bool print_alerts(libtorrent::session& ses, char const* name
void wait_for_listen(libtorrent::session& ses, char const* name);
void test_sleep(int millisec);
extern int g_udp_tracker_requests;
extern int g_http_tracker_requests;
boost::intrusive_ptr<libtorrent::torrent_info> create_torrent(std::ostream* file = 0
, int piece_size = 16 * 1024, int num_pieces = 13, bool add_tracker = true, bool encrypted = false);

66
test/test_tracker.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "test.hpp"
#include "setup_transfer.hpp"
#include "libtorrent/alert.hpp"
#include "libtorrent/session.hpp"
#include "libtorrent/error_code.hpp"
#include <fstream>
using namespace libtorrent;
int test_main()
{
int http_port = start_web_server();
int udp_port = start_tracker();
int prev_udp_announces = g_udp_tracker_requests;
int prev_http_announces = g_http_tracker_requests;
int const alert_mask = alert::all_categories
& ~alert::progress_notification
& ~alert::stats_notification;
session* s = new libtorrent::session(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48875, 49800), "0.0.0.0", 0, alert_mask);
session_settings sett;
sett.half_open_limit = 1;
sett.announce_to_all_trackers = true;
sett.announce_to_all_tiers = true;
s->set_settings(sett);
error_code ec;
create_directory("./tmp1_tracker", ec);
std::ofstream file("./tmp1_tracker/temporary");
boost::intrusive_ptr<torrent_info> t = ::create_torrent(&file, 16 * 1024, 13, false);
file.close();
char tracker_url[200];
snprintf(tracker_url, sizeof(tracker_url), "http://127.0.0.1:%d/announce", http_port);
t->add_tracker(tracker_url);
snprintf(tracker_url, sizeof(tracker_url), "udp://127.0.0.1:%d/announce", udp_port);
t->add_tracker(tracker_url);
add_torrent_params addp;
addp.paused = false;
addp.auto_managed = false;
addp.ti = t;
addp.save_path = "./tmp1_tracker";
torrent_handle h = s->add_torrent(addp);
test_sleep(2000);
// we should have announced to the tracker by now
TEST_EQUAL(g_udp_tracker_requests, prev_udp_announces + 1);
TEST_EQUAL(g_http_tracker_requests, prev_http_announces + 1);
delete s;
// we should have announced the stopped event now
TEST_EQUAL(g_udp_tracker_requests, prev_udp_announces + 2);
TEST_EQUAL(g_http_tracker_requests, prev_http_announces + 2);
stop_tracker();
stop_web_server();
}