X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Frpcnet.cpp;h=5078a7986b0d20ff9da7ca3b2b8ae8830a7e2ece;hb=5e16a8b47dcc39875b55e578ba1c4dd929fa1332;hp=f2fb213b3401d8638f972e61fb68f9e2d03d8c9b;hpb=a01b68db4ffd37a770b42fdd50080f5ce1b15732;p=novacoin.git diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index f2fb213..5078a79 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -2,12 +2,12 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "net.h" #include "bitcoinrpc.h" #include "alert.h" #include "wallet.h" #include "db.h" #include "walletdb.h" +#include "net.h" using namespace json_spirit; using namespace std; @@ -52,7 +52,7 @@ Value getpeerinfo(const Array& params, bool fHelp) Object obj; obj.push_back(Pair("addr", stats.addrName)); - obj.push_back(Pair("services", strprintf("%08"PRI64x, stats.nServices))); + obj.push_back(Pair("services", strprintf("%08" PRIx64, stats.nServices))); obj.push_back(Pair("lastsend", (boost::int64_t)stats.nLastSend)); obj.push_back(Pair("lastrecv", (boost::int64_t)stats.nLastRecv)); obj.push_back(Pair("bytessent", (boost::int64_t)stats.nSendBytes)); @@ -72,6 +72,49 @@ Value getpeerinfo(const Array& params, bool fHelp) return ret; } +Value addnode(const Array& params, bool fHelp) +{ + string strCommand; + if (params.size() == 2) + strCommand = params[1].get_str(); + if (fHelp || params.size() != 2 || + (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) + throw runtime_error( + "addnode \n" + "Attempts add or remove from the addnode list or try a connection to once."); + + string strNode = params[0].get_str(); + + if (strCommand == "onetry") + { + CAddress addr; + ConnectNode(addr, strNode.c_str()); + return Value::null; + } + + LOCK(cs_vAddedNodes); + vector::iterator it = vAddedNodes.begin(); + for(; it != vAddedNodes.end(); it++) + if (strNode == *it) + break; + + if (strCommand == "add") + { + if (it != vAddedNodes.end()) + throw JSONRPCError(-23, "Error: Node already added"); + vAddedNodes.push_back(strNode); + } + else if(strCommand == "remove") + { + if (it == vAddedNodes.end()) + throw JSONRPCError(-24, "Error: Node has not been added."); + vAddedNodes.erase(it); + } + + return Value::null; +} + + extern CCriticalSection cs_mapAlerts; extern map mapAlerts;