mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Allow passing "tried" to rpc addpeeraddress to call CAddrMan::Good()
Co-authored-by: Martin Zumsande <mzumsande@gmail.com> Co-authored-by: John Newbery <john@johnnewbery.com> Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
This commit is contained in:
parent
5e3380b9f5
commit
ef242f5213
2 changed files with 12 additions and 3 deletions
|
@ -192,6 +192,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||||
{ "unloadwallet", 1, "load_on_startup"},
|
{ "unloadwallet", 1, "load_on_startup"},
|
||||||
{ "getnodeaddresses", 0, "count"},
|
{ "getnodeaddresses", 0, "count"},
|
||||||
{ "addpeeraddress", 1, "port"},
|
{ "addpeeraddress", 1, "port"},
|
||||||
|
{ "addpeeraddress", 2, "tried"},
|
||||||
{ "stop", 0, "wait" },
|
{ "stop", 0, "wait" },
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
|
@ -921,6 +921,7 @@ static RPCHelpMan addpeeraddress()
|
||||||
{
|
{
|
||||||
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"},
|
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"},
|
||||||
{"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"},
|
{"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"},
|
||||||
|
{"tried", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, attempt to add the peer to the tried addresses table"},
|
||||||
},
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
RPCResult::Type::OBJ, "", "",
|
RPCResult::Type::OBJ, "", "",
|
||||||
|
@ -929,8 +930,8 @@ static RPCHelpMan addpeeraddress()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RPCExamples{
|
RPCExamples{
|
||||||
HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333")
|
HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true")
|
||||||
+ HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333")
|
+ HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")
|
||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
@ -941,6 +942,7 @@ static RPCHelpMan addpeeraddress()
|
||||||
|
|
||||||
const std::string& addr_string{request.params[0].get_str()};
|
const std::string& addr_string{request.params[0].get_str()};
|
||||||
const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
|
const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
|
||||||
|
const bool tried{request.params[2].isTrue()};
|
||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
CNetAddr net_addr;
|
CNetAddr net_addr;
|
||||||
|
@ -951,7 +953,13 @@ static RPCHelpMan addpeeraddress()
|
||||||
address.nTime = GetAdjustedTime();
|
address.nTime = GetAdjustedTime();
|
||||||
// The source address is set equal to the address. This is equivalent to the peer
|
// The source address is set equal to the address. This is equivalent to the peer
|
||||||
// announcing itself.
|
// announcing itself.
|
||||||
if (node.addrman->Add({address}, address)) success = true;
|
if (node.addrman->Add({address}, address)) {
|
||||||
|
success = true;
|
||||||
|
if (tried) {
|
||||||
|
// Attempt to move the address to the tried addresses table.
|
||||||
|
node.addrman->Good(address);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.pushKV("success", success);
|
obj.pushKV("success", success);
|
||||||
|
|
Loading…
Add table
Reference in a new issue