diff --git a/Jamfile b/Jamfile index 97da5e5fd..b9189e4ef 100755 --- a/Jamfile +++ b/Jamfile @@ -22,7 +22,7 @@ SOURCES = lib torrent : src/$(SOURCES) # zlib/zlib - zlib//zlib +# zlib//zlib # boost_filesystem.lib # boost_date_time.lib # boost_thread.dll diff --git a/examples/client_test.cpp b/examples/client_test.cpp index 2b93d3988..365377358 100755 --- a/examples/client_test.cpp +++ b/examples/client_test.cpp @@ -320,7 +320,9 @@ int main(int argc, char* argv[]) torrent_finished_alert* p = dynamic_cast(a.get()); if (p) { - ses.set_upload_rate_limit(30 * 1024); + ses.set_upload_rate_limit(30000); + p->handle.set_max_connections(10); + p->handle.set_max_uploads(5); } if (events.size() >= 10) events.pop_front(); events.push_back(a->msg()); diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index dfdd0740e..17cf4a093 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -146,12 +146,7 @@ namespace libtorrent bool is_seed() const; - bool has_timed_out() const - { - boost::posix_time::time_duration d; - d = boost::posix_time::second_clock::local_time() - m_last_receive; - return d > boost::posix_time::seconds(m_timeout); - } + bool has_timed_out() const; // will send a keep-alive message to the peer void keep_alive(); @@ -532,7 +527,17 @@ namespace libtorrent // message boost::posix_time::time_duration m_last_piece_time; + // this is true if this connection has been added + // to the list of connections that will be closed. bool m_disconnecting; + + // the time when this peer sent us a not_interested message + // the last time. + boost::posix_time::ptime m_became_uninterested; + + // the time when we sent a not_interested message to + // this peer the last time. + boost::posix_time::ptime m_became_uninteresting; }; // this is called each time this peer generates some diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 580af3b83..da3fcc003 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -108,6 +108,8 @@ namespace libtorrent , m_last_piece(boost::posix_time::second_clock::local_time()) , m_last_piece_time(boost::posix_time::seconds(0)) , m_disconnecting(false) + , m_became_uninterested(boost::posix_time::second_clock::local_time()) + , m_became_uninteresting(boost::posix_time::second_clock::local_time()) { INVARIANT_CHECK; @@ -171,6 +173,8 @@ namespace libtorrent , m_last_piece(boost::posix_time::second_clock::local_time()) , m_last_piece_time(boost::posix_time::seconds(0)) , m_disconnecting(false) + , m_became_uninterested(boost::posix_time::second_clock::local_time()) + , m_became_uninteresting(boost::posix_time::second_clock::local_time()) { INVARIANT_CHECK; @@ -413,6 +417,8 @@ namespace libtorrent m_statistics.received_bytes(0, received); if (m_recv_pos < m_packet_size) return; + m_became_uninterested = boost::posix_time::second_clock::local_time(); + // clear the request queue if the client isn't interested m_requests.clear(); @@ -1187,6 +1193,9 @@ namespace libtorrent char msg[] = {0,0,0,1,msg_not_interested}; m_send_buffer.insert(m_send_buffer.end(), msg, msg+sizeof(msg)); m_interesting = false; + + m_became_uninteresting = boost::posix_time::second_clock::local_time(); + #ifndef NDEBUG (*m_logger) << " ==> NOT_INTERESTED\n"; #endif @@ -1720,6 +1729,34 @@ namespace libtorrent } #endif + bool peer_connection::has_timed_out() const + { + using namespace boost::posix_time; + + // if the peer hasn't said a thing for a certain + // time, it is considered to have timed out + time_duration d; + d = second_clock::local_time() - m_last_receive; + if (d > seconds(m_timeout)) return true; + + // if the peer hasn't become interested and we haven't + // become interested in the peer for 60 seconds, it + // has also timed out. + time_duration d1; + time_duration d2; + d1 = second_clock::local_time() - m_became_uninterested; + d2 = second_clock::local_time() - m_became_uninteresting; + if (!m_interesting + && !m_peer_interested + && d1 > seconds(60) + && d2 > seconds(60)) + { + return true; + } + return false; + } + + void peer_connection::keep_alive() { INVARIANT_CHECK;