diff --git a/docs/manual.rst b/docs/manual.rst index 2053ac089..ad6721e20 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -394,7 +394,9 @@ async_add_torrent() add_torrent() flag_auto_managed = 0x040. flag_duplicate_is_error = 0x080, flag_merge_resume_trackers = 0x100, - flag_update_subscribe = 0x200 + flag_update_subscribe = 0x200, + flag_super_seeding = 0x400, + flag_sequential_download = 0x800 }; int version; @@ -417,6 +419,10 @@ async_add_torrent() add_torrent() std::string uuid; std::string source_feed_url; boost::uint64_t flags; + int max_uploads; + int max_connections; + int upload_limit; + int download_limit; }; torrent_handle add_torrent(add_torrent_params const& params); @@ -533,7 +539,9 @@ and how it's added. These are the flags:: flag_auto_managed = 0x040. flag_duplicate_is_error = 0x080, flag_merge_resume_trackers = 0x100, - flag_update_subscribe = 0x200 + flag_update_subscribe = 0x200, + flag_super_seeding = 0x400, + flag_sequential_download = 0x800 } ``flag_apply_ip_filter`` determines if the IP filter should apply to this torrent or not. By @@ -605,6 +613,20 @@ priorities for torrents in share mode, it will make it not work. The share mode has one setting, the share ratio target, see ``session_settings::share_mode_target`` for more info. +``flag_super_seeding`` sets the torrent into super seeding mode. If the torrent +is not a seed, this flag has no effect. It has the same effect as calling +``torrent_handle::super_seeding(true)`` on the torrent handle immediately +after adding it. + +``flag_sequential_download`` sets the sequential download state for the torrent. +It has the same effect as calling ``torrent_handle::sequential_download(true)`` +on the torrent handle immediately after adding it. + +``max_uploads``, ``max_connections``, ``upload_limit``, ``download_limit`` correspond +to the ``set_max_uploads()``, ``set_max_connections()``, ``set_upload_limit()`` and +``set_download_limit()`` functions on torrent_handle_. These values let you initialize +these settings when the torrent is added, instead of calling these functions immediately +following adding it. remove_torrent() ---------------- diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index 972b60b34..64d70ec49 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -71,6 +71,10 @@ namespace libtorrent #else , flags(default_flags) #endif + , max_uploads(-1) + , max_connections(-1) + , upload_limit(-1) + , download_limit(-1) { } @@ -105,6 +109,8 @@ namespace libtorrent flag_duplicate_is_error = 0x080, flag_merge_resume_trackers = 0x100, flag_update_subscribe = 0x200, + flag_super_seeding = 0x400, + flag_sequential_download = 0x800, default_flags = flag_update_subscribe | flag_auto_managed | flag_paused | flag_apply_ip_filter #ifndef TORRENT_NO_DEPRECATE @@ -144,6 +150,13 @@ namespace libtorrent bool duplicate_is_error; bool merge_resume_trackers; #endif + // -1 means unlimited on these settings + // just like their counterpart functions + // on torrent_handle + int max_uploads; + int max_connections; + int upload_limit; + int download_limit; }; } diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 0bfc6e265..e6f5a8d6d 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -770,14 +770,14 @@ namespace libtorrent void set_peer_upload_limit(tcp::endpoint ip, int limit); void set_peer_download_limit(tcp::endpoint ip, int limit); - void set_upload_limit(int limit); + void set_upload_limit(int limit, bool state_update = true); int upload_limit() const; - void set_download_limit(int limit); + void set_download_limit(int limit, bool state_update = true); int download_limit() const; - void set_max_uploads(int limit); + void set_max_uploads(int limit, bool state_update = true); int max_uploads() const { return m_max_uploads; } - void set_max_connections(int limit); + void set_max_connections(int limit, bool state_update = true); int max_connections() const { return m_max_connections; } void move_storage(std::string const& save_path); diff --git a/src/torrent.cpp b/src/torrent.cpp index 9c3c0ddde..b489591af 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -562,6 +562,17 @@ namespace libtorrent #endif INVARIANT_CHECK; + if (p.flags & add_torrent_params::flag_sequential_download) + m_sequential_download = true; + + if (p.flags & add_torrent_params::flag_super_seeding) + m_super_seeding = true; + + set_max_uploads(p.max_uploads, false); + set_max_connections(p.max_connections, false); + set_upload_limit(p.upload_limit, false); + set_download_limit(p.download_limit, false); + if (!m_name && !m_url.empty()) m_name.reset(new std::string(m_url)); #ifndef TORRENT_NO_DEPRECATE @@ -3545,9 +3556,6 @@ namespace libtorrent { if (on == m_super_seeding) return; - // don't turn on super seeding if we're not a seed - TORRENT_ASSERT(!on || is_seed() || !m_files_checked); - if (on && !is_seed() && m_files_checked) return; m_super_seeding = on; if (m_super_seeding) return; @@ -6668,21 +6676,21 @@ namespace libtorrent m_ses.m_auto_manage_time_scaler = 2; } - void torrent::set_max_uploads(int limit) + void torrent::set_max_uploads(int limit, bool state_update) { TORRENT_ASSERT(m_ses.is_network_thread()); TORRENT_ASSERT(limit >= -1); if (limit <= 0) limit = (1<<24)-1; - if (m_max_uploads != limit) state_updated(); + if (m_max_uploads != limit && state_update) state_updated(); m_max_uploads = limit; } - void torrent::set_max_connections(int limit) + void torrent::set_max_connections(int limit, bool state_update) { TORRENT_ASSERT(m_ses.is_network_thread()); TORRENT_ASSERT(limit >= -1); if (limit <= 0) limit = (1<<24)-1; - if (m_max_connections != limit) state_updated(); + if (m_max_connections != limit && state_update) state_updated(); m_max_connections = limit; if (num_peers() > int(m_max_connections)) @@ -6730,12 +6738,13 @@ namespace libtorrent (*i)->set_download_limit(limit); } - void torrent::set_upload_limit(int limit) + void torrent::set_upload_limit(int limit, bool state_update) { TORRENT_ASSERT(m_ses.is_network_thread()); TORRENT_ASSERT(limit >= -1); if (limit <= 0) limit = 0; - if (m_bandwidth_channel[peer_connection::upload_channel].throttle() != limit) + if (m_bandwidth_channel[peer_connection::upload_channel].throttle() != limit + && state_update) state_updated(); m_bandwidth_channel[peer_connection::upload_channel].throttle(limit); } @@ -6748,12 +6757,13 @@ namespace libtorrent return limit; } - void torrent::set_download_limit(int limit) + void torrent::set_download_limit(int limit, bool state_update) { TORRENT_ASSERT(m_ses.is_network_thread()); TORRENT_ASSERT(limit >= -1); if (limit <= 0) limit = 0; - if (m_bandwidth_channel[peer_connection::download_channel].throttle() != limit) + if (m_bandwidth_channel[peer_connection::download_channel].throttle() != limit + && state_update) state_updated(); m_bandwidth_channel[peer_connection::download_channel].throttle(limit); } diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index c2bcba977..7eca72774 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -293,7 +293,7 @@ namespace libtorrent { INVARIANT_CHECK; TORRENT_ASSERT(max_uploads >= 2 || max_uploads == -1); - TORRENT_ASYNC_CALL1(set_max_uploads, max_uploads); + TORRENT_ASYNC_CALL2(set_max_uploads, max_uploads, true); } void torrent_handle::use_interface(const char* net_interface) const @@ -313,14 +313,14 @@ namespace libtorrent { INVARIANT_CHECK; TORRENT_ASSERT(max_connections >= 2 || max_connections == -1); - TORRENT_ASYNC_CALL1(set_max_connections, max_connections); + TORRENT_ASYNC_CALL2(set_max_connections, max_connections, true); } void torrent_handle::set_upload_limit(int limit) const { INVARIANT_CHECK; TORRENT_ASSERT(limit >= -1); - TORRENT_ASYNC_CALL1(set_upload_limit, limit); + TORRENT_ASYNC_CALL2(set_upload_limit, limit, true); } int torrent_handle::upload_limit() const @@ -334,7 +334,7 @@ namespace libtorrent { INVARIANT_CHECK; TORRENT_ASSERT(limit >= -1); - TORRENT_ASYNC_CALL1(set_download_limit, limit); + TORRENT_ASYNC_CALL2(set_download_limit, limit, true); } int torrent_handle::download_limit() const