mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-09-13 14:52:14 +00:00
new getpieceavailability rpc
This commit is contained in:
parent
c4b0558e46
commit
4c67033b3b
@ -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
|
||||
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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…
x
Reference in New Issue
Block a user