refactor: Return std::optional from GetNameProxy

This commit is contained in:
MarcoFalke
2026-03-05 13:11:58 +01:00
parent f82d076771
commit faeac1a931
3 changed files with 16 additions and 13 deletions

View File

@@ -434,7 +434,6 @@ CNode* CConnman::ConnectNode(CAddress addrConnect,
// Connect
std::unique_ptr<Sock> sock;
Proxy proxy;
CService addr_bind;
assert(!addr_bind.IsValid());
std::unique_ptr<i2p::sam::Session> i2p_transient_session;
@@ -442,6 +441,7 @@ CNode* CConnman::ConnectNode(CAddress addrConnect,
for (auto& target_addr: connect_to) {
if (target_addr.IsValid()) {
bool use_proxy;
Proxy proxy;
if (proxy_override.has_value()) {
use_proxy = true;
proxy = proxy_override.value();
@@ -495,12 +495,14 @@ CNode* CConnman::ConnectNode(CAddress addrConnect,
// the proxy, mark this as an attempt.
addrman.get().Attempt(target_addr, fCountFailure);
}
} else if (pszDest && GetNameProxy(proxy)) {
std::string host;
uint16_t port{default_port};
SplitHostPort(std::string(pszDest), port, host);
bool proxyConnectionFailed;
sock = ConnectThroughProxy(proxy, host, port, proxyConnectionFailed);
} else if (pszDest) {
if (const auto name_proxy = GetNameProxy()) {
std::string host;
uint16_t port{default_port};
SplitHostPort(std::string(pszDest), port, host);
bool proxyConnectionFailed;
sock = ConnectThroughProxy(*name_proxy, host, port, proxyConnectionFailed);
}
}
// Check any other resolved address (if any) if we fail to connect
if (!sock) {

View File

@@ -723,12 +723,13 @@ bool SetNameProxy(const Proxy &addrProxy) {
return true;
}
bool GetNameProxy(Proxy &nameProxyOut) {
std::optional<Proxy> GetNameProxy()
{
LOCK(g_proxyinfo_mutex);
if(!nameProxy.IsValid())
return false;
nameProxyOut = nameProxy;
return true;
if (!nameProxy.IsValid()) {
return std::nullopt;
}
return nameProxy;
}
bool HaveNameProxy() {

View File

@@ -199,7 +199,7 @@ bool IsProxy(const CNetAddr &addr);
*/
bool SetNameProxy(const Proxy &addrProxy);
bool HaveNameProxy();
bool GetNameProxy(Proxy &nameProxyOut);
std::optional<Proxy> GetNameProxy();
using DNSLookupFn = std::function<std::vector<CNetAddr>(const std::string&, bool)>;
extern DNSLookupFn g_dns_lookup;