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

Function addconnection

src/rpc/net.cpp:327–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327static RPCHelpMan addconnection()
328{
329 return RPCHelpMan{"addconnection",
330 "\nOpen an outbound connection to a specified node. This RPC is for testing only.\n",
331 {
332 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
333 {"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
334 },
335 RPCResult{
336 RPCResult::Type::OBJ, "", "",
337 {
338 { RPCResult::Type::STR, "address", "Address of newly added connection." },
339 { RPCResult::Type::STR, "connection_type", "Type of connection opened." },
340 }},
341 RPCExamples{
342 HelpExampleCli("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\"")
343 + HelpExampleRpc("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\"")
344 },
345 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
346{
347 if (Params().NetworkIDString().find("regtest") == std::string::npos) {
348 throw std::runtime_error("addconnection is for regression testing (chain should have \"regtest\" in the name) only.");
349 }
350
351 RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VSTR});
352 const std::string address = request.params[0].get_str();
353 const std::string conn_type_in{TrimString(request.params[1].get_str())};
354 ConnectionType conn_type{};
355 if (conn_type_in == "outbound-full-relay") {
356 conn_type = ConnectionType::OUTBOUND_FULL_RELAY;
357 } else if (conn_type_in == "block-relay-only") {
358 conn_type = ConnectionType::BLOCK_RELAY;
359 } else if (conn_type_in == "addr-fetch") {
360 conn_type = ConnectionType::ADDR_FETCH;
361 } else if (conn_type_in == "feeler") {
362 conn_type = ConnectionType::FEELER;
363 } else {
364 throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
365 }
366
367 NodeContext& node = EnsureAnyNodeContext(request.context);
368 CConnman& connman = EnsureConnman(node);
369
370 const bool success = connman.AddConnection(address, conn_type);
371 if (!success) {
372 throw JSONRPCError(RPC_CLIENT_NODE_CAPACITY_REACHED, "Error: Already at capacity for specified connection type.");
373 }
374
375 UniValue info(UniValue::VOBJ);
376 info.pushKV("address", address);
377 info.pushKV("connection_type", conn_type_in);
378
379 return info;
380},
381 };
382}
383
384static RPCHelpMan disconnectnode()

Callers

nothing calls this directly

Calls 11

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
RPCTypeCheckFunction · 0.85
TrimStringFunction · 0.85
JSONRPCErrorFunction · 0.85
findMethod · 0.80
NetworkIDStringMethod · 0.80
AddConnectionMethod · 0.80
ParamsClass · 0.50
ToStringMethod · 0.45
pushKVMethod · 0.45

Tested by

no test coverage detected