From 418c1e8190189df45861ff656e8665cbabd3fdfc Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 29 Mar 2012 03:51:22 +0000 Subject: [PATCH] make tracker back-off configurable --- ChangeLog | 1 + bindings/python/src/session_settings.cpp | 2 ++ docs/manual.html | 24 +++++++++++++++++------- docs/manual.rst | 13 +++++++++++++ include/libtorrent/session_settings.hpp | 8 ++++++++ include/libtorrent/torrent_info.hpp | 3 ++- src/session.cpp | 1 + src/session_impl.cpp | 2 ++ src/torrent.cpp | 2 +- src/torrent_info.cpp | 7 +++++-- test/test_primitives.cpp | 4 +++- 11 files changed, 55 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 91e7af89e..e47694548 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 0.16 release + * make tracker back-off configurable * don't restart the swarm after downloading metadata from magnet links * lower the default tracker retry intervals * support banning web seeds sending corrupt data diff --git a/bindings/python/src/session_settings.cpp b/bindings/python/src/session_settings.cpp index 6c66f6e6e..cddab28c7 100644 --- a/bindings/python/src/session_settings.cpp +++ b/bindings/python/src/session_settings.cpp @@ -170,6 +170,8 @@ void bind_session_settings() .def_readwrite("enable_incoming_tcp", &session_settings::enable_incoming_tcp) .def_readwrite("enable_outgoing_utp", &session_settings::enable_outgoing_utp) .def_readwrite("enable_incoming_utp", &session_settings::enable_incoming_utp) + .def_readwrite("ssl_listen", &session_settings::ssl_listen) + .def_readwrite("tracker_backoff", &session_settings::tracker_backoff) ; enum_("proxy_type") diff --git a/docs/manual.html b/docs/manual.html index 9829d802b..439ca0447 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -4299,6 +4299,8 @@ struct session_settings bool lock_files; int ssl_listen; + + int tracker_backoff; };

version is automatically set to the libtorrent version you're using @@ -5037,6 +5039,14 @@ no SSL listen port is opened. Otherwise a socket is opened on this port. This setting is only taken into account when opening the regular listen port, and won't re-open the listen socket simply by changing this setting.

It defaults to port 4433.

+

tracker_backoff determines how aggressively to back off from retrying +failing trackers. This value determines x in the following formula, determining +the number of seconds to wait until the next retry:

+
+delay = 5 + 5 * x / 100 * fails^2
+

It defaults to 250.

+

This setting may be useful to make libtorrent more or less aggressive in hitting +trackers.

@@ -6248,7 +6258,7 @@ struct peer_disconnected_alert: peer_alert

invalid_request_alert

This is a debug alert that is generated by an incoming invalid piece request. -Ïp is the address of the peer and the request is the actual incoming +ìp is the address of the peer and the request is the actual incoming request from the peer.

 struct invalid_request_alert: peer_alert
@@ -7835,13 +7845,13 @@ std::string error_code_to_string(boost::system::error_code const& ec)
         static const char const* swedish[] =
         {
                 "inget fel",
-                "en fil i torrenten kolliderar med en fil frÂn en annan torrent",
+                "en fil i torrenten kolliderar med en fil från en annan torrent",
                 "hash check misslyckades",
-                "torrent filen ‰r inte en dictionary",
-                "'info'-nyckeln saknas eller ‰r korrupt i torrentfilen",
-                "'info'-f‰ltet ‰r inte en dictionary",
-                "'piece length' f‰ltet saknas eller ‰r korrupt i torrentfilen",
-                "torrentfilen saknar namnf‰ltet",
+                "torrent filen är inte en dictionary",
+                "'info'-nyckeln saknas eller är korrupt i torrentfilen",
+                "'info'-fältet är inte en dictionary",
+                "'piece length' fältet saknas eller är korrupt i torrentfilen",
+                "torrentfilen saknar namnfältet",
                 "ogiltigt namn i torrentfilen (kan vara en attack)",
                 // ... more strings here
         };
diff --git a/docs/manual.rst b/docs/manual.rst
index c87499d6a..e9c785897 100644
--- a/docs/manual.rst
+++ b/docs/manual.rst
@@ -4556,6 +4556,8 @@ session_settings
 		bool lock_files;
 
 		int ssl_listen;
+
+		int tracker_backoff;
 	};
 
 ``version`` is automatically set to the libtorrent version you're using
@@ -5442,6 +5444,17 @@ won't re-open the listen socket simply by changing this setting.
 
 It defaults to port 4433.
 
+``tracker_backoff`` determines how aggressively to back off from retrying
+failing trackers. This value determines *x* in the following formula, determining
+the number of seconds to wait until the next retry:
+
+	delay = 5 + 5 * x / 100 * fails^2
+
+It defaults to 250.
+
+This setting may be useful to make libtorrent more or less aggressive in hitting
+trackers.
+
 pe_settings
 ===========
 
diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp
index 4e929680f..c5776a751 100644
--- a/include/libtorrent/session_settings.hpp
+++ b/include/libtorrent/session_settings.hpp
@@ -919,6 +919,14 @@ namespace libtorrent
 
 		// open an ssl listen socket for ssl torrents on this port
 		int ssl_listen;
+
+		// this is the factor X in the formula to calculate the
+		// next tracker timeout:
+		// delay = 5 + X/100 * fails^2
+		// so, it's an exponential back-off, and this factor
+		// determines how fast the back-off happens. Default
+		// is 250
+		int tracker_backoff;
 	};
 
 #ifndef TORRENT_DISABLE_DHT
diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp
index 3faa117b5..9a00f8a0f 100644
--- a/include/libtorrent/torrent_info.hpp
+++ b/include/libtorrent/torrent_info.hpp
@@ -63,6 +63,7 @@ POSSIBILITY OF SUCH DAMAGE.
 namespace libtorrent
 {
 	class peer_connection;
+	struct session_settings;
 
 	enum
 	{
@@ -144,7 +145,7 @@ namespace libtorrent
 			min_announce = min_time();
 		}
 
-		void failed(int retry_interval = 0);
+		void failed(session_settings const& sett, int retry_interval = 0);
 
 		bool will_announce(ptime now) const
 		{
diff --git a/src/session.cpp b/src/session.cpp
index 8a08d04db..341b77560 100644
--- a/src/session.cpp
+++ b/src/session.cpp
@@ -1276,6 +1276,7 @@ namespace libtorrent
 		, use_disk_read_ahead(true)
 		, lock_files(false)
 		, ssl_listen(4433)
+		, tracker_backoff(250)
 	{}
 
 	session_settings::~session_settings() {}
diff --git a/src/session_impl.cpp b/src/session_impl.cpp
index 38cdf311b..906f4d1f1 100644
--- a/src/session_impl.cpp
+++ b/src/session_impl.cpp
@@ -441,6 +441,8 @@ namespace aux {
 		TORRENT_SETTING(integer, read_job_every)
 		TORRENT_SETTING(boolean, use_disk_read_ahead)
 		TORRENT_SETTING(boolean, lock_files)
+		TORRENT_SETTING(integer, ssl_listen)
+		TORRENT_SETTING(integer, tracker_backoff)
 	};
 
 #undef TORRENT_SETTING
diff --git a/src/torrent.cpp b/src/torrent.cpp
index 9c2530319..6a3767f7d 100644
--- a/src/torrent.cpp
+++ b/src/torrent.cpp
@@ -8454,7 +8454,7 @@ namespace libtorrent
 			announce_entry* ae = find_tracker(r);
 			if (ae)
 			{
-				ae->failed(retry_interval);
+				ae->failed(settings(), retry_interval);
 				ae->last_error = ec;
 				ae->message = msg;
 				int tracker_index = ae - &m_trackers[0];
diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp
index e549dd865..e2c7029ba 100644
--- a/src/torrent_info.cpp
+++ b/src/torrent_info.cpp
@@ -64,6 +64,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "libtorrent/utf8.hpp"
 #include "libtorrent/time.hpp"
 #include "libtorrent/invariant_check.hpp"
+#include "libtorrent/session_settings.hpp"
 
 #if TORRENT_USE_I2P
 #include "libtorrent/parse_url.hpp"
@@ -470,13 +471,15 @@ namespace libtorrent
 	int announce_entry::min_announce_in() const
 	{ return total_seconds(min_announce - time_now()); }
 
-	void announce_entry::failed(int retry_interval)
+	void announce_entry::failed(session_settings const& sett, int retry_interval)
 	{
 		++fails;
 		// the exponential back-off ends up being:
 		// 7, 15, 27, 45, 95, 127, 165, ... seconds
+		// with the default tracker_backoff of 250
 		int delay = (std::min)(tracker_retry_delay_min + int(fails) * int(fails)
-			* tracker_retry_delay_min / 2, int(tracker_retry_delay_max));
+			* tracker_retry_delay_min * sett.tracker_backoff / 100
+			, int(tracker_retry_delay_max));
 		delay = (std::max)(delay, retry_interval);
 		next_announce = time_now() + seconds(delay);
 		updating = false;
diff --git a/test/test_primitives.cpp b/test/test_primitives.cpp
index 8371b8505..841cf3df2 100644
--- a/test/test_primitives.cpp
+++ b/test/test_primitives.cpp
@@ -400,9 +400,11 @@ int test_main()
 	// on failing announces
 	announce_entry ae("dummy");
 	int last = 0;
+	session_settings sett;
+	sett.tracker_backoff = 250;
 	for (int i = 0; i < 10; ++i)
 	{
-		ae.failed(5);
+		ae.failed(sett, 5);
 		int delay = ae.next_announce_in();
 		TEST_CHECK(delay > last);
 		last = delay;