mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-04 00:12:33 +02:00
Merge 20551 via rpc_onetry_conntype
This commit is contained in:
commit
af74c96846
@ -42,11 +42,31 @@ const std::vector<std::string> CONNECTION_TYPE_DOC{
|
||||
"outbound-full-relay (default automatic connections)",
|
||||
"block-relay-only (does not relay transactions or addresses)",
|
||||
"inbound (initiated by the peer)",
|
||||
"manual (added via addnode RPC or -addnode/-connect configuration options)",
|
||||
"manual (added via addnode RPC or -addnode/-connect configuration options; protected from DoS disconnection and not required to be full nodes as other outbound peers are)",
|
||||
"addr-fetch (short-lived automatic connection for soliciting addresses)",
|
||||
"feeler (short-lived automatic connection for testing addresses)"
|
||||
};
|
||||
|
||||
ConnectionType ConnectionTypeFromValue(const UniValue& uv)
|
||||
{
|
||||
const std::string& s{uv.get_str()};
|
||||
if (s == "inbound") {
|
||||
return ConnectionType::INBOUND;
|
||||
} else if (s == "manual") {
|
||||
return ConnectionType::MANUAL;
|
||||
} else if (s == "feeler") {
|
||||
return ConnectionType::FEELER;
|
||||
} else if (s == "outbound-full-relay") {
|
||||
return ConnectionType::OUTBOUND_FULL_RELAY;
|
||||
} else if (s == "block-relay-only") {
|
||||
return ConnectionType::BLOCK_RELAY;
|
||||
} else if (s == "addr-fetch") {
|
||||
return ConnectionType::ADDR_FETCH;
|
||||
}
|
||||
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown connection type " + s);
|
||||
}
|
||||
|
||||
const std::vector<std::string> TRANSPORT_TYPE_DOC{
|
||||
"detecting (peer could be v1 or v2)",
|
||||
"v1 (plaintext transport protocol)",
|
||||
@ -311,14 +331,14 @@ static RPCHelpMan addnode()
|
||||
return 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" +
|
||||
+
|
||||
strprintf("Addnode connections are limited to %u at a time", MAX_ADDNODE_CONNECTIONS) +
|
||||
" and are counted separately from the -maxconnections limit.\n",
|
||||
{
|
||||
{"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::DefaultHint{"set by -v2transport"}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
|
||||
{"v2transport|connection_type_compat", {RPCArg::Type::BOOL, RPCArg::Type::STR}, RPCArg::DefaultHint{"set by -v2transport"}, "Attempt to connect using BIP324 v2 transport protocol (ignored for 'remove' command)"},
|
||||
{"connection_type", RPCArg::Type::STR, RPCArg::Default{"manual"}, "Type of connection: \n" + Join(CONNECTION_TYPE_DOC, ",\n") + "\nOnly supported for command \"onetry\" for now."},
|
||||
},
|
||||
RPCResult{RPCResult::Type::NONE, "", ""},
|
||||
RPCExamples{
|
||||
@ -338,7 +358,25 @@ static RPCHelpMan addnode()
|
||||
|
||||
const std::string node_arg{request.params[0].get_str()};
|
||||
bool node_v2transport = connman.GetLocalServices() & NODE_P2P_V2;
|
||||
bool use_v2transport = self.MaybeArg<bool>(2).value_or(node_v2transport);
|
||||
bool use_v2transport{node_v2transport};
|
||||
ConnectionType connection_type = ConnectionType::MANUAL;
|
||||
std::string connection_type_arg;
|
||||
if (request.params[2].isStr()) {
|
||||
// connection_type used to occupy this position (v0.21.0.knots20210130-v25.1.knots20231115)
|
||||
if (command == "remove" || request.params.size() > 3) {
|
||||
// Same behaviour as too many args passed normally
|
||||
throw std::runtime_error(self.ToString());
|
||||
}
|
||||
connection_type = ConnectionTypeFromValue(request.params[2]);
|
||||
} else {
|
||||
use_v2transport = self.MaybeArg<bool>(2).value_or(node_v2transport);
|
||||
if (!request.params[3].isNull()) {
|
||||
if (command == "remove") {
|
||||
throw std::runtime_error(self.ToString());
|
||||
}
|
||||
connection_type = ConnectionTypeFromValue(request.params[3]);
|
||||
}
|
||||
}
|
||||
|
||||
if (use_v2transport && !node_v2transport) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Error: v2transport requested but not enabled (see -v2transport)");
|
||||
@ -347,12 +385,16 @@ static RPCHelpMan addnode()
|
||||
if (command == "onetry")
|
||||
{
|
||||
CAddress addr;
|
||||
connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grant_outbound=*/{}, node_arg.c_str(), ConnectionType::MANUAL, use_v2transport);
|
||||
connman.OpenNetworkConnection(addr, /*fCountFailure=*/false, /*grant_outbound=*/{}, node_arg.c_str(), connection_type, use_v2transport);
|
||||
return UniValue::VNULL;
|
||||
}
|
||||
|
||||
if (command == "add")
|
||||
{
|
||||
if (connection_type != ConnectionType::MANUAL) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "connection_type != manual is only supported for the \"onetry\" command for now");
|
||||
}
|
||||
|
||||
if (!connman.AddNode({node_arg, use_v2transport})) {
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user