aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-07-16 16:27:24 -0400
committerAva Chow <github@achow101.com>2024-07-16 16:27:24 -0400
commit45750f61d65d5ac4a28333d8f676961037b25f55 (patch)
tree9692f38bf06ee1e6e184e8bae5d8ae4f7bba3178 /src
parent16b4f75d04c82b950e9805f5048a4834c51e1b6d (diff)
parentbca346a97056748f1e3fb899f336d56d9fd45a64 (diff)
Merge bitcoin/bitcoin#22729: Make it possible to disable Tor binds and abort startup on bind failure
bca346a97056748f1e3fb899f336d56d9fd45a64 net: require P2P binds to succeed (Vasil Dimov) af552534ab83c572d3bc3f93ccaee5c1961ccab5 net: report an error if unable to bind on the Tor listening addr:port (Vasil Dimov) 9a7e5f4d68dadc64a675f32d1e91199d6b1aa095 net: don't extra bind for Tor if binds are restricted (Vasil Dimov) Pull request description: Make it possible to disable the Tor binding on `127.0.0.1:8334` and stop startup if any P2P bind fails instead of "if all P2P binds fail". Fixes https://github.com/bitcoin/bitcoin/issues/22726 Fixes https://github.com/bitcoin/bitcoin/issues/22727 ACKs for top commit: achow101: ACK bca346a97056748f1e3fb899f336d56d9fd45a64 cbergqvist: ACK bca346a97056748f1e3fb899f336d56d9fd45a64 pinheadmz: ACK bca346a97056748f1e3fb899f336d56d9fd45a64 Tree-SHA512: fabef89a957191eea4f3e3b6109d2b8389f27ecc74440a920b0c10f31fff00a85bcfd1eb3c91826c7169c618f4de8a8d0a260e2caf40fd854f07ea9a980d8603
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp2
-rw-r--r--src/net.cpp28
2 files changed, 22 insertions, 8 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 03969b00bb..9e570d6128 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1881,6 +1881,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
CService onion_service_target;
if (!connOptions.onion_binds.empty()) {
onion_service_target = connOptions.onion_binds.front();
+ } else if (!connOptions.vBinds.empty()) {
+ onion_service_target = connOptions.vBinds.front();
} else {
onion_service_target = DefaultOnionServiceTarget();
connOptions.onion_binds.push_back(onion_service_target);
diff --git a/src/net.cpp b/src/net.cpp
index d265d78548..3d3f9f4ba7 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -3202,24 +3202,36 @@ bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlag
bool CConnman::InitBinds(const Options& options)
{
- bool fBound = false;
for (const auto& addrBind : options.vBinds) {
- fBound |= Bind(addrBind, BF_REPORT_ERROR, NetPermissionFlags::None);
+ if (!Bind(addrBind, BF_REPORT_ERROR, NetPermissionFlags::None)) {
+ return false;
+ }
}
for (const auto& addrBind : options.vWhiteBinds) {
- fBound |= Bind(addrBind.m_service, BF_REPORT_ERROR, addrBind.m_flags);
+ if (!Bind(addrBind.m_service, BF_REPORT_ERROR, addrBind.m_flags)) {
+ return false;
+ }
}
for (const auto& addr_bind : options.onion_binds) {
- fBound |= Bind(addr_bind, BF_DONT_ADVERTISE, NetPermissionFlags::None);
+ if (!Bind(addr_bind, BF_REPORT_ERROR | BF_DONT_ADVERTISE, NetPermissionFlags::None)) {
+ return false;
+ }
}
if (options.bind_on_any) {
+ // Don't consider errors to bind on IPv6 "::" fatal because the host OS
+ // may not have IPv6 support and the user did not explicitly ask us to
+ // bind on that.
+ const CService ipv6_any{in6_addr(IN6ADDR_ANY_INIT), GetListenPort()}; // ::
+ Bind(ipv6_any, BF_NONE, NetPermissionFlags::None);
+
struct in_addr inaddr_any;
inaddr_any.s_addr = htonl(INADDR_ANY);
- struct in6_addr inaddr6_any = IN6ADDR_ANY_INIT;
- fBound |= Bind(CService(inaddr6_any, GetListenPort()), BF_NONE, NetPermissionFlags::None);
- fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound ? BF_REPORT_ERROR : BF_NONE, NetPermissionFlags::None);
+ const CService ipv4_any{inaddr_any, GetListenPort()}; // 0.0.0.0
+ if (!Bind(ipv4_any, BF_REPORT_ERROR, NetPermissionFlags::None)) {
+ return false;
+ }
}
- return fBound;
+ return true;
}
bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)