aboutsummaryrefslogtreecommitdiff
path: root/src/addrman.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-05-05 21:22:55 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2012-05-05 21:33:26 +0200
commit56f1e912397de656988cf7898b5457892bce3c30 (patch)
treeb7e4893c5635ee53a24630b6c8211bad9829b51c /src/addrman.cpp
parent29a86a17350b931c2b46aebd05ab99ada0b8494c (diff)
downloadbitcoin-56f1e912397de656988cf7898b5457892bce3c30.tar.xz
Fix addrman crashes
A function returned the element to remove from a bucket, instead of its position in that bucket. This function was only called when a tried bucket overflowed, which only happens after many outgoing connections have been made. Closes: #1065, #1156
Diffstat (limited to 'src/addrman.cpp')
-rw-r--r--src/addrman.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/addrman.cpp b/src/addrman.cpp
index c1a0df6a44..10d005aae9 100644
--- a/src/addrman.cpp
+++ b/src/addrman.cpp
@@ -130,6 +130,7 @@ int CAddrMan::SelectTried(int nKBucket)
// random shuffle the first few elements (using the entire list)
// find the least recently tried among them
int64 nOldest = -1;
+ int nOldestPos = -1;
for (unsigned int i = 0; i < ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT && i < vTried.size(); i++)
{
int nPos = GetRandInt(vTried.size() - i) + i;
@@ -137,11 +138,13 @@ int CAddrMan::SelectTried(int nKBucket)
vTried[nPos] = vTried[i];
vTried[i] = nTemp;
assert(nOldest == -1 || mapInfo.count(nTemp) == 1);
- if (nOldest == -1 || mapInfo[nTemp].nLastSuccess < mapInfo[nOldest].nLastSuccess)
+ if (nOldest == -1 || mapInfo[nTemp].nLastSuccess < mapInfo[nOldest].nLastSuccess) {
nOldest = nTemp;
+ nOldestPos = nPos;
+ }
}
- return nOldest;
+ return nOldestPos;
}
int CAddrMan::ShrinkNew(int nUBucket)