diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index b17f4827..34234cc8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -255,6 +255,7 @@ static const CRPCCommand vRPCCommands[] = { "unfollow", &unfollow, false, true }, { "getfollowing", &getfollowing, false, true }, { "getlasthave", &getlasthave, false, true }, + { "getnumpieces", &getnumpieces, false, true }, { "listusernamespartial", &listusernamespartial, false, true }, { "rescandirectmsgs", &rescandirectmsgs, false, true }, }; @@ -918,7 +919,7 @@ void JSONRequest::parse(const Value& valRequest) throw JSONRPCError(RPC_INVALID_REQUEST, "Method must be a string"); strMethod = valMethod.get_str(); if (strMethod != "getwork" && strMethod != "getblocktemplate" && - strMethod != "getlasthave" && + strMethod != "getlasthave" && strMethod != "getnumpieces" && strMethod != "getinfo" && strMethod != "getbestblockhash" && strMethod != "getblock") printf("ThreadRPCServer method=%s\n", strMethod.c_str()); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index bf10b428..34147485 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -207,6 +207,7 @@ extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value unfollow(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getfollowing(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getlasthave(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getnumpieces(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value listusernamespartial(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value rescandirectmsgs(const json_spirit::Array& params, bool fHelp); diff --git a/src/twister.cpp b/src/twister.cpp index 3bc23e90..6a5339b0 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -96,7 +96,7 @@ torrent_handle startTorrentUser(std::string const &username) return m_userTorrent[username]; } -int lastPostKfromTorrent(std::string const &username) +int torrentLastHave(std::string const &username) { if( !m_userTorrent.count(username) ) return -1; @@ -105,6 +105,15 @@ int lastPostKfromTorrent(std::string const &username) return status.last_have; } +int torrentNumPieces(std::string const &username) +{ + if( !m_userTorrent.count(username) ) + return -1; + + torrent_status status = m_userTorrent[username].status(); + return status.num_pieces; +} + int saveGlobalData(std::string const& filename) { LOCK(cs_twister); @@ -1628,7 +1637,25 @@ Value getlasthave(const Array& params, bool fHelp) Object ret; LOCK(cs_twister); BOOST_FOREACH(string username, m_users[localUser].m_following) { - ret.push_back(Pair(username,lastPostKfromTorrent(username))); + ret.push_back(Pair(username,torrentLastHave(username))); + } + + return ret; +} + +Value getnumpieces(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 1)) + throw runtime_error( + "getnumpieces \n" + "get number of posts already downloaded for each user user we follow"); + + string localUser = params[0].get_str(); + + Object ret; + LOCK(cs_twister); + BOOST_FOREACH(string username, m_users[localUser].m_following) { + ret.push_back(Pair(username,torrentNumPieces(username))); } return ret;