MCPcopy Create free account
hub / github.com/LUX-Core/lux / addnode

Function addnode

src/rpcnet.cpp:175–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175UniValue addnode(const UniValue& params, bool fHelp)
176{
177 string strCommand;
178 if (params.size() == 2)
179 strCommand = params[1].get_str();
180 if (fHelp || params.size() != 2 ||
181 (strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
182 throw runtime_error(
183 "addnode \"node\" \"add|remove|onetry\"\n"
184 "\nAttempts add or remove a node from the addnode list.\n"
185 "Or try a connection to a node once.\n"
186 "\nArguments:\n"
187 "1. \"node\" (string, required) The node (see getpeerinfo for nodes)\n"
188 "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"
189 "\nExamples:\n" +
190 HelpExampleCli("addnode", "\"192.168.0.6:51472\" \"onetry\"") + HelpExampleRpc("addnode", "\"192.168.0.6:51472\", \"onetry\""));
191
192 string strNode = params[0].get_str();
193
194 if (strCommand == "onetry") {
195 CAddress addr;
196 OpenNetworkConnection(addr, false, NULL, strNode.c_str());
197 return NullUniValue;
198 }
199
200 LOCK(cs_vAddedNodes);
201 vector<string>::iterator it = vAddedNodes.begin();
202 for (; it != vAddedNodes.end(); it++)
203 if (strNode == *it)
204 break;
205
206 if (strCommand == "add") {
207 if (it != vAddedNodes.end())
208 throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
209 vAddedNodes.push_back(strNode);
210 } else if (strCommand == "remove") {
211 if (it == vAddedNodes.end())
212 throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
213 vAddedNodes.erase(it);
214 }
215
216 return NullUniValue;
217}
218
219UniValue disconnectnode(const UniValue& params, bool fHelp)
220{

Callers

nothing calls this directly

Calls 10

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
OpenNetworkConnectionFunction · 0.85
JSONRPCErrorFunction · 0.85
get_strMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
eraseMethod · 0.45

Tested by

no test coverage detected