Skip to content

Commit ef242f5

Browse files
jonatackmzumsandejnewberyvasild
committed
Allow passing "tried" to rpc addpeeraddress to call CAddrMan::Good()
Co-authored-by: Martin Zumsande <[email protected]> Co-authored-by: John Newbery <[email protected]> Co-authored-by: Vasil Dimov <[email protected]>
1 parent 5e3380b commit ef242f5

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
192192
{ "unloadwallet", 1, "load_on_startup"},
193193
{ "getnodeaddresses", 0, "count"},
194194
{ "addpeeraddress", 1, "port"},
195+
{ "addpeeraddress", 2, "tried"},
195196
{ "stop", 0, "wait" },
196197
};
197198
// clang-format on

src/rpc/net.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ static RPCHelpMan addpeeraddress()
921921
{
922922
{"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"},
923923
{"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"},
924+
{"tried", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, attempt to add the peer to the tried addresses table"},
924925
},
925926
RPCResult{
926927
RPCResult::Type::OBJ, "", "",
@@ -929,8 +930,8 @@ static RPCHelpMan addpeeraddress()
929930
},
930931
},
931932
RPCExamples{
932-
HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333")
933-
+ HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333")
933+
HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true")
934+
+ HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true")
934935
},
935936
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
936937
{
@@ -941,6 +942,7 @@ static RPCHelpMan addpeeraddress()
941942

942943
const std::string& addr_string{request.params[0].get_str()};
943944
const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())};
945+
const bool tried{request.params[2].isTrue()};
944946

945947
UniValue obj(UniValue::VOBJ);
946948
CNetAddr net_addr;
@@ -951,7 +953,13 @@ static RPCHelpMan addpeeraddress()
951953
address.nTime = GetAdjustedTime();
952954
// The source address is set equal to the address. This is equivalent to the peer
953955
// announcing itself.
954-
if (node.addrman->Add({address}, address)) success = true;
956+
if (node.addrman->Add({address}, address)) {
957+
success = true;
958+
if (tried) {
959+
// Attempt to move the address to the tried addresses table.
960+
node.addrman->Good(address);
961+
}
962+
}
955963
}
956964

957965
obj.pushKV("success", success);

0 commit comments

Comments
 (0)