diff --git a/ChangeLog b/ChangeLog index 657cf238b..c9b54c16b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * add option to ignore min-interval from trackers on force-reannounce * raise default setting for active_limit * fall back to copy+remove if rename_file fails * improve handling of filesystems not supporting fallocate() diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index c440aa46a..7673fedfd 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -393,7 +393,7 @@ void add_piece(torrent_handle& th, int piece, char const *data, int flags) void bind_torrent_handle() { // arguments are: number of seconds and tracker index - void (torrent_handle::*force_reannounce0)(int, int) const = &torrent_handle::force_reannounce; + void (torrent_handle::*force_reannounce0)(int, int, int) const = &torrent_handle::force_reannounce; #ifndef TORRENT_NO_DEPRECATE bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding; @@ -496,7 +496,7 @@ void bind_torrent_handle() .def("save_resume_data", _(&torrent_handle::save_resume_data), arg("flags") = 0) .def("need_save_resume_data", _(&torrent_handle::need_save_resume_data)) .def("force_reannounce", _(force_reannounce0) - , (arg("seconds") = 0, arg("tracker_idx") = -1)) + , (arg("seconds") = 0, arg("tracker_idx") = -1, arg("flags") = 0)) #ifndef TORRENT_DISABLE_DHT .def("force_dht_announce", _(&torrent_handle::force_dht_announce)) #endif @@ -558,6 +558,10 @@ void bind_torrent_handle() .value("only_if_modified", torrent_handle::only_if_modified) ; + enum_("reannounce_flags_t") + .value("ignore_min_interval", torrent_handle::ignore_min_interval) + ; + enum_("deadline_flags") .value("alert_when_available", torrent_handle::alert_when_available) ; diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 6d22d798a..92b5d59cc 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -731,7 +731,7 @@ namespace libtorrent void do_connect_boost(); // forcefully sets next_announce to the current time - void force_tracker_request(time_point, int tracker_idx); + void force_tracker_request(time_point, int tracker_idx, int flags); void scrape_tracker(int idx, bool user_triggered); void announce_with_tracker(boost::uint8_t e = tracker_request::none); diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index a23e7c6ca..95be00d48 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -1092,6 +1092,15 @@ namespace libtorrent void prioritize_files(std::vector const& files) const; std::vector file_priorities() const; + // flags to be used with force_reannounce + enum reannounce_flags_t + { + // by default, force-reannounce will still honor the min-interval + // published by the tracker. If this flag is set, it will be ignored + // and the tracker is announced immediately. + ignore_min_interval = 1 + }; + // ``force_reannounce()`` will force this torrent to do another tracker // request, to receive new peers. The ``seconds`` argument specifies how // many seconds from now to issue the tracker announces. @@ -1104,9 +1113,13 @@ namespace libtorrent // The ``tracker_index`` argument specifies which tracker to re-announce. // If set to -1 (which is the default), all trackers are re-announce. // + // The ``flags`` argument can be used to affect the re-announce. See + // reannounce_flags_t. + // // ``force_dht_announce`` will announce the torrent to the DHT // immediately. void force_reannounce(int seconds = 0, int tracker_index = -1) const; + void force_reannounce(int seconds, int tracker_index, int flags) const; void force_dht_announce() const; #ifndef TORRENT_NO_DEPRECATE diff --git a/include/libtorrent/tracker_manager.hpp b/include/libtorrent/tracker_manager.hpp index 9d1414eeb..6e964f874 100644 --- a/include/libtorrent/tracker_manager.hpp +++ b/include/libtorrent/tracker_manager.hpp @@ -194,7 +194,7 @@ namespace libtorrent { tracker_response() : interval(1800) - , min_interval(120) + , min_interval(1) , complete(-1) , incomplete(-1) , downloaders(-1) diff --git a/src/torrent.cpp b/src/torrent.cpp index a657d943e..838c04061 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3590,10 +3590,12 @@ namespace { } debug_log("TRACKER RESPONSE\n" "interval: %d\n" + "min-interval: %d\n" "external ip: %s\n" "resolved to: %s\n" "we connected to: %s\n" , interval + , resp.min_interval , print_address(resp.external_ip).c_str() , resolved_to.c_str() , print_address(tracker_ip).c_str()); @@ -3815,7 +3817,8 @@ namespace { // this is the entry point for the client to force a re-announce. It's // considered a client-initiated announce (as opposed to the regular ones, // issued by libtorrent) - void torrent::force_tracker_request(time_point t, int tracker_idx) + void torrent::force_tracker_request(time_point const t, int const tracker_idx + , int const flags) { if (is_paused()) return; if (tracker_idx == -1) @@ -3823,7 +3826,10 @@ namespace { for (std::vector::iterator i = m_trackers.begin() , end(m_trackers.end()); i != end; ++i) { - i->next_announce = (std::max)(t, i->min_announce) + seconds(1); + i->next_announce = (flags & torrent_handle::ignore_min_interval) + ? t + seconds(1) + : (std::max)(t, i->min_announce) + seconds(1); + i->min_announce = i->next_announce; i->triggered_manually = true; } } @@ -3833,7 +3839,10 @@ namespace { if (tracker_idx < 0 || tracker_idx >= int(m_trackers.size())) return; announce_entry& e = m_trackers[tracker_idx]; - e.next_announce = (std::max)(t, e.min_announce) + seconds(1); + e.next_announce = (flags & torrent_handle::ignore_min_interval) + ? t + seconds(1) + : (std::max)(t, e.min_announce) + seconds(1); + e.min_announce = e.next_announce; e.triggered_manually = true; } update_tracker_timer(clock_type::now()); diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index a152f164e..30c429724 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -709,8 +709,8 @@ namespace libtorrent void torrent_handle::force_reannounce( boost::posix_time::time_duration duration) const { - TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() - + seconds(duration.total_seconds()), -1); + TORRENT_ASYNC_CALL3(force_tracker_request, aux::time_now() + + seconds(duration.total_seconds()), -1, 0); } #endif @@ -723,7 +723,13 @@ namespace libtorrent void torrent_handle::force_reannounce(int s, int idx) const { - TORRENT_ASYNC_CALL2(force_tracker_request, aux::time_now() + seconds(s), idx); + TORRENT_ASYNC_CALL3(force_tracker_request, aux::time_now() + seconds(s), idx, 0); + } + + void torrent_handle::force_reannounce(int s, int idx, int flags) const + { + TORRENT_ASYNC_CALL3(force_tracker_request, aux::time_now() + seconds(s) + , idx, flags); } void torrent_handle::file_status(std::vector& status) const diff --git a/src/tracker_manager.cpp b/src/tracker_manager.cpp index 604070032..06b850e56 100644 --- a/src/tracker_manager.cpp +++ b/src/tracker_manager.cpp @@ -279,8 +279,6 @@ namespace libtorrent TORRENT_ASSERT(req.num_want >= 0); TORRENT_ASSERT(!m_abort || req.event == tracker_request::stopped); if (m_abort && req.event != tracker_request::stopped) return; - if (req.event == tracker_request::stopped) - req.num_want = 0; #ifndef TORRENT_DISABLE_LOGGING boost::shared_ptr cb = c.lock();