Browse Source

Remove vfReachable and modify IsReachable to only use vfLimited.

We do not know that a class of Network is reachable, only that it is not.
0.13
Patrick Strateman 9 years ago
parent
commit
110b62f069
  1. 7
      src/init.cpp
  2. 12
      src/net.cpp
  3. 1
      src/net.h
  4. 2
      src/torcontrol.cpp

7
src/init.cpp

@ -1199,6 +1199,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// -proxy sets a proxy for all outgoing network traffic // -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 // -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 = GetArg("-proxy", ""); std::string proxyArg = GetArg("-proxy", "");
SetLimited(NET_TOR);
if (proxyArg != "" && proxyArg != "0") { if (proxyArg != "" && proxyArg != "0") {
proxyType addrProxy = proxyType(CService(proxyArg, 9050), proxyRandomize); proxyType addrProxy = proxyType(CService(proxyArg, 9050), proxyRandomize);
if (!addrProxy.IsValid()) if (!addrProxy.IsValid())
@ -1208,7 +1209,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
SetProxy(NET_IPV6, addrProxy); SetProxy(NET_IPV6, addrProxy);
SetProxy(NET_TOR, addrProxy); SetProxy(NET_TOR, addrProxy);
SetNameProxy(addrProxy); SetNameProxy(addrProxy);
SetReachable(NET_TOR); // by default, -proxy sets onion as reachable, unless -noonion later SetLimited(NET_TOR, false); // 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 // -onion can be used to set only a proxy for .onion, or override normal proxy for .onion addresses
@ -1217,13 +1218,13 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
std::string onionArg = GetArg("-onion", ""); std::string onionArg = GetArg("-onion", "");
if (onionArg != "") { if (onionArg != "") {
if (onionArg == "0") { // Handle -noonion/-onion=0 if (onionArg == "0") { // Handle -noonion/-onion=0
SetReachable(NET_TOR, false); // set onions as unreachable SetLimited(NET_TOR); // set onions as unreachable
} else { } else {
proxyType addrOnion = proxyType(CService(onionArg, 9050), proxyRandomize); proxyType addrOnion = proxyType(CService(onionArg, 9050), proxyRandomize);
if (!addrOnion.IsValid()) if (!addrOnion.IsValid())
return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg)); return InitError(strprintf(_("Invalid -onion address: '%s'"), onionArg));
SetProxy(NET_TOR, addrOnion); SetProxy(NET_TOR, addrOnion);
SetReachable(NET_TOR); SetLimited(NET_TOR, false);
} }
} }

12
src/net.cpp

@ -79,7 +79,6 @@ bool fListen = true;
uint64_t nLocalServices = NODE_NETWORK; uint64_t nLocalServices = NODE_NETWORK;
CCriticalSection cs_mapLocalHost; CCriticalSection cs_mapLocalHost;
map<CNetAddr, LocalServiceInfo> mapLocalHost; map<CNetAddr, LocalServiceInfo> mapLocalHost;
static bool vfReachable[NET_MAX] = {};
static bool vfLimited[NET_MAX] = {}; static bool vfLimited[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL; static CNode* pnodeLocalHost = NULL;
uint64_t nLocalHostNonce = 0; uint64_t nLocalHostNonce = 0;
@ -226,14 +225,6 @@ void AdvertiseLocal(CNode *pnode)
} }
} }
void SetReachable(enum Network net, bool fFlag)
{
LOCK(cs_mapLocalHost);
vfReachable[net] = fFlag;
if (net == NET_IPV6 && fFlag)
vfReachable[NET_IPV4] = true;
}
// learn a new local address // learn a new local address
bool AddLocal(const CService& addr, int nScore) bool AddLocal(const CService& addr, int nScore)
{ {
@ -256,7 +247,6 @@ bool AddLocal(const CService& addr, int nScore)
info.nScore = nScore + (fAlready ? 1 : 0); info.nScore = nScore + (fAlready ? 1 : 0);
info.nPort = addr.GetPort(); info.nPort = addr.GetPort();
} }
SetReachable(addr.GetNetwork());
} }
return true; return true;
@ -319,7 +309,7 @@ bool IsLocal(const CService& addr)
bool IsReachable(enum Network net) bool IsReachable(enum Network net)
{ {
LOCK(cs_mapLocalHost); LOCK(cs_mapLocalHost);
return vfReachable[net] && !vfLimited[net]; return !vfLimited[net];
} }
/** check whether a given address is in a network we can probably connect to */ /** check whether a given address is in a network we can probably connect to */

1
src/net.h

@ -146,7 +146,6 @@ bool IsLocal(const CService& addr);
bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL); bool GetLocal(CService &addr, const CNetAddr *paddrPeer = NULL);
bool IsReachable(enum Network net); bool IsReachable(enum Network net);
bool IsReachable(const CNetAddr &addr); bool IsReachable(const CNetAddr &addr);
void SetReachable(enum Network net, bool fFlag = true);
CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL); CAddress GetLocalAddress(const CNetAddr *paddrPeer = NULL);

2
src/torcontrol.cpp

@ -459,7 +459,7 @@ void TorController::auth_cb(TorControlConnection& conn, const TorControlReply& r
if (GetArg("-onion", "") == "") { if (GetArg("-onion", "") == "") {
proxyType addrOnion = proxyType(CService("127.0.0.1", 9050), true); proxyType addrOnion = proxyType(CService("127.0.0.1", 9050), true);
SetProxy(NET_TOR, addrOnion); SetProxy(NET_TOR, addrOnion);
SetReachable(NET_TOR); SetLimited(NET_TOR, false);
} }
// Finally - now create the service // Finally - now create the service

Loading…
Cancel
Save