Skip to content

Commit 6bf786d

Browse files
fanquakePastaPastaPasta
authored andcommitted
Merge bitcoin#25735: net: remove useless call to IsReachable() from CConnman::Bind()
9cbfe40 net: remove useless call to IsReachable() from CConnman::Bind() (Vasil Dimov) Pull request description: `CConnman::Bind()` is called without `BF_EXPLICIT` only when passed either `0.0.0.0` or `::`. For those addresses `IsReachable()` is always true (regardless of the `-onlynet=` setting!), meaning that the `if` condition never evaluates to true. `IsReachable()` is always true for the "any" IPv4 and IPv6 addresses because `CNetAddr::GetNetwork()` returns `NET_UNROUTABLE` instead of `NET_IPV4` or `NET_IPV6` and the network `NET_UNROUTABLE` is always considered reachable. It follows that `BF_EXPLICIT` is unnecessary, remove it too. ACKs for top commit: naumenkogs: ACK 9cbfe40 aureleoules: ACK 9cbfe40 mzumsande: ACK 9cbfe40 Tree-SHA512: 4e53ee8a73ddd133fd4ff25635135b65e5c19d1fc56fe5c30337406560664616c0adff414dca47602948919f34c81073aae6bfc2871509f3912663d86750928e
1 parent 012b0b7 commit 6bf786d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/net.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ static constexpr auto FEELER_SLEEP_WINDOW{1s};
105105
/** Used to pass flags to the Bind() function */
106106
enum BindFlags {
107107
BF_NONE = 0,
108-
BF_EXPLICIT = (1U << 0),
109-
BF_REPORT_ERROR = (1U << 1),
108+
BF_REPORT_ERROR = (1U << 0),
110109
/**
111110
* Do not call AddLocal() for our special addresses, e.g., for incoming
112111
* Tor connections, to prevent gossiping them over the network.
113112
*/
114-
BF_DONT_ADVERTISE = (1U << 2),
113+
BF_DONT_ADVERTISE = (1U << 1),
115114
};
116115

117116
#ifndef USE_WAKEUP_PIPE
@@ -3329,9 +3328,6 @@ bool CConnman::Bind(const CService& addr_, unsigned int flags, NetPermissionFlag
33293328
{
33303329
const CService addr{MaybeFlipIPv6toCJDNS(addr_)};
33313330

3332-
if (!(flags & BF_EXPLICIT) && !IsReachable(addr)) {
3333-
return false;
3334-
}
33353331
bilingual_str strError;
33363332
if (!BindListenPort(addr, strError, permissions)) {
33373333
if ((flags & BF_REPORT_ERROR) && clientInterface) {
@@ -3351,13 +3347,13 @@ bool CConnman::InitBinds(const Options& options)
33513347
{
33523348
bool fBound = false;
33533349
for (const auto& addrBind : options.vBinds) {
3354-
fBound |= Bind(addrBind, (BF_EXPLICIT | BF_REPORT_ERROR), NetPermissionFlags::None);
3350+
fBound |= Bind(addrBind, BF_REPORT_ERROR, NetPermissionFlags::None);
33553351
}
33563352
for (const auto& addrBind : options.vWhiteBinds) {
3357-
fBound |= Bind(addrBind.m_service, (BF_EXPLICIT | BF_REPORT_ERROR), addrBind.m_flags);
3353+
fBound |= Bind(addrBind.m_service, BF_REPORT_ERROR, addrBind.m_flags);
33583354
}
33593355
for (const auto& addr_bind : options.onion_binds) {
3360-
fBound |= Bind(addr_bind, BF_EXPLICIT | BF_DONT_ADVERTISE, NetPermissionFlags::None);
3356+
fBound |= Bind(addr_bind, BF_DONT_ADVERTISE, NetPermissionFlags::None);
33613357
}
33623358
if (options.bind_on_any) {
33633359
struct in_addr inaddr_any;

0 commit comments

Comments
 (0)