Browse Source

new getpieceavailability rpc

miguelfreitas
Miguel Freitas 10 years ago
parent
commit
4c67033b3b
  1. 2
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 18
      src/twister.cpp

2
src/bitcoinrpc.cpp

@ -279,6 +279,7 @@ static const CRPCCommand vRPCCommands[] = @@ -279,6 +279,7 @@ static const CRPCCommand vRPCCommands[] =
{ "newgroupinvite", &newgroupinvite, false, true, false },
{ "newgroupdescription", &newgroupdescription, false, true, false },
{ "leavegroup", &leavegroup, false, true, false },
{ "getpieceavailability", &getpieceavailability, false, true, true },
};
CRPCTable::CRPCTable()
@ -1344,6 +1345,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri @@ -1344,6 +1345,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "newgroupinvite" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "newgroupinvite" && n > 3) ConvertTo<Array>(params[3]);
if (strMethod == "newgroupdescription" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "getpieceavailability" && n > 1) ConvertTo<boost::int64_t>(params[1]);
return params;
}

1
src/bitcoinrpc.h

@ -232,5 +232,6 @@ extern json_spirit::Value getgroupinfo(const json_spirit::Array& params, bool fH @@ -232,5 +232,6 @@ extern json_spirit::Value getgroupinfo(const json_spirit::Array& params, bool fH
extern json_spirit::Value newgroupinvite(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value newgroupdescription(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value leavegroup(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getpieceavailability(const json_spirit::Array& params, bool fHelp);
#endif

18
src/twister.cpp

@ -3806,3 +3806,21 @@ Value leavegroup(const Array& params, bool fHelp) @@ -3806,3 +3806,21 @@ Value leavegroup(const Array& params, bool fHelp)
}
Value getpieceavailability(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 2 )
throw runtime_error(
"getpieceavailability <username> <k>'\n"
"Get piece availability (peer count for this piece)");
EnsureWalletIsUnlocked();
string strUsername = params[0].get_str();
int k = params[1].get_int();
torrent_handle h = getTorrentUser(strUsername);
std::vector<int> avail;
h.piece_availability(avail);
return avail.size() > k ? avail.at(k) : 0;
}

Loading…
Cancel
Save