| 272 | } |
| 273 | |
| 274 | UniValue addnode(const UniValue& params, bool fHelp) |
| 275 | { |
| 276 | string strCommand; |
| 277 | if (params.size() == 2) |
| 278 | strCommand = params[1].get_str(); |
| 279 | if (fHelp || params.size() != 2 || |
| 280 | (strCommand != "onetry" && strCommand != "add" && strCommand != "remove")) |
| 281 | throw runtime_error( |
| 282 | "addnode \"node\" \"add|remove|onetry\"\n" |
| 283 | "\nAttempts add or remove a node from the addnode list.\n" |
| 284 | "Or try a connection to a node once.\n" |
| 285 | "\nArguments:\n" |
| 286 | "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n" |
| 287 | "2. \"command\" (string, required) 'add' to add a node to the list, 'remove' to remove a node from the list, 'onetry' to try a connection to the node once\n" |
| 288 | "\nExamples:\n" |
| 289 | + HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"") |
| 290 | + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"") |
| 291 | ); |
| 292 | |
| 293 | string strNode = params[0].get_str(); |
| 294 | |
| 295 | if (strCommand == "onetry") |
| 296 | { |
| 297 | CAddress addr; |
| 298 | OpenNetworkConnection(addr, false, NULL, strNode.c_str()); |
| 299 | return NullUniValue; |
| 300 | } |
| 301 | |
| 302 | LOCK(cs_vAddedNodes); |
| 303 | vector<string>::iterator it = vAddedNodes.begin(); |
| 304 | for(; it != vAddedNodes.end(); it++) |
| 305 | if (strNode == *it) |
| 306 | break; |
| 307 | |
| 308 | if (strCommand == "add") |
| 309 | { |
| 310 | if (it != vAddedNodes.end()) |
| 311 | throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added"); |
| 312 | vAddedNodes.push_back(strNode); |
| 313 | } |
| 314 | else if(strCommand == "remove") |
| 315 | { |
| 316 | if (it == vAddedNodes.end()) |
| 317 | throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added."); |
| 318 | vAddedNodes.erase(it); |
| 319 | } |
| 320 | |
| 321 | return NullUniValue; |
| 322 | } |
| 323 | |
| 324 | UniValue getaddednodeinfo(const UniValue& params, bool fHelp) |
| 325 | { |
nothing calls this directly
no test coverage detected