MCPcopy Create free account
hub / github.com/ElementsProject/elements / addnode

Function addnode

src/rpc/net.cpp:269–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269static RPCHelpMan addnode()
270{
271 return RPCHelpMan{"addnode",
272 "\nAttempts to add or remove a node from the addnode list.\n"
273 "Or try a connection to a node once.\n"
274 "Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n"
275 "full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n" +
276 strprintf("Addnode connections are limited to %u at a time", MAX_ADDNODE_CONNECTIONS) +
277 " and are counted separately from the -maxconnections limit.\n",
278 {
279 {"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The node (see getpeerinfo for nodes)"},
280 {"command", RPCArg::Type::STR, RPCArg::Optional::NO, "'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"},
281 },
282 RPCResult{RPCResult::Type::NONE, "", ""},
283 RPCExamples{
284 HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"")
285 + HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")
286 },
287 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
288{
289 std::string strCommand;
290 if (!request.params[1].isNull())
291 strCommand = request.params[1].get_str();
292 if (strCommand != "onetry" && strCommand != "add" && strCommand != "remove") {
293 throw std::runtime_error(
294 self.ToString());
295 }
296
297 NodeContext& node = EnsureAnyNodeContext(request.context);
298 CConnman& connman = EnsureConnman(node);
299
300 std::string strNode = request.params[0].get_str();
301
302 if (strCommand == "onetry")
303 {
304 CAddress addr;
305 connman.OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), ConnectionType::MANUAL);
306 return NullUniValue;
307 }
308
309 if (strCommand == "add")
310 {
311 if (!connman.AddNode(strNode)) {
312 throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
313 }
314 }
315 else if(strCommand == "remove")
316 {
317 if (!connman.RemoveAddedNode(strNode)) {
318 throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node could not be removed. It has not been added previously.");
319 }
320 }
321
322 return NullUniValue;
323},
324 };
325}
326

Callers

nothing calls this directly

Calls 8

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
OpenNetworkConnectionMethod · 0.80
AddNodeMethod · 0.80
RemoveAddedNodeMethod · 0.80
isNullMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected