mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 14:53:43 +01:00
rpc: addnode arg to use BIP324 v2 p2p
Co-authored-by: Pieter Wuille <bitcoin-dev@wuille.net>
This commit is contained in:
@@ -289,11 +289,12 @@ static RPCHelpMan addnode()
|
||||
{
|
||||
{"node", RPCArg::Type::STR, RPCArg::Optional::NO, "The address of the peer to connect to"},
|
||||
{"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"},
|
||||
{"v2transport", RPCArg::Type::BOOL, RPCArg::Default{false}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{
|
||||
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\"")
|
||||
+ HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\"")
|
||||
HelpExampleCli("addnode", "\"192.168.0.6:8333\" \"onetry\" true")
|
||||
+ HelpExampleRpc("addnode", "\"192.168.0.6:8333\", \"onetry\" true")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
@@ -307,17 +308,22 @@ static RPCHelpMan addnode()
|
||||
CConnman& connman = EnsureConnman(node);
|
||||
|
||||
const std::string node_arg{request.params[0].get_str()};
|
||||
bool use_v2transport = self.Arg<bool>(2);
|
||||
|
||||
if (use_v2transport && !(node.connman->GetLocalServices() & NODE_P2P_V2)) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");
|
||||
}
|
||||
|
||||
if (command == "onetry")
|
||||
{
|
||||
CAddress addr;
|
||||
connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grantOutbound=*/nullptr, node_arg.c_str(), ConnectionType::MANUAL, /*use_v2transport=*/false);
|
||||
connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grantOutbound=*/nullptr, node_arg.c_str(), ConnectionType::MANUAL, use_v2transport);
|
||||
return UniValue::VNULL;
|
||||
}
|
||||
|
||||
if (command == "add")
|
||||
{
|
||||
if (!connman.AddNode(node_arg)) {
|
||||
if (!connman.AddNode({node_arg, use_v2transport})) {
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
|
||||
}
|
||||
}
|
||||
@@ -475,7 +481,7 @@ static RPCHelpMan getaddednodeinfo()
|
||||
if (!request.params[0].isNull()) {
|
||||
bool found = false;
|
||||
for (const AddedNodeInfo& info : vInfo) {
|
||||
if (info.strAddedNode == request.params[0].get_str()) {
|
||||
if (info.m_params.m_added_node == request.params[0].get_str()) {
|
||||
vInfo.assign(1, info);
|
||||
found = true;
|
||||
break;
|
||||
@@ -490,7 +496,7 @@ static RPCHelpMan getaddednodeinfo()
|
||||
|
||||
for (const AddedNodeInfo& info : vInfo) {
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("addednode", info.strAddedNode);
|
||||
obj.pushKV("addednode", info.m_params.m_added_node);
|
||||
obj.pushKV("connected", info.fConnected);
|
||||
UniValue addresses(UniValue::VARR);
|
||||
if (info.fConnected) {
|
||||
|
||||
Reference in New Issue
Block a user