From 323af56cc2ab500199784fb65c4c12d05683fab2 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 16 Jun 2015 01:24:35 -0400 Subject: [PATCH] update interest when changing upload-only mode --- include/libtorrent/peer_connection.hpp | 2 +- src/bt_peer_connection.cpp | 18 +++++++++--------- src/peer_connection.cpp | 2 +- src/torrent.cpp | 5 +++++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index b6d2f35a5..5bb80eac9 100644 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -389,7 +389,7 @@ namespace libtorrent // this adds an announcement in the announcement queue // it will let the peer know that we have the given piece void announce_piece(int index); - + // this will tell the peer to announce the given piece // and only allow it to request that piece void superseed_piece(int replace_piece, int new_piece); diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index b829239b8..69fe055bd 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -140,7 +140,7 @@ namespace libtorrent void bt_peer_connection::start() { peer_connection::start(); - + // start in the state where we are trying to read the // handshake from the other side m_recv_buffer.reset(20); @@ -185,7 +185,7 @@ namespace libtorrent cork c_(*this); #if !defined(TORRENT_DISABLE_ENCRYPTION) && !defined(TORRENT_DISABLE_EXTENSIONS) - + boost::uint8_t out_enc_policy = m_settings.get_int(settings_pack::out_enc_policy); #ifdef TORRENT_USE_OPENSSL @@ -245,14 +245,14 @@ namespace libtorrent #endif { write_handshake(); - + // start in the state where we are trying to read the // handshake from the other side m_recv_buffer.reset(20); setup_receive(); } } - + void bt_peer_connection::on_metadata() { #ifndef TORRENT_DISABLE_LOGGING @@ -489,10 +489,10 @@ namespace libtorrent TORRENT_ASSERT(!m_rc4_encrypted); TORRENT_ASSERT(is_outgoing()); TORRENT_ASSERT(!m_sent_handshake); - + boost::shared_ptr t = associated_torrent().lock(); TORRENT_ASSERT(t); - + hasher h; sha1_hash const& info_hash = t->torrent_file().info_hash(); char const* const secret = m_dh_key_exchange->get_secret(); @@ -1083,7 +1083,7 @@ namespace libtorrent bitfield bits; bits.assign((char*)recv_buffer.begin + 1 , t->valid_metadata()?get_bitfield().size():(m_recv_buffer.packet_size()-1)*8); - + incoming_bitfield(bits); } @@ -1124,7 +1124,7 @@ namespace libtorrent INVARIANT_CHECK; TORRENT_ASSERT(received >= 0); - + buffer::const_interval recv_buffer = m_recv_buffer.get(); int recv_pos = m_recv_buffer.pos(); // recv_buffer.end - recv_buffer.begin; @@ -1374,7 +1374,7 @@ namespace libtorrent const char* ptr = recv_buffer.begin + 1; int listen_port = detail::read_uint16(ptr); - + incoming_dht_port(listen_port); if (!m_supports_dht_port) diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index acfa6d021..4bfb1f2a2 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -2082,7 +2082,7 @@ namespace libtorrent if (t && t->has_picker()) t->picker().check_peer_invariant(m_have_piece, this); #endif - + // this will cause us to send the INTERESTED message if (!t->is_upload_only()) t->peer_is_interesting(*this); diff --git a/src/torrent.cpp b/src/torrent.cpp index 67e6eec61..891ac7151 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -1057,6 +1057,9 @@ namespace libtorrent , end(m_connections.end()); i != end; ++i) { peer_connection* p = (*i); + // we may want to disconnect other upload-only peers + if (p->upload_only()) + p->update_interest(); p->cancel_all_requests(); } // this is used to try leaving upload only mode periodically @@ -1076,6 +1079,8 @@ namespace libtorrent , end(m_connections.end()); i != end; ++i) { peer_connection* p = (*i); + // we may be interested now, or no longer interested + p->update_interest(); p->send_block_requests(); } }