Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC: Support addnode onetry without making the connection priviliged #12674

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Expand Up @@ -153,6 +153,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "bumpfee", 1, "options" },
{ "logging", 0, "include" },
{ "logging", 1, "exclude" },
{ "addnode", 2, "privileged" },
{ "disconnectnode", 1, "nodeid" },
// Echo with conversion (For testing only)
{ "echojson", 0, "arg0" },
Expand Down
16 changes: 10 additions & 6 deletions src/rpc/net.cpp
Expand Up @@ -228,17 +228,16 @@ static UniValue addnode(const JSONRPCRequest& request)
std::string strCommand;
if (!request.params[1].isNull())
strCommand = request.params[1].get_str();
if (request.fHelp || request.params.size() != 2 ||
if (request.fHelp || request.params.size() < 2 || request.params.size() > 3 ||
luke-jr marked this conversation as resolved.
Show resolved Hide resolved
(strCommand != "onetry" && strCommand != "add" && strCommand != "remove"))
throw std::runtime_error(
RPCHelpMan{"addnode",
"\nAttempts to add or remove a node from the addnode list.\n"
"Or try a connection to a node once.\n"
"Nodes added using addnode (or -connect) are protected from DoS disconnection and are not required to be\n"
"full nodes/support SegWit as other outbound peers are (though such peers will not be synced from).\n",
"Or try a connection to a node once.\n",
{
{"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The node (see getpeerinfo for nodes)"},
{"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"},
{"privileged", RPCArg::Type::BOOL, /* default */ "true", "If true, nodes added will be protected from DoS disconnection and not required to be full nodes or support segwit as other outbound peers are (though such peers will not be synced from). Only supported for command \"onetry\" for now."},
},
RPCResult{RPCResult::Type::NONE, "", ""},
RPCExamples{
Expand All @@ -251,14 +250,19 @@ static UniValue addnode(const JSONRPCRequest& request)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");

std::string strNode = request.params[0].get_str();
const bool privileged = request.params[2].isNull() ? true : request.params[2].get_bool();
luke-jr marked this conversation as resolved.
Show resolved Hide resolved

if (strCommand == "onetry")
{
CAddress addr;
g_rpc_node->connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, true);
g_rpc_node->connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, privileged);
return NullUniValue;
}

if (!privileged) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unprivileged connections are only supported for the \"onetry\" command for now");
luke-jr marked this conversation as resolved.
Show resolved Hide resolved
}

if (strCommand == "add")
{
if(!g_rpc_node->connman->AddNode(strNode))
Expand Down Expand Up @@ -766,7 +770,7 @@ static const CRPCCommand commands[] =
{ "network", "getconnectioncount", &getconnectioncount, {} },
{ "network", "ping", &ping, {} },
{ "network", "getpeerinfo", &getpeerinfo, {} },
{ "network", "addnode", &addnode, {"node","command"} },
{ "network", "addnode", &addnode, {"node","command","privileged"} },
{ "network", "disconnectnode", &disconnectnode, {"address", "nodeid"} },
{ "network", "getaddednodeinfo", &getaddednodeinfo, {"node"} },
{ "network", "getnettotals", &getnettotals, {} },
Expand Down