From c70223ff38415e7554cc1040f1b2f538f4b9b1a5 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Fri, 17 Aug 2007 16:40:55 +0000 Subject: [PATCH] added url seed related functions to torrent_handle --- docs/manual.rst | 17 ++++++++++++----- include/libtorrent/torrent.hpp | 2 ++ include/libtorrent/torrent_handle.hpp | 5 ++++- src/torrent_handle.cpp | 20 ++++++++++++++++++-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 34d8171fd..e9b32aad1 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1090,8 +1090,8 @@ The input range is assumed to be valid within the torrent. ``file_offset`` must refer to a valid file, i.e. it cannot be >= ``num_files()``. -url_seeds() ------------ +url_seeds() add_url_seed() +-------------------------- :: @@ -1266,6 +1266,8 @@ Its declaration looks like this:: void replace_trackers(std::vector const&); void add_url_seed(std::string const& url); + void remove_url_seed(std::string const& url); + std::set url_seeds() const; void set_ratio(float ratio) const; void set_max_uploads(int max_uploads) const; @@ -1601,17 +1603,22 @@ replace it. If you want an immediate effect, you have to call `force_reannounce()`_. -add_url_seed() --------------- +add_url_seed() remove_url_seed() url_seeds() +-------------------------------------------- :: void add_url_seed(std::string const& url); + void remove_url_seed(std::string const& url); + std::set url_seeds() const; ``add_url_seed()`` adds another url to the torrent's list of url seeds. If the given url already exists in that list, the call has no effect. The torrent will connect to the server and try to download pieces from it, unless it's -paused, queued, checking or seeding. +paused, queued, checking or seeding. ``remove_url_seed()`` removes the given +url if it exists already. ``url_seeds()`` return a set of the url seeds +currently in this torrent. Note that urls that fails may be removed +automatically from the list. See `HTTP seeding`_ for more information. diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 8c53166d4..6781465c0 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -249,6 +249,8 @@ namespace libtorrent void remove_url_seed(std::string const& url) { m_web_seeds.erase(url); } + std::set url_seeds() const + { return m_web_seeds; } bool free_upload_slots() const { return m_num_uploads < m_max_uploads; } diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 3f7ae5bcc..31a39c38e 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -34,6 +34,7 @@ POSSIBILITY OF SUCH DAMAGE. #define TORRENT_TORRENT_HANDLE_HPP_INCLUDED #include +#include #ifdef _MSC_VER #pragma warning(push, 1) @@ -273,7 +274,9 @@ namespace libtorrent std::vector const& trackers() const; void replace_trackers(std::vector const&) const; - void add_url_seed(std::string const& url); + void add_url_seed(std::string const& url) const; + void remove_url_seed(std::string const& url) const; + std::set url_seeds() const; bool has_metadata() const; const torrent_info& get_torrent_info() const; diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index e0e9f29e6..9dc1e6d26 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -453,14 +453,30 @@ namespace libtorrent , m_chk, m_info_hash, bind(&torrent::trackers, _1)); } - void torrent_handle::add_url_seed(std::string const& url) + void torrent_handle::add_url_seed(std::string const& url) const { INVARIANT_CHECK; - return call_member(m_ses, m_chk, m_info_hash + call_member(m_ses, m_chk, m_info_hash , bind(&torrent::add_url_seed, _1, url)); } + void torrent_handle::remove_url_seed(std::string const& url) const + { + INVARIANT_CHECK; + + call_member(m_ses, m_chk, m_info_hash + , bind(&torrent::remove_url_seed, _1, url)); + } + + std::set torrent_handle::url_seeds() const + { + INVARIANT_CHECK; + + return call_member >(m_ses, m_chk, m_info_hash + , bind(&torrent::url_seeds, _1)); + } + void torrent_handle::replace_trackers( std::vector const& urls) const {