From 6c137d6ef67ddf89568dfdae0a7d03d308164980 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 25 Oct 2009 02:37:45 +0000 Subject: [PATCH] announces torrents immediately to the DHT when it's started --- ChangeLog | 2 ++ bindings/python/src/torrent_handle.cpp | 1 + docs/manual.rst | 8 ++++++-- include/libtorrent/torrent.hpp | 4 ++++ include/libtorrent/torrent_handle.hpp | 4 ++++ src/session_impl.cpp | 7 +++++++ src/torrent.cpp | 12 ++++++++++++ src/torrent_handle.cpp | 8 ++++++++ 8 files changed, 44 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 17a47f0ff..02a260c97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -74,6 +74,7 @@ * added torrent_status::finished_time * automatically caps files and connections by default to rlimit * added session::is_dht_running() function + * added torrent_handle::force_dht_announce() release 0.14.7 @@ -88,6 +89,7 @@ release 0.14.7 was received * fixed incorrect error when deleting files from a torrent where not all files have been created + * announces torrents immediately to the DHT when it's started release 0.14.6 diff --git a/bindings/python/src/torrent_handle.cpp b/bindings/python/src/torrent_handle.cpp index 51bf506aa..7c6207554 100644 --- a/bindings/python/src/torrent_handle.cpp +++ b/bindings/python/src/torrent_handle.cpp @@ -353,6 +353,7 @@ void bind_torrent_handle() .def("save_resume_data", _(&torrent_handle::save_resume_data)) .def("force_reannounce", _(force_reannounce0)) .def("force_reannounce", &force_reannounce) + .def("force_dht_announce", _(&torrent_handle::force_dht_announce)) .def("scrape_tracker", _(&torrent_handle::scrape_tracker)) .def("name", _(&torrent_handle::name)) .def("set_upload_limit", _(&torrent_handle::set_upload_limit)) diff --git a/docs/manual.rst b/docs/manual.rst index daf002faf..0e0822317 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -1863,6 +1863,7 @@ Its declaration looks like this:: void save_resume_data() const; void force_reannounce() const; + void force_dht_announce() const; void force_reannounce(boost::posix_time::time_duration) const; void scrape_tracker() const; void connect_peer(asio::ip::tcp::endpoint const& adr, int source = 0) const; @@ -2188,18 +2189,21 @@ read_piece_alert_. In order to receive this alert, you must enable Note that if you read multiple pieces, the read operations are not guaranteed to finish in the same order as you initiated them. -force_reannounce() ------------------- +force_reannounce() force_dht_announce() +--------------------------------------- :: void force_reannounce() const; void force_reannounce(boost::posix_time::time_duration) const; + void force_dht_announce() 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_dht_announce`` will announce the torrent to the DHT immediately. + scrape_tracker() ---------------- diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 4dd731790..f5be5ced2 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -412,6 +412,10 @@ namespace libtorrent , address const& bind_interface = address_v4::any()); ptime const& last_scrape() const { return m_last_scrape; } +#ifndef TORRENT_DISABLE_DHT + void force_dht_announce(); +#endif + // sets the username and password that will be sent to // the tracker void set_tracker_login(std::string const& name, std::string const& pw); diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index f5b96e73f..45a819a6c 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -511,6 +511,10 @@ namespace libtorrent // forces this torrent to reannounce // (make a rerequest from the tracker) void force_reannounce() const; +#ifndef TORRENT_DISABLE_DHT + // announces this torrent to the DHT immediately + void force_dht_announce() const; +#endif // forces a reannounce in the specified amount of time. // This overrides the default announce interval, and no diff --git a/src/session_impl.cpp b/src/session_impl.cpp index d178177a7..38ffdc1af 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2570,6 +2570,13 @@ namespace aux { std::list >().swap(m_dht_router_nodes); m_dht->start(startup_state); + + // announce all torrents we have to the DHT + for (torrent_map::const_iterator i = m_torrents.begin() + , end(m_torrents.end()); i != end; ++i) + { + i->second->force_dht_announce(); + } } #ifndef TORRENT_DISABLE_DHT diff --git a/src/torrent.cpp b/src/torrent.cpp index 6d0b423ba..bfeffce89 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -359,6 +359,18 @@ namespace libtorrent return verified_trackers == 0; } + + void torrent::force_dht_announce() + { + m_last_dht_announce = min_time(); + // DHT announces are done on the local service + // discovery timer. Trigger it. + error_code ec; + boost::weak_ptr self(shared_from_this()); + m_lsd_announce_timer.expires_from_now(seconds(1), ec); + m_lsd_announce_timer.async_wait( + bind(&torrent::on_lsd_announce_disp, self, _1)); + } #endif torrent::~torrent() diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index cf03e0218..f215134f3 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -661,6 +661,14 @@ namespace libtorrent TORRENT_FORWARD(force_tracker_request(time_now() + seconds(duration.total_seconds()))); } +#ifndef TORRENT_DISABLE_DHT + void torrent_handle::force_dht_announce() const + { + INVARIANT_CHECK; + TORRENT_FORWARD(force_dht_announce()); + } +#endif + void torrent_handle::force_reannounce() const { INVARIANT_CHECK;