mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
p2p, refactor: return vector/optional<CService> in Lookup
This commit is contained in:
40
src/init.cpp
40
src/init.cpp
@@ -1355,12 +1355,12 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
|
||||
std::string proxyArg = args.GetArg("-proxy", "");
|
||||
if (proxyArg != "" && proxyArg != "0") {
|
||||
CService proxyAddr;
|
||||
if (!Lookup(proxyArg, proxyAddr, 9050, fNameLookup)) {
|
||||
const std::optional<CService> proxyAddr{Lookup(proxyArg, 9050, fNameLookup)};
|
||||
if (!proxyAddr.has_value()) {
|
||||
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
|
||||
}
|
||||
|
||||
Proxy addrProxy = Proxy(proxyAddr, proxyRandomize);
|
||||
Proxy addrProxy = Proxy(proxyAddr.value(), proxyRandomize);
|
||||
if (!addrProxy.IsValid())
|
||||
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
|
||||
|
||||
@@ -1386,11 +1386,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
"reaching the Tor network is explicitly forbidden: -onion=0"));
|
||||
}
|
||||
} else {
|
||||
CService addr;
|
||||
if (!Lookup(onionArg, addr, 9050, fNameLookup) || !addr.IsValid()) {
|
||||
const std::optional<CService> addr{Lookup(onionArg, 9050, fNameLookup)};
|
||||
if (!addr.has_value() || !addr->IsValid()) {
|
||||
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
|
||||
}
|
||||
onion_proxy = Proxy{addr, proxyRandomize};
|
||||
onion_proxy = Proxy{addr.value(), proxyRandomize};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1410,9 +1410,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
}
|
||||
|
||||
for (const std::string& strAddr : args.GetArgs("-externalip")) {
|
||||
CService addrLocal;
|
||||
if (Lookup(strAddr, addrLocal, GetListenPort(), fNameLookup) && addrLocal.IsValid())
|
||||
AddLocal(addrLocal, LOCAL_MANUAL);
|
||||
const std::optional<CService> addrLocal{Lookup(strAddr, GetListenPort(), fNameLookup)};
|
||||
if (addrLocal.has_value() && addrLocal->IsValid())
|
||||
AddLocal(addrLocal.value(), LOCAL_MANUAL);
|
||||
else
|
||||
return InitError(ResolveErrMsg("externalip", strAddr));
|
||||
}
|
||||
@@ -1748,13 +1748,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
};
|
||||
|
||||
for (const std::string& bind_arg : args.GetArgs("-bind")) {
|
||||
CService bind_addr;
|
||||
std::optional<CService> bind_addr;
|
||||
const size_t index = bind_arg.rfind('=');
|
||||
if (index == std::string::npos) {
|
||||
if (Lookup(bind_arg, bind_addr, default_bind_port, /*fAllowLookup=*/false)) {
|
||||
connOptions.vBinds.push_back(bind_addr);
|
||||
if (IsBadPort(bind_addr.GetPort())) {
|
||||
InitWarning(BadPortWarning("-bind", bind_addr.GetPort()));
|
||||
bind_addr = Lookup(bind_arg, default_bind_port, /*fAllowLookup=*/false);
|
||||
if (bind_addr.has_value()) {
|
||||
connOptions.vBinds.push_back(bind_addr.value());
|
||||
if (IsBadPort(bind_addr.value().GetPort())) {
|
||||
InitWarning(BadPortWarning("-bind", bind_addr.value().GetPort()));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -1762,8 +1763,9 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
const std::string network_type = bind_arg.substr(index + 1);
|
||||
if (network_type == "onion") {
|
||||
const std::string truncated_bind_arg = bind_arg.substr(0, index);
|
||||
if (Lookup(truncated_bind_arg, bind_addr, BaseParams().OnionServiceTargetPort(), false)) {
|
||||
connOptions.onion_binds.push_back(bind_addr);
|
||||
bind_addr = Lookup(truncated_bind_arg, BaseParams().OnionServiceTargetPort(), false);
|
||||
if (bind_addr.has_value()) {
|
||||
connOptions.onion_binds.push_back(bind_addr.value());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -1841,11 +1843,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
|
||||
const std::string& i2psam_arg = args.GetArg("-i2psam", "");
|
||||
if (!i2psam_arg.empty()) {
|
||||
CService addr;
|
||||
if (!Lookup(i2psam_arg, addr, 7656, fNameLookup) || !addr.IsValid()) {
|
||||
const std::optional<CService> addr{Lookup(i2psam_arg, 7656, fNameLookup)};
|
||||
if (!addr.has_value() || !addr->IsValid()) {
|
||||
return InitError(strprintf(_("Invalid -i2psam address or hostname: '%s'"), i2psam_arg));
|
||||
}
|
||||
SetProxy(NET_I2P, Proxy{addr});
|
||||
SetProxy(NET_I2P, Proxy{addr.value()});
|
||||
} else {
|
||||
if (args.IsArgSet("-onlynet") && IsReachable(NET_I2P)) {
|
||||
return InitError(
|
||||
|
||||
Reference in New Issue
Block a user