mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-02-05 11:24:19 +00:00
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
This commit is contained in:
parent
29a86a1735
commit
56f1e91239
@ -130,6 +130,7 @@ int CAddrMan::SelectTried(int nKBucket)
|
|||||||
// random shuffle the first few elements (using the entire list)
|
// random shuffle the first few elements (using the entire list)
|
||||||
// find the least recently tried among them
|
// find the least recently tried among them
|
||||||
int64 nOldest = -1;
|
int64 nOldest = -1;
|
||||||
|
int nOldestPos = -1;
|
||||||
for (unsigned int i = 0; i < ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT && i < vTried.size(); i++)
|
for (unsigned int i = 0; i < ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT && i < vTried.size(); i++)
|
||||||
{
|
{
|
||||||
int nPos = GetRandInt(vTried.size() - i) + i;
|
int nPos = GetRandInt(vTried.size() - i) + i;
|
||||||
@ -137,11 +138,13 @@ int CAddrMan::SelectTried(int nKBucket)
|
|||||||
vTried[nPos] = vTried[i];
|
vTried[nPos] = vTried[i];
|
||||||
vTried[i] = nTemp;
|
vTried[i] = nTemp;
|
||||||
assert(nOldest == -1 || mapInfo.count(nTemp) == 1);
|
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;
|
nOldest = nTemp;
|
||||||
|
nOldestPos = nPos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nOldest;
|
return nOldestPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAddrMan::ShrinkNew(int nUBucket)
|
int CAddrMan::ShrinkNew(int nUBucket)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user