diff --git a/ChangeLog b/ChangeLog index 0b62524d9..12eb30428 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,7 @@ * fix uTP edge case where udp socket buffer fills up * fix nagle implementation in uTP + * make 'close_redudnant_connections' cover more cases * set_piece_deadline() also unfilters the piece (if its priority is 0) * add work-around for bug in windows vista and earlier in GetOverlappedResult * fix traversal algorithm leak in DHT diff --git a/src/bt_peer_connection.cpp b/src/bt_peer_connection.cpp index 73527aa7d..e9c6daa64 100644 --- a/src/bt_peer_connection.cpp +++ b/src/bt_peer_connection.cpp @@ -1853,6 +1853,11 @@ namespace libtorrent if (m_upload_only_id == 0) return; if (t->share_mode()) return; + // if we send upload-only, the other end is very likely to disconnect + // us, at least if it's a seed. If we don't want to close redundant + // connections, don't sent upload-only + if (!m_ses.settings().close_redundant_connections) return; + char msg[7] = {0, 0, 0, 3, msg_extended}; char* ptr = msg + 5; detail::write_uint8(m_upload_only_id, ptr); diff --git a/src/torrent.cpp b/src/torrent.cpp index 3c373a66b..dc417e790 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -6183,25 +6183,29 @@ namespace libtorrent m_completed_time = time(0); // disconnect all seeds - // TODO: 1 should disconnect all peers that have the pieces we have - // not just seeds. It would be pretty expensive to check all pieces - // for all peers though - std::vector seeds; - for (peer_iterator i = m_connections.begin(); - i != m_connections.end(); ++i) + if (settings().close_redundant_connections) { - peer_connection* p = *i; - TORRENT_ASSERT(p->associated_torrent().lock().get() == this); - if (p->upload_only()) + // TODO: 1 should disconnect all peers that have the pieces we have + // not just seeds + // not just seeds. It would be pretty expensive to check all pieces + // for all peers though + std::vector seeds; + for (peer_iterator i = m_connections.begin(); + i != m_connections.end(); ++i) { + peer_connection* p = *i; + TORRENT_ASSERT(p->associated_torrent().lock().get() == this); + if (p->upload_only()) + { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_ERROR_LOGGING - p->peer_log("*** SEED, CLOSING CONNECTION"); + p->peer_log("*** SEED, CLOSING CONNECTION"); #endif - seeds.push_back(p); + seeds.push_back(p); + } } + std::for_each(seeds.begin(), seeds.end() + , boost::bind(&peer_connection::disconnect, _1, errors::torrent_finished, 0)); } - std::for_each(seeds.begin(), seeds.end() - , boost::bind(&peer_connection::disconnect, _1, errors::torrent_finished, 0)); if (m_abort) return;