From f26df6cbfaaddf9693c1707f4083fc2a99075b41 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 2 Jan 2014 02:16:31 +0000 Subject: [PATCH] allow force_announce to only affect a single tracker --- ChangeLog | 1 + bindings/python/src/torrent_handle.cpp | 8 ++++++-- include/libtorrent/torrent.hpp | 3 +-- include/libtorrent/torrent_handle.hpp | 26 +++++++++++++++++--------- src/torrent.cpp | 24 +++++++++++++++--------- src/torrent_handle.cpp | 9 ++++++--- 6 files changed, 46 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 845529107..226ca144b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * allow force_announce to only affect a single tracker * add moving_storage field to torrent_status * expose UPnP and NAT-PMP mapping in session object * DHT refactoring and support for storing arbitrary data with put diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 7d47a3a06..024c6f6dc 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -348,7 +348,8 @@ void add_piece(torrent_handle& th, int piece, char const *data, int flags) void bind_torrent_handle() { - void (torrent_handle::*force_reannounce0)() const = &torrent_handle::force_reannounce; + // arguments are: number of seconds and tracker index + void (torrent_handle::*force_reannounce0)(int, int) const = &torrent_handle::force_reannounce; #ifndef TORRENT_NO_DEPRECATE bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding; @@ -442,8 +443,11 @@ void bind_torrent_handle() .def("file_priority", &file_prioritity1) .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)) + .def("force_reannounce", _(force_reannounce0) + , (arg("seconds") = 0, arg("tracker_idx") = -1)) +#ifndef TORRENT_NO_DEPRECATE .def("force_reannounce", &force_reannounce) +#endif #ifndef TORRENT_DISABLE_DHT .def("force_dht_announce", _(&torrent_handle::force_dht_announce)) #endif diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 496a1b5d1..1d539ae4f 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -480,8 +480,7 @@ namespace libtorrent ptime next_announce() const; // forcefully sets next_announce to the current time - void force_tracker_request(); - void force_tracker_request(ptime); + void force_tracker_request(ptime, int tracker_idx); void scrape_tracker(); void announce_with_tracker(tracker_request::event_t e = tracker_request::none diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index db7eba465..3d2f55b96 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -862,23 +862,31 @@ namespace libtorrent void prioritize_files(std::vector const& files) const; std::vector file_priorities() const; - // ``force_reannounce()`` will force this torrent to do another tracker request, to receive new - // peers. The second overload of ``force_reannounce`` that takes a ``time_duration`` as - // argument will schedule a reannounce in that amount of time from now. + // ``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. // - // If the tracker's ``min_interval`` has not passed since the last announce, the forced - // announce will be scheduled to happen immediately as the ``min_interval`` expires. This is - // to honor trackers minimum re-announce interval settings. + // If the tracker's ``min_interval`` has not passed since the last + // announce, the forced announce will be scheduled to happen immediately + // as the ``min_interval`` expires. This is to honor trackers minimum + // re-announce interval settings. + // + // The ``tracker_index`` argument specifies which tracker to re-announce. + // If set to -1 (which is the default), all trackers are re-announce. // - // ``force_dht_announce`` will announce the torrent to the DHT immediately. - void force_reannounce() const; + // ``force_dht_announce`` will announce the torrent to the DHT + // immediately. + void force_reannounce(int seconds = 0, int tracker_index = -1) const; void force_dht_announce() const; +#ifndef TORRENT_NO_DEPRECATE // forces a reannounce in the specified amount of time. // This overrides the default announce interval, and no // announce will take place until the given time has // timed out. - void force_reannounce(boost::posix_time::time_duration) const; + TORRENT_DEPRECATED_PREFIX + void force_reannounce(boost::posix_time::time_duration) const TORRENT_DEPRECATED; +#endif // ``scrape_tracker()`` will send a scrape request to the tracker. A scrape request queries the // tracker for statistics such as total number of incomplete peers, complete peers, number of diff --git a/src/torrent.cpp b/src/torrent.cpp index 15b8da353..b556124e2 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2682,17 +2682,23 @@ namespace libtorrent return m_waiting_tracker?m_tracker_timer.expires_at():min_time(); } - void torrent::force_tracker_request() - { - force_tracker_request(time_now_hires()); - } - - void torrent::force_tracker_request(ptime t) + void torrent::force_tracker_request(ptime t, int tracker_idx) { if (is_paused()) return; - 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); + if (tracker_idx == -1) + { + 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); + } + else + { + TORRENT_ASSERT(tracker_idx >= 0 && tracker_idx < int(m_trackers.size())); + 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); + } update_tracker_timer(time_now_hires()); } diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index aecef1d3c..4265cb6b1 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -810,11 +810,14 @@ namespace libtorrent TORRENT_ASYNC_CALL2(add_peer, adr, source); } +#ifndef TORRENT_NO_DEPRECATE void torrent_handle::force_reannounce( boost::posix_time::time_duration duration) const { - TORRENT_ASYNC_CALL1(force_tracker_request, time_now() + seconds(duration.total_seconds())); + TORRENT_ASYNC_CALL2(force_tracker_request, time_now() + + seconds(duration.total_seconds()), -1); } +#endif void torrent_handle::force_dht_announce() const { @@ -823,9 +826,9 @@ namespace libtorrent #endif } - void torrent_handle::force_reannounce() const + void torrent_handle::force_reannounce(int s, int idx) const { - TORRENT_ASYNC_CALL1(force_tracker_request, time_now()); + TORRENT_ASYNC_CALL2(force_tracker_request, time_now() + seconds(s), idx); } void torrent_handle::scrape_tracker() const