Browse Source

getnumpieces rpc

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
f4d6c2be28
  1. 3
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 31
      src/twister.cpp

3
src/bitcoinrpc.cpp

@ -255,6 +255,7 @@ static const CRPCCommand vRPCCommands[] = @@ -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) @@ -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());

1
src/bitcoinrpc.h

@ -207,6 +207,7 @@ extern json_spirit::Value follow(const json_spirit::Array& params, bool fHelp); @@ -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);

31
src/twister.cpp

@ -96,7 +96,7 @@ torrent_handle startTorrentUser(std::string const &username) @@ -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) @@ -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) @@ -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 <username>\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;

Loading…
Cancel
Save