From 5fb854d7246e63219635ed6d413c2911c7d75e84 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 9 Dec 2008 07:56:37 +0000 Subject: [PATCH] improved super seeding with strict option --- docs/manual.rst | 5 +++++ include/libtorrent/session_settings.hpp | 5 +++++ src/peer_connection.cpp | 19 ++++++++++++++++++- test/test_swarm.cpp | 6 +++++- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index 5b55b6665..5b3640f0d 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3147,6 +3147,7 @@ that will be sent to the tracker. The user-agent is a good way to identify your bool announce_to_all_trackers; bool prefer_udp_trackers; + bool strict_super_seeding; }; ``user_agent`` this is the client identification to the tracker. @@ -3445,6 +3446,10 @@ trackers for the same hostname. Setting this to fails means that the trackers' tier is respected and there's no preference of one protocol over another. +``strict_super_seeding`` when this is set to true, a piece has to +have been forwarded to a third peer before another one is handed out. +This is the traditional definition of super seeding. + pe_settings =========== diff --git a/include/libtorrent/session_settings.hpp b/include/libtorrent/session_settings.hpp index c13ddc8d3..d103befc2 100644 --- a/include/libtorrent/session_settings.hpp +++ b/include/libtorrent/session_settings.hpp @@ -146,6 +146,7 @@ namespace libtorrent , rate_limit_ip_overhead(true) , announce_to_all_trackers(false) , prefer_udp_trackers(true) + , strict_super_seeding(false) {} // this is the user agent that will be sent to the tracker @@ -468,6 +469,10 @@ namespace libtorrent // with udp:// protocol, it is preferred over the same // tracker over http://. bool prefer_udp_trackers; + + // when set to true, a piece has to have been forwarded + // to a third peer before another one is handed out + bool strict_super_seeding; }; #ifndef TORRENT_DISABLE_DHT diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 79ac4dc2c..96cbb3801 100644 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -1234,7 +1234,7 @@ namespace libtorrent return; } - if (t->super_seeding()) + if (t->super_seeding() && !m_ses.settings().strict_super_seeding) { // if we're superseeding and the peer just told // us that it completed the piece we're superseeding @@ -1284,6 +1284,23 @@ namespace libtorrent } } + // if we're super seeding, this might mean that somebody + // forwarded this piece. In which case we need to give + // a new piece to that peer + if (t->super_seeding() + && m_ses.settings().strict_super_seeding + && (index != m_superseed_piece || t->num_peers() == 1)) + { + for (torrent::peer_iterator i = t->begin() + , end(t->end()); i != end; ++i) + { + peer_connection* p = *i; + if (p->superseed_piece() != index) continue; + if (!p->has_piece(index)) continue; + p->superseed_piece(t->get_piece_to_super_seed(p->get_bitfield())); + } + } + if (is_seed()) { m_peer_info->seed = true; diff --git a/test/test_swarm.cpp b/test/test_swarm.cpp index 4a08b90f0..a6a7f323d 100644 --- a/test/test_swarm.cpp +++ b/test/test_swarm.cpp @@ -44,7 +44,7 @@ POSSIBILITY OF SUCH DAMAGE. using boost::filesystem::remove_all; using boost::filesystem::exists; -void test_swarm(bool super_seeding = false) +void test_swarm(bool super_seeding = false, bool strict = false) { using namespace libtorrent; @@ -74,6 +74,7 @@ void test_swarm(bool super_seeding = false) session_settings settings; settings.allow_multiple_connections_per_ip = true; settings.ignore_limits_on_local_network = false; + settings.strict_super_seeding = strict; ses1.set_settings(settings); ses2.set_settings(settings); ses3.set_settings(settings); @@ -205,6 +206,9 @@ int test_main() // with super seeding test_swarm(true); + // with strict super seeding + test_swarm(true, true); + return 0; }