Browse Source

newpostraw api allows encrypting/signing posts in javascript before posting to any public twisterd server.

miguelfreitas
Miguel Freitas 10 years ago
parent
commit
401c24d18a
  1. 2
      src/bitcoinrpc.cpp
  2. 1
      src/bitcoinrpc.h
  3. 31
      src/twister.cpp

2
src/bitcoinrpc.cpp

@ -249,6 +249,7 @@ static const CRPCCommand vRPCCommands[] =
{ "dhtputraw", &dhtputraw, false, true, true }, { "dhtputraw", &dhtputraw, false, true, true },
{ "dhtget", &dhtget, false, true, true }, { "dhtget", &dhtget, false, true, true },
{ "newpostmsg", &newpostmsg, false, true, false }, { "newpostmsg", &newpostmsg, false, true, false },
{ "newpostraw", &newpostraw, false, true, true },
{ "newdirectmsg", &newdirectmsg, false, true, false }, { "newdirectmsg", &newdirectmsg, false, true, false },
{ "newrtmsg", &newrtmsg, false, true, false }, { "newrtmsg", &newrtmsg, false, true, false },
{ "getposts", &getposts, false, true, false }, { "getposts", &getposts, false, true, false },
@ -1304,6 +1305,7 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
if (strMethod == "dhtget" && n > 5) ConvertTo<boost::int64_t>(params[5]); if (strMethod == "dhtget" && n > 5) ConvertTo<boost::int64_t>(params[5]);
if (strMethod == "newpostmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "newpostmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "newpostmsg" && n > 4) ConvertTo<boost::int64_t>(params[4]); if (strMethod == "newpostmsg" && n > 4) ConvertTo<boost::int64_t>(params[4]);
if (strMethod == "newpostraw" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "newdirectmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "newdirectmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
if (strMethod == "newdirectmsg" && n > 4) ConvertTo<bool>(params[4]); if (strMethod == "newdirectmsg" && n > 4) ConvertTo<bool>(params[4]);
if (strMethod == "newrtmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]); if (strMethod == "newrtmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);

1
src/bitcoinrpc.h

@ -202,6 +202,7 @@ extern json_spirit::Value dhtput(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dhtputraw(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dhtputraw(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value dhtget(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value dhtget(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value newpostmsg(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value newpostraw(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value newrtmsg(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value newrtmsg(const json_spirit::Array& params, bool fHelp);
extern json_spirit::Value getposts(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value getposts(const json_spirit::Array& params, bool fHelp);

31
src/twister.cpp

@ -1677,7 +1677,7 @@ Value dhtputraw(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() != 1) if (fHelp || params.size() != 1)
throw runtime_error( throw runtime_error(
"dhtput <hexdata>\n" "dhtputraw <hexdata>\n"
"Store resource in dht network"); "Store resource in dht network");
string hexdata = params[0].get_str(); string hexdata = params[0].get_str();
@ -1947,6 +1947,33 @@ Value newpostmsg(const Array& params, bool fHelp)
return entryToJson(v); return entryToJson(v);
} }
Value newpostraw(const Array& params, bool fHelp)
{
if (fHelp || params.size() != 3)
throw runtime_error(
"newpostraw <username> <k> <hexdata>\n"
"Post a new raw post (already signed) to swarm");
string strUsername = params[0].get_str();
int k = params[1].get_int();
string hexdata = params[2].get_str();
vector<unsigned char> buf = ParseHex(hexdata);
std::string errmsg;
if( !acceptSignedPost((const char *)buf.data(),buf.size(),strUsername,k,errmsg,NULL) )
throw JSONRPCError(RPC_INVALID_PARAMS,errmsg);
torrent_handle h = getTorrentUser(strUsername);
if( h.is_valid() ) {
// if member of torrent post it directly
h.add_piece(k,(const char *)buf.data(),buf.size());
} else {
throw JSONRPCError(RPC_INTERNAL_ERROR,"swarm resource forwarding not implemented");
}
return Value();
}
Value newdirectmsg(const Array& params, bool fHelp) Value newdirectmsg(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 4 || params.size() > 5 ) if (fHelp || params.size() < 4 || params.size() > 5 )
@ -2107,7 +2134,7 @@ Value getposts(const Array& params, bool fHelp)
{ {
if (fHelp || params.size() < 2 || params.size() > 4) if (fHelp || params.size() < 2 || params.size() > 4)
throw runtime_error( throw runtime_error(
"getposts <count> '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [allowed_flags] [required_flags]\n" "getposts <count> '[{\"username\":username,\"max_id\":max_id,\"since_id\":since_id},...]' [allowed_flags=~2] [required_flags=0]\n"
"get posts from users\n" "get posts from users\n"
"max_id and since_id may be omited\n" "max_id and since_id may be omited\n"
"(optional) allowed/required flags are bitwise fields (1=RT,2=DM)"); "(optional) allowed/required flags are bitwise fields (1=RT,2=DM)");

Loading…
Cancel
Save