diff options
| author | Matt Corallo <[email protected]> | 2013-01-23 11:45:00 -0500 |
|---|---|---|
| committer | Matt Corallo <[email protected]> | 2013-01-27 03:03:04 -0500 |
| commit | 72a348fd9a7015aa039f9cbdc9166f388f4725e0 (patch) | |
| tree | ac3b1167ed8737ec0709600834a6379571abbcf2 /src/rpcnet.cpp | |
| parent | Make ThreadOpenAddedConnections2 exit quicker if(GetNameProxy()). (diff) | |
| download | discoin-72a348fd9a7015aa039f9cbdc9166f388f4725e0.tar.xz discoin-72a348fd9a7015aa039f9cbdc9166f388f4725e0.zip | |
Add addnode RPC command.
Diffstat (limited to 'src/rpcnet.cpp')
| -rw-r--r-- | src/rpcnet.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/rpcnet.cpp b/src/rpcnet.cpp index 491297eb1..f3b41e5be 100644 --- a/src/rpcnet.cpp +++ b/src/rpcnet.cpp @@ -65,3 +65,45 @@ 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 <node> <add|remove|onetry>\n" + "Attempts add or remove <node> from the addnode list or try a connection to <node> once."); + + string strNode = params[0].get_str(); + + if (strCommand == "onetry") + { + CAddress addr; + ConnectNode(addr, strNode.c_str()); + return Value::null; + } + + LOCK(cs_vAddedNodes); + vector<string>::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; +} + |