Merge #15138: Drop IsLimited in favor of IsReachable
d6b076c17b
Drop IsLimited in favor of IsReachable (Ben Woosley) Pull request description: These two methods have had the same meaning, but inverted, since110b62f069
. Having one name for a single concept simplifies the code. This is a follow-up to #15051. /cc #7553 Tree-SHA512: 347ceb9e2a55ea06f4c01226411c7bbcade09dd82130e4c59d0824ecefd960875938022edbe5d4bfdf12b0552c9b4cb78b09a688284d707119571daf4eb371b4
This commit is contained in:
commit
43a79d22c1
6 changed files with 44 additions and 65 deletions
10
src/init.cpp
10
src/init.cpp
|
@ -1321,7 +1321,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
|||
for (int n = 0; n < NET_MAX; n++) {
|
||||
enum Network net = (enum Network)n;
|
||||
if (!nets.count(net))
|
||||
SetLimited(net);
|
||||
SetReachable(net, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1332,7 +1332,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
|||
// -proxy sets a proxy for all outgoing network traffic
|
||||
// -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 = gArgs.GetArg("-proxy", "");
|
||||
SetLimited(NET_ONION);
|
||||
SetReachable(NET_ONION, false);
|
||||
if (proxyArg != "" && proxyArg != "0") {
|
||||
CService proxyAddr;
|
||||
if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) {
|
||||
|
@ -1347,7 +1347,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
|||
SetProxy(NET_IPV6, addrProxy);
|
||||
SetProxy(NET_ONION, addrProxy);
|
||||
SetNameProxy(addrProxy);
|
||||
SetLimited(NET_ONION, false); // by default, -proxy sets onion as reachable, unless -noonion later
|
||||
SetReachable(NET_ONION, true); // by default, -proxy sets onion as reachable, unless -noonion later
|
||||
}
|
||||
|
||||
// -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
|
||||
|
@ -1356,7 +1356,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
|||
std::string onionArg = gArgs.GetArg("-onion", "");
|
||||
if (onionArg != "") {
|
||||
if (onionArg == "0") { // Handle -noonion/-onion=0
|
||||
SetLimited(NET_ONION); // set onions as unreachable
|
||||
SetReachable(NET_ONION, false);
|
||||
} else {
|
||||
CService onionProxy;
|
||||
if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) {
|
||||
|
@ -1366,7 +1366,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
|||
if (!addrOnion.IsValid())
|
||||
return InitError(strprintf(_("Invalid -onion address or hostname: '%s'"), onionArg));
|
||||
SetProxy(NET_ONION, addrOnion);
|
||||
SetLimited(NET_ONION, false);
|
||||
SetReachable(NET_ONION, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
34
src/net.cpp
34
src/net.cpp
|
@ -183,7 +183,7 @@ bool IsPeerAddrLocalGood(CNode *pnode)
|
|||
{
|
||||
CService addrLocal = pnode->GetAddrLocal();
|
||||
return fDiscover && pnode->addr.IsRoutable() && addrLocal.IsRoutable() &&
|
||||
!IsLimited(addrLocal.GetNetwork());
|
||||
IsReachable(addrLocal.GetNetwork());
|
||||
}
|
||||
|
||||
// pushes our own address to a peer
|
||||
|
@ -222,7 +222,7 @@ bool AddLocal(const CService& addr, int nScore)
|
|||
if (!fDiscover && nScore < LOCAL_MANUAL)
|
||||
return false;
|
||||
|
||||
if (IsLimited(addr))
|
||||
if (!IsReachable(addr))
|
||||
return false;
|
||||
|
||||
LogPrintf("AddLocal(%s,%i)\n", addr.ToString(), nScore);
|
||||
|
@ -252,24 +252,23 @@ void RemoveLocal(const CService& addr)
|
|||
mapLocalHost.erase(addr);
|
||||
}
|
||||
|
||||
/** Make a particular network entirely off-limits (no automatic connects to it) */
|
||||
void SetLimited(enum Network net, bool fLimited)
|
||||
void SetReachable(enum Network net, bool reachable)
|
||||
{
|
||||
if (net == NET_UNROUTABLE || net == NET_INTERNAL)
|
||||
return;
|
||||
LOCK(cs_mapLocalHost);
|
||||
vfLimited[net] = fLimited;
|
||||
vfLimited[net] = !reachable;
|
||||
}
|
||||
|
||||
bool IsLimited(enum Network net)
|
||||
bool IsReachable(enum Network net)
|
||||
{
|
||||
LOCK(cs_mapLocalHost);
|
||||
return vfLimited[net];
|
||||
return !vfLimited[net];
|
||||
}
|
||||
|
||||
bool IsLimited(const CNetAddr &addr)
|
||||
bool IsReachable(const CNetAddr &addr)
|
||||
{
|
||||
return IsLimited(addr.GetNetwork());
|
||||
return IsReachable(addr.GetNetwork());
|
||||
}
|
||||
|
||||
/** vote for a local address */
|
||||
|
@ -292,19 +291,6 @@ bool IsLocal(const CService& addr)
|
|||
return mapLocalHost.count(addr) > 0;
|
||||
}
|
||||
|
||||
/** check whether a given network is one we can probably connect to */
|
||||
bool IsReachable(enum Network net)
|
||||
{
|
||||
return !IsLimited(net);
|
||||
}
|
||||
|
||||
/** check whether a given address is in a network we can probably connect to */
|
||||
bool IsReachable(const CNetAddr& addr)
|
||||
{
|
||||
return IsReachable(addr.GetNetwork());
|
||||
}
|
||||
|
||||
|
||||
CNode* CConnman::FindNode(const CNetAddr& ip)
|
||||
{
|
||||
LOCK(cs_vNodes);
|
||||
|
@ -1965,7 +1951,7 @@ void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
|
|||
if (nTries > 100)
|
||||
break;
|
||||
|
||||
if (IsLimited(addr))
|
||||
if (!IsReachable(addr))
|
||||
continue;
|
||||
|
||||
// only consider very recently tried nodes after 30 failed attempts
|
||||
|
@ -2327,7 +2313,7 @@ NodeId CConnman::GetNewNodeId()
|
|||
|
||||
|
||||
bool CConnman::Bind(const CService &addr, unsigned int flags) {
|
||||
if (!(flags & BF_EXPLICIT) && IsLimited(addr))
|
||||
if (!(flags & BF_EXPLICIT) && !IsReachable(addr))
|
||||
return false;
|
||||
std::string strError;
|
||||
if (!BindListenPort(addr, strError, (flags & BF_WHITELIST) != 0)) {
|
||||
|
|
16
src/net.h
16
src/net.h
|
@ -520,17 +520,23 @@ enum
|
|||
|
||||
bool IsPeerAddrLocalGood(CNode *pnode);
|
||||
void AdvertiseLocal(CNode *pnode);
|
||||
void SetLimited(enum Network net, bool fLimited = true);
|
||||
bool IsLimited(enum Network net);
|
||||
bool IsLimited(const CNetAddr& addr);
|
||||
|
||||
/**
|
||||
* Mark a network as reachable or unreachable (no automatic connects to it)
|
||||
* @note Networks are reachable by default
|
||||
*/
|
||||
void SetReachable(enum Network net, bool reachable);
|
||||
/** @returns true if the network is reachable, false otherwise */
|
||||
bool IsReachable(enum Network net);
|
||||
/** @returns true if the address is in a reachable network, false otherwise */
|
||||
bool IsReachable(const CNetAddr& addr);
|
||||
|
||||
bool AddLocal(const CService& addr, int nScore = LOCAL_NONE);
|
||||
bool AddLocal(const CNetAddr& addr, int nScore = LOCAL_NONE);
|
||||
void RemoveLocal(const CService& addr);
|
||||
bool SeenLocal(const CService& addr);
|
||||
bool IsLocal(const CService& addr);
|
||||
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = nullptr);
|
||||
bool IsReachable(enum Network net);
|
||||
bool IsReachable(const CNetAddr &addr);
|
||||
CAddress GetLocalAddress(const CNetAddr *paddrPeer, ServiceFlags nLocalServices);
|
||||
|
||||
|
||||
|
|
|
@ -423,7 +423,7 @@ static UniValue GetNetworksInfo()
|
|||
UniValue obj(UniValue::VOBJ);
|
||||
GetProxy(network, proxy);
|
||||
obj.pushKV("name", GetNetworkName(network));
|
||||
obj.pushKV("limited", IsLimited(network));
|
||||
obj.pushKV("limited", !IsReachable(network));
|
||||
obj.pushKV("reachable", IsReachable(network));
|
||||
obj.pushKV("proxy", proxy.IsValid() ? proxy.proxy.ToStringIPPort() : std::string());
|
||||
obj.pushKV("proxy_randomize_credentials", proxy.randomize_credentials);
|
||||
|
|
|
@ -230,26 +230,21 @@ BOOST_AUTO_TEST_CASE(ipv4_peer_with_ipv6_addrMe_test)
|
|||
|
||||
BOOST_AUTO_TEST_CASE(LimitedAndReachable_Network)
|
||||
{
|
||||
SetLimited(NET_IPV4, true);
|
||||
SetLimited(NET_IPV6, true);
|
||||
SetLimited(NET_ONION, true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_IPV4), true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_IPV6), true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_ONION), true);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_IPV4), true);
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_IPV6), true);
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_ONION), true);
|
||||
SetReachable(NET_IPV4, false);
|
||||
SetReachable(NET_IPV6, false);
|
||||
SetReachable(NET_ONION, false);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_IPV4), false);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_IPV6), false);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_ONION), false);
|
||||
|
||||
|
||||
SetLimited(NET_IPV4, false);
|
||||
SetLimited(NET_IPV6, false);
|
||||
SetLimited(NET_ONION, false);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_IPV4), false);
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_IPV6), false);
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_ONION), false);
|
||||
SetReachable(NET_IPV4, true);
|
||||
SetReachable(NET_IPV6, true);
|
||||
SetReachable(NET_ONION, true);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_IPV4), true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_IPV6), true);
|
||||
|
@ -258,19 +253,13 @@ BOOST_AUTO_TEST_CASE(LimitedAndReachable_Network)
|
|||
|
||||
BOOST_AUTO_TEST_CASE(LimitedAndReachable_NetworkCaseUnroutableAndInternal)
|
||||
{
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_UNROUTABLE), false);
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_INTERNAL), false);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_UNROUTABLE), true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_INTERNAL), true);
|
||||
|
||||
SetLimited(NET_UNROUTABLE, true);
|
||||
SetLimited(NET_INTERNAL, true);
|
||||
SetReachable(NET_UNROUTABLE, false);
|
||||
SetReachable(NET_INTERNAL, false);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_UNROUTABLE), false); // Ignored for both networks
|
||||
BOOST_CHECK_EQUAL(IsLimited(NET_INTERNAL), false);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_UNROUTABLE), true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_UNROUTABLE), true); // Ignored for both networks
|
||||
BOOST_CHECK_EQUAL(IsReachable(NET_INTERNAL), true);
|
||||
}
|
||||
|
||||
|
@ -289,15 +278,13 @@ BOOST_AUTO_TEST_CASE(LimitedAndReachable_CNetAddr)
|
|||
{
|
||||
CNetAddr addr = UtilBuildAddress(0x001, 0x001, 0x001, 0x001); // 1.1.1.1
|
||||
|
||||
SetLimited(NET_IPV4, false);
|
||||
BOOST_CHECK_EQUAL(IsLimited(addr), false);
|
||||
SetReachable(NET_IPV4, true);
|
||||
BOOST_CHECK_EQUAL(IsReachable(addr), true);
|
||||
|
||||
SetLimited(NET_IPV4, true);
|
||||
BOOST_CHECK_EQUAL(IsLimited(addr), true);
|
||||
SetReachable(NET_IPV4, false);
|
||||
BOOST_CHECK_EQUAL(IsReachable(addr), false);
|
||||
|
||||
SetLimited(NET_IPV4, false); // have to reset this, because this is stateful.
|
||||
SetReachable(NET_IPV4, true); // have to reset this, because this is stateful.
|
||||
}
|
||||
|
||||
|
||||
|
@ -305,7 +292,7 @@ BOOST_AUTO_TEST_CASE(LocalAddress_BasicLifecycle)
|
|||
{
|
||||
CService addr = CService(UtilBuildAddress(0x002, 0x001, 0x001, 0x001), 1000); // 2.1.1.1:1000
|
||||
|
||||
SetLimited(NET_IPV4, false);
|
||||
SetReachable(NET_IPV4, true);
|
||||
|
||||
BOOST_CHECK_EQUAL(IsLocal(addr), false);
|
||||
BOOST_CHECK_EQUAL(AddLocal(addr, 1000), true);
|
||||
|
|
|
@ -527,7 +527,7 @@ void TorController::auth_cb(TorControlConnection& _conn, const TorControlReply&
|
|||
CService resolved(LookupNumeric("127.0.0.1", 9050));
|
||||
proxyType addrOnion = proxyType(resolved, true);
|
||||
SetProxy(NET_ONION, addrOnion);
|
||||
SetLimited(NET_ONION, false);
|
||||
SetReachable(NET_ONION, true);
|
||||
}
|
||||
|
||||
// Finally - now create the service
|
||||
|
|
Loading…
Reference in a new issue