| 906 | } |
| 907 | |
| 908 | static RPCHelpMan addpeeraddress() |
| 909 | { |
| 910 | return RPCHelpMan{"addpeeraddress", |
| 911 | "\nAdd the address of a potential peer to the address manager. This RPC is for testing only.\n", |
| 912 | { |
| 913 | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The IP address of the peer"}, |
| 914 | {"port", RPCArg::Type::NUM, RPCArg::Optional::NO, "The port of the peer"}, |
| 915 | {"tried", RPCArg::Type::BOOL, RPCArg::Default{false}, "If true, attempt to add the peer to the tried addresses table"}, |
| 916 | }, |
| 917 | RPCResult{ |
| 918 | RPCResult::Type::OBJ, "", "", |
| 919 | { |
| 920 | {RPCResult::Type::BOOL, "success", "whether the peer address was successfully added to the address manager"}, |
| 921 | }, |
| 922 | }, |
| 923 | RPCExamples{ |
| 924 | HelpExampleCli("addpeeraddress", "\"1.2.3.4\" 8333 true") |
| 925 | + HelpExampleRpc("addpeeraddress", "\"1.2.3.4\", 8333, true") |
| 926 | }, |
| 927 | [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
| 928 | { |
| 929 | NodeContext& node = EnsureAnyNodeContext(request.context); |
| 930 | if (!node.addrman) { |
| 931 | throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Address manager functionality missing or disabled"); |
| 932 | } |
| 933 | |
| 934 | const std::string& addr_string{request.params[0].get_str()}; |
| 935 | const uint16_t port{static_cast<uint16_t>(request.params[1].get_int())}; |
| 936 | const bool tried{request.params[2].isTrue()}; |
| 937 | |
| 938 | UniValue obj(UniValue::VOBJ); |
| 939 | CNetAddr net_addr; |
| 940 | bool success{false}; |
| 941 | |
| 942 | if (LookupHost(addr_string, net_addr, false)) { |
| 943 | CAddress address{{net_addr, port}, ServiceFlags{NODE_NETWORK | NODE_WITNESS}}; |
| 944 | address.nTime = GetAdjustedTime(); |
| 945 | // The source address is set equal to the address. This is equivalent to the peer |
| 946 | // announcing itself. |
| 947 | if (node.addrman->Add({address}, address)) { |
| 948 | success = true; |
| 949 | if (tried) { |
| 950 | // Attempt to move the address to the tried addresses table. |
| 951 | node.addrman->Good(address); |
| 952 | } |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | obj.pushKV("success", success); |
| 957 | return obj; |
| 958 | }, |
| 959 | }; |
| 960 | } |
| 961 | |
| 962 | void RegisterNetRPCCommands(CRPCTable &t) |
| 963 | { |
nothing calls this directly
no test coverage detected