aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatt Corallo <git@bluematt.me>2013-03-27 19:45:43 -0400
committerMatt Corallo <git@bluematt.me>2013-04-01 11:56:23 -0400
commitb5afda67f2846ddc6554304acc1567796733725b (patch)
treee98486aeeba72e420d3229a136d841c4735b1246 /src
parent5ffc299404f4bcce3b9b2522096f8ed53d3181d5 (diff)
Move mapAlreadyAskedFor to limitedmap
This will result in re-requesting invs if we are under heavy inv load, however as long as we get no more than 16,000 invs in two minutes, this should have no effect on runtime behavior.
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp2
-rw-r--r--src/net.h14
2 files changed, 13 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 9ee6cb423c..926d570264 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -63,7 +63,7 @@ CCriticalSection cs_vNodes;
map<CInv, CDataStream> mapRelay;
deque<pair<int64, CInv> > vRelayExpiration;
CCriticalSection cs_mapRelay;
-map<CInv, int64> mapAlreadyAskedFor;
+limitedmap<CInv, int64> mapAlreadyAskedFor(MAX_INV_SZ);
static deque<string> vOneShots;
CCriticalSection cs_vOneShots;
diff --git a/src/net.h b/src/net.h
index 368e4cd4bb..9cbb593f56 100644
--- a/src/net.h
+++ b/src/net.h
@@ -15,6 +15,7 @@
#endif
#include "mruset.h"
+#include "limitedmap.h"
#include "netbase.h"
#include "protocol.h"
#include "addrman.h"
@@ -100,7 +101,7 @@ extern CCriticalSection cs_vNodes;
extern std::map<CInv, CDataStream> mapRelay;
extern std::deque<std::pair<int64, CInv> > vRelayExpiration;
extern CCriticalSection cs_mapRelay;
-extern std::map<CInv, int64> mapAlreadyAskedFor;
+extern limitedmap<CInv, int64> mapAlreadyAskedFor;
extern std::vector<std::string> vAddedNodes;
extern CCriticalSection cs_vAddedNodes;
@@ -367,7 +368,12 @@ public:
{
// We're using mapAskFor as a priority queue,
// the key is the earliest time the request can be sent
- int64& nRequestTime = mapAlreadyAskedFor[inv];
+ int64 nRequestTime;
+ limitedmap<CInv, int64>::const_iterator it = mapAlreadyAskedFor.find(inv);
+ if (it != mapAlreadyAskedFor.end())
+ nRequestTime = it->second;
+ else
+ nRequestTime = 0;
if (fDebugNet)
printf("askfor %s %"PRI64d" (%s)\n", inv.ToString().c_str(), nRequestTime, DateTimeStrFormat("%H:%M:%S", nRequestTime/1000000).c_str());
@@ -380,6 +386,10 @@ public:
// Each retry is 2 minutes after the last
nRequestTime = std::max(nRequestTime + 2 * 60 * 1000000, nNow);
+ if (it != mapAlreadyAskedFor.end())
+ mapAlreadyAskedFor.update(it, nRequestTime);
+ else
+ mapAlreadyAskedFor.insert(std::make_pair(inv, nRequestTime));
mapAskFor.insert(std::make_pair(nRequestTime, inv));
}