diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index e94d24f67..2c83b2fed 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -252,6 +252,7 @@ namespace libtorrent void flush_cache(); void pause(); void resume(); + void set_allow_peers(bool b); void set_announce_to_dht(bool b) { m_announce_to_dht = b; } void set_announce_to_trackers(bool b) { m_announce_to_trackers = b; } void set_announce_to_lsd(bool b) { m_announce_to_lsd = b; } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 123d67ac6..c9d0635a3 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2377,11 +2377,11 @@ namespace aux { --tracker_limit; t->set_announce_to_dht(dht_limit >= 0); t->set_announce_to_trackers(tracker_limit >= 0); - if (t->is_paused()) t->resume(); + t->set_allow_peers(true); } else { - if (!t->is_paused()) t->pause(); + t->set_allow_peers(false); } } } diff --git a/src/torrent.cpp b/src/torrent.cpp index 42217e8bc..c28bbd52f 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -5335,6 +5335,30 @@ namespace libtorrent stop_announcing(); } + void torrent::set_allow_peers(bool b) + { + if (m_allow_peers == b) return; + + bool checking_files = should_check_files(); + + m_allow_peers = b; + + if (!b) + { + m_announce_to_dht = false; + m_announce_to_trackers = false; + m_announce_to_lsd = false; + do_pause(); + } + else + { + do_resume(); + } + + if (!checking_files && should_check_files()) + queue_torrent_check(); + } + void torrent::resume() { INVARIANT_CHECK; @@ -5345,12 +5369,9 @@ namespace libtorrent && m_announce_to_lsd) return; bool checking_files = should_check_files(); m_allow_peers = true; - if (!m_auto_managed) - { - m_announce_to_dht = true; - m_announce_to_trackers = true; - m_announce_to_lsd = true; - } + m_announce_to_dht = true; + m_announce_to_trackers = true; + m_announce_to_lsd = true; do_resume(); if (!checking_files && should_check_files()) queue_torrent_check();