From 13ca78e92bb5b8b2516becef3d1e64444130da63 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 16 May 2007 04:12:13 +0000 Subject: [PATCH] #47. introduced parole mode for peers that fails the hash check. --- include/libtorrent/peer_connection.hpp | 11 +++++++++++ src/peer_connection.cpp | 6 ++++++ src/policy.cpp | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/libtorrent/peer_connection.hpp b/include/libtorrent/peer_connection.hpp index cbe8c1478..954c5b8c1 100755 --- a/include/libtorrent/peer_connection.hpp +++ b/include/libtorrent/peer_connection.hpp @@ -174,6 +174,9 @@ namespace libtorrent void set_non_prioritized(bool b) { m_non_prioritized = b; } + bool on_parole() const + { return m_on_parole; } + // this adds an announcement in the announcement queue // it will let the peer know that we have the given piece void announce_piece(int index); @@ -633,6 +636,14 @@ namespace libtorrent // are preferred. bool m_prefer_whole_pieces; + // if this is true, the peer has previously participated + // in a piece that failed the piece hash check. This will + // put the peer on parole and only request entire pieces. + // if a piece pass that was partially requested from this + // peer it will leave parole mode and continue download + // pieces as normal peers. + bool m_on_parole; + // if this is true, the blocks picked by the piece // picker will be merged before passed to the // request function. i.e. subsequent blocks are diff --git a/src/peer_connection.cpp b/src/peer_connection.cpp index 450d2c0dd..96f9d54b3 100755 --- a/src/peer_connection.cpp +++ b/src/peer_connection.cpp @@ -119,6 +119,7 @@ namespace libtorrent , m_writing(false) , m_reading(false) , m_prefer_whole_pieces(false) + , m_on_parole(false) , m_request_large_blocks(false) , m_non_prioritized(false) , m_refs(0) @@ -189,6 +190,7 @@ namespace libtorrent , m_writing(false) , m_reading(false) , m_prefer_whole_pieces(false) + , m_on_parole(false) , m_request_large_blocks(false) , m_non_prioritized(false) , m_refs(0) @@ -401,6 +403,8 @@ namespace libtorrent } #endif + m_on_parole = false; + m_trust_points++; // TODO: make this limit user settable if (m_trust_points > 20) m_trust_points = 20; @@ -418,6 +422,8 @@ namespace libtorrent } #endif + m_on_parole = true; + // we decrease more than we increase, to keep the // allowed failed/passed ratio low. // TODO: make this limit user settable diff --git a/src/policy.cpp b/src/policy.cpp index 0973e3746..7f0e9f7a4 100755 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -186,7 +186,9 @@ namespace libtorrent std::vector interesting_pieces; interesting_pieces.reserve(100); - bool prefer_whole_pieces = c.prefer_whole_pieces(); + bool prefer_whole_pieces = c.prefer_whole_pieces() + || c.on_parole(); + if (!prefer_whole_pieces) { prefer_whole_pieces = c.statistics().download_payload_rate()