diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index 4535d64c..e0bbfeb8 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -242,6 +242,10 @@ static const CRPCCommand vRPCCommands[] = { "newrtmsg", &newrtmsg, false, true }, { "getposts", &getposts, false, true }, { "setspammsg", &setspammsg, false, true }, + { "getspammsg", &getspammsg, false, true }, + { "follow", &follow, false, true }, + { "unfollow", &unfollow, false, true }, + { "getfollowing", &getfollowing, false, true }, }; CRPCTable::CRPCTable() @@ -1188,6 +1192,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 2) ConvertTo(params[2]); if (strMethod == "getposts" && n > 0) ConvertTo(params[0]); if (strMethod == "getposts" && n > 1) ConvertTo(params[1]); + if (strMethod == "follow" && n > 0) ConvertTo(params[0]); + if (strMethod == "unfollow" && n > 0) ConvertTo(params[0]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index e39f26e7..efe4d6fa 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -199,5 +199,9 @@ extern json_spirit::Value newdirectmsg(const json_spirit::Array& params, bool fH 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 setspammsg(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value getspammsg(const json_spirit::Array& params, bool fHelp); +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); #endif diff --git a/src/twister.cpp b/src/twister.cpp index 7e513851..1fe5fca2 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -38,6 +38,7 @@ static CCriticalSection cs_dhtgetMap; static map m_dhtgetMap; static map m_specialResources; static map m_userTorrent; +static std::set m_following; sha1_hash dhtTargetHash(std::string const &username, std::string const &resource, std::string const &type) { @@ -1153,3 +1154,81 @@ Value setspammsg(const Array& params, bool fHelp) return Value(); } + +Value getspammsg(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 0)) + throw runtime_error( + "getspammsg\n" + "get spam message attached to generated blocks"); + + Array ret; + ret.push_back(strSpamUser); + ret.push_back(strSpamMessage); + + return ret; +} + +Value follow(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 1)) + throw runtime_error( + "follow [username1,username2,...]\n" + "start following users"); + + Array users = params[0].get_array(); + + for( unsigned int u = 0; u < users.size(); u++ ) { + string username = users[u].get_str(); + + if( !m_following.count(username) ) { + if( m_userTorrent.count(username) ) { + // perhaps torrent is already initialized due to neighborhood + m_following.insert(username); + } else { + torrent_handle h = startTorrentUser(username); + if( h.is_valid() ) { + m_following.insert(username); + } + } + } + } + + return Value(); +} + +Value unfollow(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 1)) + throw runtime_error( + "unfollow [username1,username2,...]\n" + "stop following users"); + + Array users = params[0].get_array(); + + for( unsigned int u = 0; u < users.size(); u++ ) { + string username = users[u].get_str(); + + if( m_following.count(username) ) { + m_following.erase(username); + } + } + + return Value(); +} + +Value getfollowing(const Array& params, bool fHelp) +{ + if (fHelp || (params.size() != 0)) + throw runtime_error( + "getfollowing\n" + "get list of users we follow"); + + Array ret; + BOOST_FOREACH(string username, m_following) { + ret.push_back(username); + } + + return ret; +} +