From c7464576299791ed94fe5acc87fb4a2b3eac12a8 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Tue, 4 Sep 2007 18:42:53 +0000 Subject: [PATCH] fix lt bugs 145 and 122 --- libtorrent/src/peer_connection.cpp | 2 +- libtorrent/src/policy.cpp | 5 +++-- libtorrent/src/session_impl.cpp | 23 ++++++++++++++++++++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libtorrent/src/peer_connection.cpp b/libtorrent/src/peer_connection.cpp index c6be880ad..2ae8893e5 100755 --- a/libtorrent/src/peer_connection.cpp +++ b/libtorrent/src/peer_connection.cpp @@ -948,7 +948,7 @@ namespace libtorrent // if this is a web seed. we don't have a peer_info struct if (m_peer_info) m_peer_info->seed = true; // if we're a seed too, disconnect - if (t->is_seed()) + if (t->is_finished()) { throw protocol_error("seed to seed connection redundant, disconnecting"); } diff --git a/libtorrent/src/policy.cpp b/libtorrent/src/policy.cpp index 5683b74e5..b1bcc6403 100755 --- a/libtorrent/src/policy.cpp +++ b/libtorrent/src/policy.cpp @@ -516,6 +516,7 @@ namespace libtorrent int max_failcount = m_torrent->settings().max_failcount; int min_reconnect_time = m_torrent->settings().min_reconnect_time; + bool finished = m_torrent->is_finished(); aux::session_impl& ses = m_torrent->session(); @@ -524,7 +525,7 @@ namespace libtorrent if (i->connection) continue; if (i->banned) continue; if (i->type == peer::not_connectable) continue; - if (i->seed && m_torrent->is_seed()) continue; + if (i->seed && finished) continue; if (i->failcount >= max_failcount) continue; if (now - i->connected < seconds(i->failcount * min_reconnect_time)) continue; @@ -1179,7 +1180,7 @@ namespace libtorrent && m_torrent->session().num_uploads() < m_torrent->session().max_uploads() && (m_torrent->ratio() == 0 || c.share_diff() >= -free_upload_amount - || m_torrent->is_seed())) + || m_torrent->is_finished())) { m_torrent->session().unchoke_peer(c); } diff --git a/libtorrent/src/session_impl.cpp b/libtorrent/src/session_impl.cpp index 125664302..596ffc4b2 100755 --- a/libtorrent/src/session_impl.cpp +++ b/libtorrent/src/session_impl.cpp @@ -785,9 +785,30 @@ namespace detail } return; } + // check if we have any active torrents + // if we don't reject the connection + if (m_torrents.empty()) + { + return; + } + else + { + bool has_active_torrent = false; + for (torrent_map::iterator i = m_torrents.begin() + , end(m_torrents.end()); i != end; ++i) + { + if (!i->second->is_paused()) + { + has_active_torrent = true; + break; + } + } + if (!has_active_torrent) + return; + } boost::intrusive_ptr c( - new bt_peer_connection(*this, s, 0)); + new bt_peer_connection(*this, s, 0)); #ifndef NDEBUG c->m_in_constructor = false; #endif