diff --git a/ChangeLog b/ChangeLog index 869d0cf00..a4ebc57ce 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,5 @@ + * add_tracker() function added to torrent_handle * if there is no working tracker, current_tracker is the tracker that is currently being tried * torrents that are checking can now be paused, which will diff --git a/docs/manual.rst b/docs/manual.rst index 626d863e6..03629c279 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1619,6 +1619,7 @@ Its declaration looks like this:: std::vector const& trackers() const; void replace_trackers(std::vector const&); + void add_tracker(announc_entry const& url); void add_url_seed(std::string const& url); void remove_url_seed(std::string const& url); @@ -2047,13 +2048,14 @@ set_tracker_login() of the tracker announce. Set this if the tracker requires authorization. -trackers() replace_trackers() ------------------------------ +trackers() replace_trackers() add_tracker() +------------------------------------------- :: std::vector const& trackers() const; void replace_trackers(std::vector const&) const; + void add_tracker(announc_entry const& url); ``trackers()`` will return the list of trackers for this torrent. The announce entry contains both a string ``url`` which specify the announce url @@ -2064,6 +2066,10 @@ a list of the same form as the one returned from ``trackers()`` and will replace it. If you want an immediate effect, you have to call `force_reannounce()`_. +``add_tracker()`` will look if the specified tracker is already in the set. +If it is, it doesn't do anything. If it's not in the current set of trackers, +it will insert it in the tier specified in the announce_entry. + add_url_seed() remove_url_seed() url_seeds() -------------------------------------------- diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index f4ad12f17..eb0a17c63 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -586,6 +586,7 @@ namespace libtorrent { return m_trackers; } void replace_trackers(std::vector const& urls); + void add_tracker(announce_entry const& urls); torrent_handle get_handle(); diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 8cb97b7cb..6499527a3 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -331,6 +331,7 @@ namespace libtorrent std::vector const& trackers() const; void replace_trackers(std::vector const&) const; + void add_tracker(announce_entry const&) const; void add_url_seed(std::string const& url) const; void remove_url_seed(std::string const& url) const; diff --git a/src/torrent.cpp b/src/torrent.cpp index 5cc232987..3f345e3ed 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -2063,6 +2063,19 @@ namespace libtorrent else stop_announcing(); } + void torrent::add_tracker(announce_entry const& url) + { + std::vector::iterator k = std::find_if(m_trackers.begin() + , m_trackers.end(), boost::bind(&announce_entry::url, _1) == url.url); + if (k != m_trackers.end()) return; + k = std::upper_bound(m_trackers.begin(), m_trackers.end(), url + , boost::bind(&announce_entry::tier, _1) < boost::bind(&announce_entry::tier, _2)); + if (k - m_trackers.begin() < m_currently_trying_tracker) ++m_currently_trying_tracker; + if (k - m_trackers.begin() < m_last_working_tracker) ++m_last_working_tracker; + m_trackers.insert(k, url); + if (!m_trackers.empty()) start_announcing(); + } + void torrent::choke_peer(peer_connection& c) { INVARIANT_CHECK; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 44e823f17..441f7ef69 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -511,6 +511,12 @@ namespace libtorrent TORRENT_FORWARD(replace_trackers(urls)); } + void torrent_handle::add_tracker(announce_entry const& url) const + { + INVARIANT_CHECK; + TORRENT_FORWARD(add_tracker(url)); + } + storage_interface* torrent_handle::get_storage_impl() const { INVARIANT_CHECK;