add build option to disable predictive pieces feature

This commit is contained in:
arvidn 2020-03-17 22:15:33 +01:00 committed by Arvid Norberg
parent 903ead89b1
commit 0d06d47a29
6 changed files with 36 additions and 0 deletions

View File

@ -435,6 +435,9 @@ feature.compose <sanitize>rtc : <cflags>/RTCc <cflags>/RTCsu ;
feature test-coverage : off on : composite propagated link-incompatible ;
feature.compose <test-coverage>on : <cflags>--coverage <linkflags>--coverage ;
feature predictive-pieces : on off : composite propagated ;
feature.compose <predictive-pieces>off : <define>TORRENT_DISABLE_PREDICTIVE_PIECES ;
feature streaming : on off : composite propagated ;
feature.compose <streaming>off : <define>TORRENT_DISABLE_STREAMING ;

View File

@ -380,6 +380,15 @@ Build features:
| | protocol. |
| | * ``off`` - disable bittorrent extensions. |
+--------------------------+----------------------------------------------------+
| ``streaming`` | * ``on`` - enable streaming functionality. i.e. |
| | ``set_piece_deadline()``. |
| | * ``off`` - disable streaming functionality. |
+--------------------------+----------------------------------------------------+
| ``predictive-pieces`` | * ``on`` - enable predictive piece announce |
| | feature. i.e. |
| | settings_pack::predictive_piece_announce |
| | * ``off`` - disable feature. |
+--------------------------+----------------------------------------------------+
| ``fpic`` | * ``off`` - default. Build without specifying |
| | ``-fPIC``. |
| | * ``on`` - Force build with ``-fPIC`` (useful for |
@ -533,6 +542,10 @@ defines you can use to control the build.
| ``TORRENT_DISABLE_STREAMING`` | Disables set_piece_deadline() and associated |
| | functionality. |
+----------------------------------------+-------------------------------------------------+
| ``TORRENT_DISABLE_PREDICTIVE_PIECES`` | Disables |
| | settings_pack::predictive_piece_announce |
| | feature. |
+----------------------------------------+-------------------------------------------------+
| ``TORRENT_LINKING_SHARED`` | If this is defined when including the |
| | libtorrent headers, the classes and functions |
| | will be tagged with ``__declspec(dllimport)`` |

View File

@ -814,6 +814,7 @@ namespace libtorrent {
return m_picker->has_piece_passed(index);
}
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
// a predictive piece is a piece that we might
// not have yet, but still announced to peers, anticipating that
// we'll have it very soon
@ -821,6 +822,7 @@ namespace libtorrent {
{
return std::binary_search(m_predictive_pieces.begin(), m_predictive_pieces.end(), index);
}
#endif // TORRENT_DISABLE_PREDICTIVE_PIECES
private:
@ -1116,12 +1118,14 @@ namespace libtorrent {
void set_apply_ip_filter(bool b);
bool apply_ip_filter() const { return m_apply_ip_filter; }
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
std::vector<piece_index_t> const& predictive_pieces() const
{ return m_predictive_pieces; }
// this is called whenever we predict to have this piece
// within one second
void predicted_have_piece(piece_index_t index, int milliseconds);
#endif
void clear_in_state_update()
{
@ -1336,6 +1340,7 @@ namespace libtorrent {
std::string m_source_feed_url;
#endif
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
// this is a list of all pieces that we have announced
// as having, without actually having yet. If we receive
// a request for a piece in this list, we need to hold off
@ -1347,6 +1352,7 @@ namespace libtorrent {
// TODO: 3 factor out predictive pieces and all operations on it into a
// separate class (to use as memeber here instead)
std::vector<piece_index_t> m_predictive_pieces;
#endif
// the performance counters of this session
counters& m_stats_counters;

View File

@ -2045,10 +2045,12 @@ namespace {
}
}
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
// add predictive pieces to the bitfield as well, since we won't
// announce them again
for (piece_index_t const p : t->predictive_pieces())
msg[5 + static_cast<int>(p) / CHAR_BIT] |= (char_top_bit >> (static_cast<int>(p) & char_bit_mask));
#endif
#ifndef TORRENT_DISABLE_LOGGING
if (should_log(peer_log_alert::outgoing_message))

View File

@ -2430,7 +2430,9 @@ namespace libtorrent {
if (r.piece < piece_index_t(0)
|| r.piece >= t->torrent_file().end_piece()
|| (!t->has_piece_passed(r.piece)
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
&& !t->is_predictive_piece(r.piece)
#endif
&& !t->seed_mode())
|| r.start < 0
|| r.start >= ti.piece_size(r.piece)
@ -2959,6 +2961,7 @@ namespace libtorrent {
// if we requested this block from other peers, cancel it now
if (multi) t->cancel_block(block_finished);
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
if (m_settings.get_int(settings_pack::predictive_piece_announce))
{
piece_index_t const piece = block_finished.piece_index;
@ -2994,6 +2997,7 @@ namespace libtorrent {
}
}
}
#endif // TORRENT_DISABLE_PREDICTIVE_PIECES
TORRENT_ASSERT(picker.num_peers(block_finished) == 0);
@ -5208,11 +5212,13 @@ namespace libtorrent {
if (!t->has_piece_passed(r.piece) && !seed_mode)
{
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
// we don't have this piece yet, but we anticipate to have
// it very soon, so we have told our peers we have it.
// hold off on sending it. If the piece fails later
// we will reject this request
if (t->is_predictive_piece(r.piece)) continue;
#endif
#ifndef TORRENT_DISABLE_LOGGING
peer_log(peer_log_alert::outgoing_message, "REJECT_PIECE"
, "piece: %d s: %x l: %x piece not passed hash check"

View File

@ -3862,6 +3862,7 @@ bool is_downloading_state(int const st)
// (unless it has already been announced through predictive_piece_announce
// feature).
bool announce_piece = true;
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
auto const it = std::lower_bound(m_predictive_pieces.begin()
, m_predictive_pieces.end(), index);
if (it != m_predictive_pieces.end() && *it == index)
@ -3870,6 +3871,7 @@ bool is_downloading_state(int const st)
announce_piece = false;
m_predictive_pieces.erase(it);
}
#endif
// make a copy of the peer list since peers
// may disconnect while looping
@ -4043,6 +4045,7 @@ bool is_downloading_state(int const st)
we_have(index);
}
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
// we believe we will complete this piece very soon
// announce it to peers ahead of time to eliminate the
// round-trip times involved in announcing it, requesting it
@ -4068,6 +4071,7 @@ bool is_downloading_state(int const st)
m_predictive_pieces.insert(i, index);
}
#endif
void torrent::piece_failed(piece_index_t const index)
{
@ -4085,6 +4089,7 @@ bool is_downloading_state(int const st)
inc_stats_counter(counters::num_piece_failed);
#ifndef TORRENT_DISABLE_PREDICTIVE_PIECES
auto const it = std::lower_bound(m_predictive_pieces.begin()
, m_predictive_pieces.end(), index);
if (it != m_predictive_pieces.end() && *it == index)
@ -4101,6 +4106,7 @@ bool is_downloading_state(int const st)
}
m_predictive_pieces.erase(it);
}
#endif
// increase the total amount of failed bytes
add_failed_bytes(m_torrent_file->piece_size(index));