diff --git a/libtorrent/include/libtorrent/torrent.hpp b/libtorrent/include/libtorrent/torrent.hpp index c754a738..195354c9 100644 --- a/libtorrent/include/libtorrent/torrent.hpp +++ b/libtorrent/include/libtorrent/torrent.hpp @@ -200,7 +200,7 @@ namespace libtorrent void read_piece(int piece); void on_disk_read_complete(int ret, disk_io_job const& j, peer_request r, read_piece_struct* rp); - void get_pieces(std::vector *pieces, int count, int max_id, int since_id, uint32_t filter_flags, + void get_pieces(std::vector *pieces, int count, int max_id, int since_id, std::pair flags, mutex *mut, condition_variable *cond, int *reqs); void on_disk_read_get_piece_complete(int ret, disk_io_job const& j, std::vector *pieces, mutex *mut, condition_variable *cond, int *reqs); diff --git a/libtorrent/include/libtorrent/torrent_handle.hpp b/libtorrent/include/libtorrent/torrent_handle.hpp index 5471ef6c..fd236057 100644 --- a/libtorrent/include/libtorrent/torrent_handle.hpp +++ b/libtorrent/include/libtorrent/torrent_handle.hpp @@ -168,7 +168,7 @@ namespace libtorrent enum flags_t { overwrite_existing = 1 }; void add_piece(int piece, char const* data, int size, int flags = 0) const; void read_piece(int piece) const; - void get_pieces(std::vector &pieces, int count, int max_id, int since_id, uint32_t filter_flags) const; + void get_pieces(std::vector &pieces, int count, int max_id, int since_id, uint32_t allowed_flags, uint32_t required_flags) const; bool have_piece(int piece) const; void recheck_pieces(uint32_t piece_flags) const; diff --git a/libtorrent/src/torrent.cpp b/libtorrent/src/torrent.cpp index ca62c642..d8819ef4 100644 --- a/libtorrent/src/torrent.cpp +++ b/libtorrent/src/torrent.cpp @@ -916,9 +916,11 @@ namespace libtorrent } } - void torrent::get_pieces(std::vector *pieces, int count, int max_id, int since_id, uint32_t filter_flags, + void torrent::get_pieces(std::vector *pieces, int count, int max_id, int since_id, std::pair flags, mutex *mut, condition_variable *cond, int *reqs) { + uint32_t allowed_flags = flags.first; + uint32_t required_flags = flags.second; if( !m_picker ) return; max_id = std::min( max_id, m_picker->last_have() ); @@ -927,7 +929,8 @@ namespace libtorrent for( int i = max_id; i >= 0 && i > since_id && (*reqs) < count; i--) { if( m_picker->have_piece(i) && - (m_picker->post_flags(i) & filter_flags) == m_picker->post_flags(i) ) { + (m_picker->post_flags(i) & allowed_flags) == m_picker->post_flags(i) && + (m_picker->post_flags(i) & required_flags) == required_flags ) { (*reqs)++; peer_request r; diff --git a/libtorrent/src/torrent_handle.cpp b/libtorrent/src/torrent_handle.cpp index 99fa84b1..c1c098ff 100644 --- a/libtorrent/src/torrent_handle.cpp +++ b/libtorrent/src/torrent_handle.cpp @@ -823,7 +823,7 @@ namespace libtorrent TORRENT_ASYNC_CALL1(read_piece, piece); } - void torrent_handle::get_pieces(std::vector &pieces, int count, int max_id, int since_id, uint32_t filter_flags) const + void torrent_handle::get_pieces(std::vector &pieces, int count, int max_id, int since_id, uint32_t allowed_flags, uint32_t required_flags) const { INVARIANT_CHECK; @@ -831,7 +831,7 @@ namespace libtorrent libtorrent::condition_variable cond; int reqs = 0; - TORRENT_SYNC_CALL8(get_pieces, &pieces, count, max_id, since_id, filter_flags, &mut, &cond, &reqs); + TORRENT_SYNC_CALL8(get_pieces, &pieces, count, max_id, since_id, std::make_pair(allowed_flags,required_flags), &mut, &cond, &reqs); mutex::scoped_lock l2(mut); while( reqs > 0 ) { diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 9e267aee..73a704e8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -1311,6 +1311,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "getposts" && n > 1) ConvertTo(params[1]); if (strMethod == "getposts" && n > 2) ConvertTo(params[2]); + if (strMethod == "getposts" && n > 3) ConvertTo(params[3]); if (strMethod == "getdirectmsgs" && n > 1) ConvertTo(params[1]); if (strMethod == "getdirectmsgs" && n > 2) ConvertTo(params[2]); if (strMethod == "getmentions" && n > 1) ConvertTo(params[1]); diff --git a/src/twister.cpp b/src/twister.cpp index a0ca31ef..890c0029 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1831,7 +1831,7 @@ int findLastPublicPostLocalUser( std::string strUsername ) std::vector pieces; int max_id = std::numeric_limits::max(); int since_id = -1; - h.get_pieces(pieces, 1, max_id, since_id, ~USERPOST_FLAG_DM); + h.get_pieces(pieces, 1, max_id, since_id, ~USERPOST_FLAG_DM, 0); if( pieces.size() ) { string const& piece = pieces.front(); @@ -2105,15 +2105,17 @@ Value newrtmsg(const Array& params, bool fHelp) Value getposts(const Array& params, bool fHelp) { - if (fHelp || params.size() < 2 || params.size() > 3) + if (fHelp || params.size() < 2 || params.size() > 4) throw runtime_error( - "getposts '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [flags]\n" + "getposts '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [allowed_flags] [required_flags]\n" "get posts from users\n" - "max_id and since_id may be omited"); + "max_id and since_id may be omited\n" + "(optional) allowed/required flags are bitwise fields (1=RT,2=DM)"); int count = params[0].get_int(); Array users = params[1].get_array(); - int flags = (params.size() > 2) ? params[2].get_int() : ~USERPOST_FLAG_DM; + int allowed_flags = (params.size() > 2) ? params[2].get_int() : ~USERPOST_FLAG_DM; + int required_flags = (params.size() > 3) ? params[3].get_int() : 0; std::multimap postsByTime; @@ -2132,7 +2134,7 @@ Value getposts(const Array& params, bool fHelp) torrent_handle h = getTorrentUser(strUsername); if( h.is_valid() ){ std::vector pieces; - h.get_pieces(pieces, count, max_id, since_id, flags); + h.get_pieces(pieces, count, max_id, since_id, allowed_flags, required_flags); BOOST_FOREACH(string const& piece, pieces) { lazy_entry v; @@ -2900,7 +2902,7 @@ Value search(const Array& params, bool fHelp) BOOST_FOREACH(const PAIRTYPE(std::string,torrent_handle)& item, users) { std::vector pieces; - item.second.get_pieces(pieces, std::numeric_limits::max(), std::numeric_limits::max(), -1, ~USERPOST_FLAG_DM); + item.second.get_pieces(pieces, std::numeric_limits::max(), std::numeric_limits::max(), -1, ~USERPOST_FLAG_DM, 0); BOOST_FOREACH(string const& piece, pieces) { lazy_entry const* p = searcher.matchRawMessage(piece, v);