allow force_announce to only affect a single tracker

This commit is contained in:
Arvid Norberg 2014-01-02 02:16:31 +00:00
parent 31e6d54ad2
commit f26df6cbfa
6 changed files with 46 additions and 25 deletions

View File

@ -1,3 +1,4 @@
* allow force_announce to only affect a single tracker
* add moving_storage field to torrent_status * add moving_storage field to torrent_status
* expose UPnP and NAT-PMP mapping in session object * expose UPnP and NAT-PMP mapping in session object
* DHT refactoring and support for storing arbitrary data with put * DHT refactoring and support for storing arbitrary data with put

View File

@ -348,7 +348,8 @@ void add_piece(torrent_handle& th, int piece, char const *data, int flags)
void bind_torrent_handle() 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 #ifndef TORRENT_NO_DEPRECATE
bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding; bool (torrent_handle::*super_seeding0)() const = &torrent_handle::super_seeding;
@ -442,8 +443,11 @@ void bind_torrent_handle()
.def("file_priority", &file_prioritity1) .def("file_priority", &file_prioritity1)
.def("save_resume_data", _(&torrent_handle::save_resume_data), arg("flags") = 0) .def("save_resume_data", _(&torrent_handle::save_resume_data), arg("flags") = 0)
.def("need_save_resume_data", _(&torrent_handle::need_save_resume_data)) .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) .def("force_reannounce", &force_reannounce)
#endif
#ifndef TORRENT_DISABLE_DHT #ifndef TORRENT_DISABLE_DHT
.def("force_dht_announce", _(&torrent_handle::force_dht_announce)) .def("force_dht_announce", _(&torrent_handle::force_dht_announce))
#endif #endif

View File

@ -480,8 +480,7 @@ namespace libtorrent
ptime next_announce() const; ptime next_announce() const;
// forcefully sets next_announce to the current time // forcefully sets next_announce to the current time
void force_tracker_request(); void force_tracker_request(ptime, int tracker_idx);
void force_tracker_request(ptime);
void scrape_tracker(); void scrape_tracker();
void announce_with_tracker(tracker_request::event_t e void announce_with_tracker(tracker_request::event_t e
= tracker_request::none = tracker_request::none

View File

@ -862,23 +862,31 @@ namespace libtorrent
void prioritize_files(std::vector<int> const& files) const; void prioritize_files(std::vector<int> const& files) const;
std::vector<int> file_priorities() const; std::vector<int> file_priorities() const;
// ``force_reannounce()`` will force this torrent to do another tracker request, to receive new // ``force_reannounce()`` will force this torrent to do another tracker
// peers. The second overload of ``force_reannounce`` that takes a ``time_duration`` as // request, to receive new peers. The ``seconds`` argument specifies how
// argument will schedule a reannounce in that amount of time from now. // many seconds from now to issue the tracker announces.
// //
// If the tracker's ``min_interval`` has not passed since the last announce, the forced // If the tracker's ``min_interval`` has not passed since the last
// announce will be scheduled to happen immediately as the ``min_interval`` expires. This is // announce, the forced announce will be scheduled to happen immediately
// to honor trackers minimum re-announce interval settings. // 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. // ``force_dht_announce`` will announce the torrent to the DHT
void force_reannounce() const; // immediately.
void force_reannounce(int seconds = 0, int tracker_index = -1) const;
void force_dht_announce() const; void force_dht_announce() const;
#ifndef TORRENT_NO_DEPRECATE
// forces a reannounce in the specified amount of time. // forces a reannounce in the specified amount of time.
// This overrides the default announce interval, and no // This overrides the default announce interval, and no
// announce will take place until the given time has // announce will take place until the given time has
// timed out. // 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 // ``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 // tracker for statistics such as total number of incomplete peers, complete peers, number of

View File

@ -2682,17 +2682,23 @@ namespace libtorrent
return m_waiting_tracker?m_tracker_timer.expires_at():min_time(); return m_waiting_tracker?m_tracker_timer.expires_at():min_time();
} }
void torrent::force_tracker_request() void torrent::force_tracker_request(ptime t, int tracker_idx)
{
force_tracker_request(time_now_hires());
}
void torrent::force_tracker_request(ptime t)
{ {
if (is_paused()) return; if (is_paused()) return;
for (std::vector<announce_entry>::iterator i = m_trackers.begin() if (tracker_idx == -1)
, end(m_trackers.end()); i != end; ++i) {
i->next_announce = (std::max)(t, i->min_announce) + seconds(1); for (std::vector<announce_entry>::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()); update_tracker_timer(time_now_hires());
} }

View File

@ -810,11 +810,14 @@ namespace libtorrent
TORRENT_ASYNC_CALL2(add_peer, adr, source); TORRENT_ASYNC_CALL2(add_peer, adr, source);
} }
#ifndef TORRENT_NO_DEPRECATE
void torrent_handle::force_reannounce( void torrent_handle::force_reannounce(
boost::posix_time::time_duration duration) const 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 void torrent_handle::force_dht_announce() const
{ {
@ -823,9 +826,9 @@ namespace libtorrent
#endif #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 void torrent_handle::scrape_tracker() const