diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index 05db4ecf2..32301ddc1 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -937,6 +937,10 @@ namespace libtorrent time_point m_last_receive; time_point m_last_sent; + // the last time we filled our send buffer with payload + // this is used for timeouts + time_point m_last_sent_payload; + // the time when the first entry in the request queue was requested. Used // for request timeout. it doesn't necessarily represent the time when a // specific request was made. Since requests can be handled out-of-order, diff --git a/simulation/test_swarm.cpp b/simulation/test_swarm.cpp index e8d2d9bab..8cc3e3be5 100644 --- a/simulation/test_swarm.cpp +++ b/simulation/test_swarm.cpp @@ -68,7 +68,7 @@ TORRENT_TEST(plain) // terminate , [](int ticks, lt::session& ses) -> bool { - if (ticks > 75) + if (ticks > 80) { TEST_ERROR("timeout"); return true; @@ -109,7 +109,7 @@ TORRENT_TEST(session_stats) , [](int ticks, lt::session& ses) -> bool { ses.post_session_stats(); - if (ticks > 75) + if (ticks > 80) { TEST_ERROR("timeout"); return true; @@ -135,7 +135,7 @@ TORRENT_TEST(suggest) // terminate , [](int ticks, lt::session& ses) -> bool { - if (ticks > 75) + if (ticks > 80) { TEST_ERROR("timeout"); return true; @@ -163,7 +163,7 @@ TORRENT_TEST(utp_only) // terminate , [](int ticks, lt::session& ses) -> bool { - if (ticks > 75) + if (ticks > 80) { TEST_ERROR("timeout"); return true; @@ -322,7 +322,7 @@ TORRENT_TEST(explicit_cache) // terminate , [](int ticks, lt::session& ses) -> bool { - if (ticks > 75) + if (ticks > 80) { TEST_ERROR("timeout"); return true; diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 53251dcf7..088c191f5 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -137,6 +137,7 @@ namespace libtorrent , m_last_choke(min_time()) , m_last_receive(aux::time_now()) , m_last_sent(aux::time_now()) + , m_last_sent_payload(aux::time_now()) , m_requested(min_time()) , m_remote_dl_update(aux::time_now()) , m_connect(aux::time_now()) @@ -4824,10 +4825,13 @@ namespace libtorrent return; } - // disconnect peers that we unchoked, but - // they didn't send a request within 60 seconds. + // disconnect peers that we unchoked, but they didn't send a request in + // the last 60 seconds, and we haven't been working on servicing a request + // for more than 60 seconds. // but only if we're a seed - d = now - (std::max)(m_last_unchoke, m_last_incoming_request); + d = now - (std::max)((std::max)(m_last_unchoke, m_last_incoming_request) + , m_last_sent_payload); + if (may_timeout && !m_connecting && m_requests.empty() @@ -5220,6 +5224,7 @@ namespace libtorrent , boost::bind(&peer_connection::on_disk_read_complete , self(), _1, r, clock_type::now()), this); } + m_last_sent_payload = clock_type::now(); m_requests.erase(m_requests.begin() + i); if (m_requests.empty()) diff --git a/src/utp_stream.cpp b/src/utp_stream.cpp index aa0a16b52..24532b2a3 100644 --- a/src/utp_stream.cpp +++ b/src/utp_stream.cpp @@ -65,7 +65,9 @@ static struct utp_logger FILE* utp_log_file; mutex utp_log_mutex; - utp_logger() : utp_log_file(NULL) {} + utp_logger() : utp_log_file(NULL) { + utp_log_file = fopen("utp.log", "w+"); + } ~utp_logger() { if (utp_log_file) fclose(utp_log_file);