diff --git a/docs/manual.html b/docs/manual.html index c0be79719..11e0ed2f2 100755 --- a/docs/manual.html +++ b/docs/manual.html @@ -884,6 +884,7 @@ struct torrent_handle bool is_seed() const; void filter_piece(int index, bool filter); + void filter_pieces(std::vector<bool> const& bitmask); bool is_piece_filtered(int index) const; std::vector<bool> filtered_pieces() const; @@ -904,7 +905,7 @@ perform any operation on it, unless you first assign it a valid handle. If you t any operation on an uninitialized handle, it will throw invalid_handle.

TODO: document trackers() and replace_trackers()

TODO: document how to create a .torrent

-

TODO: document filter_piece(), is_piece_filtered() and filtered_pieces()

+

TODO: document filter_piece(), filter_pieces(), is_piece_filtered() and filtered_pieces()

save_path()

diff --git a/docs/manual.rst b/docs/manual.rst index 6dd3b7ac4..57931a930 100755 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -813,6 +813,7 @@ Its declaration looks like this:: bool is_seed() const; void filter_piece(int index, bool filter); + void filter_pieces(std::vector const& bitmask); bool is_piece_filtered(int index) const; std::vector filtered_pieces() const; @@ -836,7 +837,7 @@ any operation on an uninitialized handle, it will throw ``invalid_handle``. **TODO: document how to create a .torrent** -**TODO: document filter_piece(), is_piece_filtered() and filtered_pieces()** +**TODO: document filter_piece(), filter_pieces(), is_piece_filtered() and filtered_pieces()** save_path() ----------- diff --git a/include/libtorrent/torrent.hpp b/include/libtorrent/torrent.hpp index 6548f1823..c24c36dff 100755 --- a/include/libtorrent/torrent.hpp +++ b/include/libtorrent/torrent.hpp @@ -146,7 +146,8 @@ namespace libtorrent void resume(); bool is_paused() const { return m_paused; } - void filter_piece(int index, bool download); + void filter_piece(int index, bool filter); + void filter_pieces(std::vector const& bitmask); bool is_piece_filtered(int index) const; void filtered_pieces(std::vector& bitmask) const; diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 6599c448e..0c67cccad 100755 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -227,6 +227,7 @@ namespace libtorrent // marks the piece with the given index as filtered // it will not be downloaded void filter_piece(int index, bool filter); + void filter_pieces(std::vector const& pieces); bool is_piece_filtered(int index) const; std::vector filtered_pieces() const; diff --git a/src/identify_client.cpp b/src/identify_client.cpp index 8bd27276b..c41b9b494 100755 --- a/src/identify_client.cpp +++ b/src/identify_client.cpp @@ -100,9 +100,9 @@ namespace if (!std::isalnum(id[0])) return boost::optional(); - if (std::equal(id.begin()+4, id.begin()+8, "----")) + if (std::equal(id.begin()+4, id.begin()+6, "--")) { - if (!std::isalnum(id[1]) || (id[2] < '0') + if ((id[1] < '0') || (id[2] < '0') || (id[3] < '0')) return boost::optional(); ret.major_version = decode_digit(id[1]); diff --git a/src/piece_picker.cpp b/src/piece_picker.cpp index 7086088d6..ec8930f4d 100755 --- a/src/piece_picker.cpp +++ b/src/piece_picker.cpp @@ -572,7 +572,7 @@ namespace libtorrent // is downloading them. // partial is pieces that are partially being downloaded, and // parts of them may be free for download as well, the - // partially donloaded pieces will be prioritized + // partially downloaded pieces will be prioritized assert(m_piece_info.begin() != m_piece_info.end()); // +1 is to ignore pieces that no peer has. The bucket with index 0 contains // pieces that 0 other peers has. diff --git a/src/torrent.cpp b/src/torrent.cpp index 131d9c8ce..2e3313f27 100755 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -588,6 +588,33 @@ namespace libtorrent else m_picker->mark_as_unfiltered(index); } + void torrent::filter_pieces(std::vector const& bitmask) + { + // this call is only valid on torrents with metadata + assert(m_picker.get()); + assert(index >= 0); + assert(index < m_torrent_file.num_pieces()); + + // TODO: update peer's interesting-bit + + std::vector > state; + state.reserve(100); + int index = 0; + for (std::vector::const_iterator i = bitmask.begin() + , end(bitmask.end()); i != end; ++i, ++index) + { + if (m_picker->is_filtered(index) == *i) continue; + state.push_back(std::make_pair(index, *i)); + } + std::random_shuffle(state.begin(), state.end()); + for (std::vector >::iterator i = state.begin(); + i != state.end(); ++i) + { + if (i->second) m_picker->mark_as_filtered(i->first); + else m_picker->mark_as_unfiltered(i->first); + } + } + // TODO: add a function to set the filter with one call bool torrent::is_piece_filtered(int index) const diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 291637629..4a814a909 100755 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -263,6 +263,13 @@ namespace libtorrent , bind(&torrent::filter_piece, _1, index, filter)); } + void torrent_handle::filter_pieces(std::vector const& pieces) + { + INVARIANT_CHECK; + call_member(m_ses, m_chk, m_info_hash + , bind(&torrent::filter_pieces, _1, pieces)); + } + bool torrent_handle::is_piece_filtered(int index) const { INVARIANT_CHECK;