Skip to content

Commit c65c0d0

Browse files
committed
init: allow UNIX socket path for -proxy and -onion
1 parent c3bd431 commit c65c0d0

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

src/init.cpp

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
12981298
std::string host_out;
12991299
uint16_t port_out{0};
13001300
if (!SplitHostPort(socket_addr, port_out, host_out)) {
1301+
#if HAVE_SOCKADDR_UN
1302+
// Allow unix domain sockets for -proxy and -onion e.g. unix:/some/file/path
1303+
if ((port_option != "-proxy" && port_option != "-onion") || socket_addr.find(ADDR_PREFIX_UNIX) != 0) {
1304+
return InitError(InvalidPortErrMsg(port_option, socket_addr));
1305+
}
1306+
#else
13011307
return InitError(InvalidPortErrMsg(port_option, socket_addr));
1308+
#endif
13021309
}
13031310
}
13041311
}
@@ -1365,12 +1372,18 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13651372
// -noproxy (or -proxy=0) as well as the empty string can be used to not set a proxy, this is the default
13661373
std::string proxyArg = args.GetArg("-proxy", "");
13671374
if (proxyArg != "" && proxyArg != "0") {
1368-
const std::optional<CService> proxyAddr{Lookup(proxyArg, 9050, fNameLookup)};
1369-
if (!proxyAddr.has_value()) {
1370-
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1375+
Proxy addrProxy;
1376+
if (IsUnixSocketPath(proxyArg)) {
1377+
addrProxy = Proxy(proxyArg, proxyRandomize);
1378+
} else {
1379+
const std::optional<CService> proxyAddr{Lookup(proxyArg, 9050, fNameLookup)};
1380+
if (!proxyAddr.has_value()) {
1381+
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
1382+
}
1383+
1384+
addrProxy = Proxy(proxyAddr.value(), proxyRandomize);
13711385
}
13721386

1373-
Proxy addrProxy = Proxy(proxyAddr.value(), proxyRandomize);
13741387
if (!addrProxy.IsValid())
13751388
return InitError(strprintf(_("Invalid -proxy address or hostname: '%s'"), proxyArg));
13761389

@@ -1396,11 +1409,16 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13961409
"reaching the Tor network is explicitly forbidden: -onion=0"));
13971410
}
13981411
} else {
1399-
const std::optional<CService> addr{Lookup(onionArg, 9050, fNameLookup)};
1400-
if (!addr.has_value() || !addr->IsValid()) {
1401-
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
1412+
if (IsUnixSocketPath(onionArg)) {
1413+
onion_proxy = Proxy(onionArg, proxyRandomize);
1414+
} else {
1415+
const std::optional<CService> addr{Lookup(onionArg, 9050, fNameLookup)};
1416+
if (!addr.has_value() || !addr->IsValid()) {
1417+
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
1418+
}
1419+
1420+
onion_proxy = Proxy(addr.value(), proxyRandomize);
14021421
}
1403-
onion_proxy = Proxy{addr.value(), proxyRandomize};
14041422
}
14051423
}
14061424

0 commit comments

Comments
 (0)