aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-04-10 20:22:04 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-11 15:29:19 +0200
commit090e5b40f1b3ac9ac6209f8996da4d686686a2ac (patch)
treec26367aef8abd697b3f035e2340dcb407cd3424f /src/net.cpp
parentd32148567f5866a7cd2a77a2f44f846134011c9c (diff)
downloadbitcoin-090e5b40f1b3ac9ac6209f8996da4d686686a2ac.tar.xz
Limited relaying/storing of foreign addresses
Introduce a boolean variable for each "network" (ipv4, ipv6, tor, i2p), and track whether we are likely to able to connect to it. Addresses in "addr" messages outside of our network get limited relaying and are not stored in addrman.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 75c8bbabaf..d407e66420 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -45,8 +45,9 @@ bool OpenNetworkConnection(const CAddress& addrConnect, const char *strDest = NU
bool fClient = false;
static bool fUseUPnP = false;
uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK);
-CCriticalSection cs_mapLocalHost;
-map<CNetAddr, int> mapLocalHost;
+static CCriticalSection cs_mapLocalHost;
+static map<CNetAddr, int> mapLocalHost;
+static bool vfReachable[NET_MAX] = {};
static CNode* pnodeLocalHost = NULL;
uint64 nLocalHostNonce = 0;
array<int, THREAD_MAX> vnThreadsRunning;
@@ -214,6 +215,9 @@ bool AddLocal(const CNetAddr& addr, int nScore)
{
LOCK(cs_mapLocalHost);
mapLocalHost[addr] = std::max(nScore, mapLocalHost[addr]) + (mapLocalHost.count(addr) ? 1 : 0);
+ enum Network net = addr.GetNetwork();
+ vfReachable[net] = true;
+ if (net == NET_IPV6) vfReachable[NET_IPV4] = true;
}
AdvertizeLocal();
@@ -243,6 +247,12 @@ bool IsLocal(const CNetAddr& addr)
return mapLocalHost.count(addr) > 0;
}
+// check whether a given address is in a network we can probably connect to
+bool IsReachable(const CNetAddr& addr)
+{
+ LOCK(cs_mapLocalHost);
+ return vfReachable[addr.GetNetwork()];
+}
bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const char* pszKeyword, CNetAddr& ipRet)
{