aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-04-03 18:31:35 -0700
committerGavin Andresen <gavinandresen@gmail.com>2013-04-03 18:31:35 -0700
commitaaf47eac3abef5741b6c108fdc8a19cb46b773a2 (patch)
tree287dffec550319b4fb6d662d61768862ac410de1 /src/net.h
parentf7955fafbd22849b50500d04640a2ebacd9fb976 (diff)
parentb5afda67f2846ddc6554304acc1567796733725b (diff)
Merge pull request #2423 from TheBlueMatt/limitedmapalreadyaskedfor
Limited mapAlreadyAskedFor
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/net.h b/src/net.h
index 65e83f909c..30b9ac8663 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"
@@ -79,7 +80,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;
@@ -346,7 +347,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());
@@ -359,6 +365,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));
}