aboutsummaryrefslogtreecommitdiff
path: root/src/rpc/net.cpp
diff options
context:
space:
mode:
authorstratospher <44024636+stratospher@users.noreply.github.com>2022-02-04 11:05:23 +0530
committerstratospher <44024636+stratospher@users.noreply.github.com>2024-01-23 22:04:48 +0530
commit4487b8051797173c7ab432e75efa370afb03b529 (patch)
tree0ddab3eb06d55c64ce8979b0806c78130399e963 /src/rpc/net.cpp
parent16b5b4b674414c41f34b0d37e15a16521fb08013 (diff)
downloadbitcoin-4487b8051797173c7ab432e75efa370afb03b529.tar.xz
[rpc/net] Allow v2 p2p support in addconnection
This test-only RPC is required when a TestNode initiates an outbound v2 p2p connection. Add a new arg `v2transport` so that the node can attempt v2 connections.
Diffstat (limited to 'src/rpc/net.cpp')
-rw-r--r--src/rpc/net.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp
index c631132df2..47eb5c4f3e 100644
--- a/src/rpc/net.cpp
+++ b/src/rpc/net.cpp
@@ -370,6 +370,7 @@ static RPCHelpMan addconnection()
{
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address and port to attempt connecting to."},
{"connection_type", RPCArg::Type::STR, RPCArg::Optional::NO, "Type of connection to open (\"outbound-full-relay\", \"block-relay-only\", \"addr-fetch\" or \"feeler\")."},
+ {"v2transport", RPCArg::Type::BOOL, RPCArg::Default{false}, "Attempt to connect using BIP324 v2 transport protocol"},
},
RPCResult{
RPCResult::Type::OBJ, "", "",
@@ -378,8 +379,8 @@ static RPCHelpMan addconnection()
{ RPCResult::Type::STR, "connection_type", "Type of connection opened." },
}},
RPCExamples{
- HelpExampleCli("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\"")
- + HelpExampleRpc("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\"")
+ HelpExampleCli("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\" true")
+ + HelpExampleRpc("addconnection", "\"192.168.0.6:8333\" \"outbound-full-relay\" true")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
@@ -401,11 +402,16 @@ static RPCHelpMan addconnection()
} else {
throw JSONRPCError(RPC_INVALID_PARAMETER, self.ToString());
}
+ bool use_v2transport = !request.params[2].isNull() && request.params[2].get_bool();
NodeContext& node = EnsureAnyNodeContext(request.context);
CConnman& connman = EnsureConnman(node);
- const bool success = connman.AddConnection(address, conn_type);
+ if (use_v2transport && !(connman.GetLocalServices() & NODE_P2P_V2)) {
+ throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: Adding v2transport connections requires -v2transport init flag to be set.");
+ }
+
+ const bool success = connman.AddConnection(address, conn_type, use_v2transport);
if (!success) {
throw JSONRPCError(RPC_CLIENT_NODE_CAPACITY_REACHED, "Error: Already at capacity for specified connection type.");
}