diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f329339f..64f4aff7b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -599,6 +599,8 @@ target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME loggin DESCRIPTION "build with logging" DISABLED TORRENT_DISABLE_LOGGING) target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME mutable-torrents DEFAULT ON DESCRIPTION "Enables mutable torrent support" DISABLED TORRENT_DISABLE_MUTABLE_TORRENTS) +target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME streaming DEFAULT ON + DESCRIPTION "Enables support for piece deadline" DISABLED TORRENT_DISABLE_STREAMING) find_public_dependency(Iconv) if(MSVC) diff --git a/ChangeLog b/ChangeLog index d7d6b3d64..42df19e42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,5 @@ + * add build option to disable streaming + 1.2.5 release * announce port=1 instead of port=0, when there is no listen port diff --git a/Jamfile b/Jamfile index ac9ee96f7..bea1ee2d5 100644 --- a/Jamfile +++ b/Jamfile @@ -435,6 +435,9 @@ feature.compose rtc : /RTCc /RTCsu ; feature test-coverage : off on : composite propagated link-incompatible ; feature.compose on : --coverage --coverage ; +feature streaming : on off : composite propagated ; +feature.compose off : TORRENT_DISABLE_STREAMING ; + feature i2p : on off : composite propagated ; feature.compose on : TORRENT_USE_I2P=1 ; feature.compose off : TORRENT_USE_I2P=0 ; diff --git a/docs/building.rst b/docs/building.rst index a7dc6b685..a24f1ff96 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -530,6 +530,9 @@ defines you can use to control the build. +----------------------------------------+-------------------------------------------------+ | ``TORRENT_DISABLE_MUTABLE_TORRENTS`` | Disables mutable torrent support (`BEP 38`_) | +----------------------------------------+-------------------------------------------------+ +| ``TORRENT_DISABLE_STREAMING`` | Disables set_piece_deadline() and associated | +| | functionality. | ++----------------------------------------+-------------------------------------------------+ | ``TORRENT_LINKING_SHARED`` | If this is defined when including the | | | libtorrent headers, the classes and functions | | | will be tagged with ``__declspec(dllimport)`` | diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 794454878..7162cc20a 100644 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -115,6 +115,7 @@ namespace libtorrent { TORRENT_EXTRA_EXPORT std::int64_t calc_bytes(file_storage const& fs, piece_count const& pc); +#ifndef TORRENT_DISABLE_STREAMING struct time_critical_piece { // when this piece was first requested @@ -137,6 +138,7 @@ namespace libtorrent { bool operator<(time_critical_piece const& rhs) const { return deadline < rhs.deadline; } }; +#endif // TORRENT_DISABLE_STREAMING // this is the internal representation of web seeds struct web_seed_t : web_seed_entry @@ -579,10 +581,13 @@ namespace libtorrent { void prioritize_files(aux::vector files); void file_priorities(aux::vector*) const; +#ifndef TORRENT_DISABLE_STREAMING void cancel_non_critical(); void set_piece_deadline(piece_index_t piece, int t, deadline_flags_t flags); void reset_piece_deadline(piece_index_t piece); void clear_time_critical(); +#endif // TORRENT_DISABLE_STREAMING + void update_piece_priorities( aux::vector const& file_prios); @@ -1154,7 +1159,13 @@ namespace libtorrent { #endif int num_time_critical_pieces() const - { return int(m_time_critical_pieces.size()); } + { +#ifndef TORRENT_DISABLE_STREAMING + return int(m_time_critical_pieces.size()); +#else + return 0; +#endif + } int get_suggest_pieces(std::vector& p , typed_bitfield const& bits @@ -1219,9 +1230,11 @@ namespace libtorrent { bool should_announce_dht() const; #endif +#ifndef TORRENT_DISABLE_STREAMING void remove_time_critical_piece(piece_index_t piece, bool finished = false); void remove_time_critical_pieces(aux::vector const& priority); void request_time_critical_pieces(); +#endif // TORRENT_DISABLE_STREAMING void need_peer_list(); @@ -1293,8 +1306,10 @@ namespace libtorrent { aux::vector m_trackers; +#ifndef TORRENT_DISABLE_STREAMING // this list is sorted by time_critical_piece::deadline std::vector m_time_critical_pieces; +#endif std::string m_trackerid; #if TORRENT_ABI_VERSION == 1 diff --git a/src/torrent.cpp b/src/torrent.cpp index 7fc205e24..b33b58f73 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -3933,7 +3933,9 @@ bool is_downloading_state(int const st) } }); +#ifndef TORRENT_DISABLE_STREAMING remove_time_critical_piece(index, true); +#endif if (is_downloading_state(m_state)) { @@ -3982,7 +3984,9 @@ bool is_downloading_state(int const st) inc_stats_counter(counters::num_piece_passed); +#ifndef TORRENT_DISABLE_STREAMING remove_time_critical_piece(index, true); +#endif if (settings().get_int(settings_pack::suggest_mode) == settings_pack::suggest_read_cache) @@ -4607,6 +4611,7 @@ bool is_downloading_state(int const st) return detail::read_uint32(ptr); } +#ifndef TORRENT_DISABLE_STREAMING void torrent::cancel_non_critical() { std::set time_critical; @@ -4834,6 +4839,7 @@ bool is_downloading_state(int const st) ++i; } } +#endif // TORRENT_DISABLE_STREAMING void torrent::piece_availability(aux::vector& avail) const { @@ -4880,7 +4886,9 @@ bool is_downloading_state(int const st) if (filter_updated) { update_peer_interest(was_finished); +#ifndef TORRENT_DISABLE_STREAMING if (priority == dont_download) remove_time_critical_piece(index); +#endif // TORRENT_DISABLE_STREAMING } } @@ -4984,7 +4992,9 @@ bool is_downloading_state(int const st) set_need_save_resume(); update_peer_interest(was_finished); +#ifndef TORRENT_DISABLE_STREAMING remove_time_critical_pieces(pieces); +#endif } state_updated(); @@ -7831,11 +7841,13 @@ bool is_downloading_state(int const st) TORRENT_ASSERT(m_sequence_number == no_pos || m_ses.verify_queue_position(this, m_sequence_number)); +#ifndef TORRENT_DISABLE_STREAMING for (auto const& i : m_time_critical_pieces) { TORRENT_ASSERT(!is_seed()); TORRENT_ASSERT(!has_picker() || !m_picker->have_piece(i.piece)); } +#endif switch (current_stats_state()) { @@ -9137,6 +9149,7 @@ bool is_downloading_state(int const st) } } +#ifndef TORRENT_DISABLE_STREAMING // ---- TIME CRITICAL PIECES ---- #if TORRENT_DEBUG_STREAMING > 0 @@ -9166,6 +9179,7 @@ bool is_downloading_state(int const st) { request_time_critical_pieces(); } +#endif // TORRENT_DISABLE_STREAMING // ---- WEB SEEDS ---- @@ -9463,6 +9477,8 @@ bool is_downloading_state(int const st) m_ses.received_synack(ipv6); } +#ifndef TORRENT_DISABLE_STREAMING + #if TORRENT_DEBUG_STREAMING > 0 char const* esc(char const* code) { @@ -9990,6 +10006,7 @@ bool is_downloading_state(int const st) p->send_block_requests(); } } +#endif // TORRENT_DISABLE_STREAMING std::set torrent::web_seeds(web_seed_entry::type_t const type) const { diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 70d9b7ed6..e0ac275d0 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -801,17 +801,29 @@ namespace libtorrent { void torrent_handle::set_piece_deadline(piece_index_t index, int deadline , deadline_flags_t const flags) const { +#ifndef TORRENT_DISABLE_STREAMING async_call(&torrent::set_piece_deadline, index, deadline, flags); +#else + TORRENT_UNUSED(deadline); + if (flags & alert_when_available) + async_call(&torrent::read_piece, index); +#endif } void torrent_handle::reset_piece_deadline(piece_index_t index) const { +#ifndef TORRENT_DISABLE_STREAMING async_call(&torrent::reset_piece_deadline, index); +#else + TORRENT_UNUSED(index); +#endif } void torrent_handle::clear_piece_deadlines() const { +#ifndef TORRENT_DISABLE_STREAMING async_call(&torrent::clear_time_critical); +#endif } std::shared_ptr torrent_handle::native_handle() const