p2p, refactor: return std::optional<CNetAddr> in LookupHost

This commit is contained in:
brunoerg
2022-10-11 13:37:45 -03:00
parent 34bcdfc6a6
commit 5c832c3820
12 changed files with 61 additions and 83 deletions

View File

@@ -713,9 +713,10 @@ static RPCHelpMan setban()
isSubnet = true;
if (!isSubnet) {
CNetAddr resolved;
LookupHost(request.params[0].get_str(), resolved, false);
netAddr = resolved;
const std::optional<CNetAddr> addr{LookupHost(request.params[0].get_str(), false)};
if (addr.has_value()) {
netAddr = addr.value();
}
}
else
LookupSubNet(request.params[0].get_str(), subNet);
@@ -943,11 +944,11 @@ static RPCHelpMan addpeeraddress()
const bool tried{request.params[2].isNull() ? false : request.params[2].get_bool()};
UniValue obj(UniValue::VOBJ);
CNetAddr net_addr;
std::optional<CNetAddr> net_addr{LookupHost(addr_string, false)};
bool success{false};
if (LookupHost(addr_string, net_addr, false)) {
CService service{net_addr, port};
if (net_addr.has_value()) {
CService service{net_addr.value(), port};
CAddress address{MaybeFlipIPv6toCJDNS(service), ServiceFlags{NODE_NETWORK | NODE_WITNESS}};
address.nTime = Now<NodeSeconds>();
// The source address is set equal to the address. This is equivalent to the peer