Changeset View
Changeset View
Standalone View
Standalone View
src/addrman.cpp
Show First 20 Lines • Show All 260 Lines • ▼ Show 20 Lines | void CAddrMan::Good_(const CService &addr, bool test_before_evict, | ||||
} | } | ||||
// which tried bucket to move the entry to | // which tried bucket to move the entry to | ||||
int tried_bucket = info.GetTriedBucket(nKey); | int tried_bucket = info.GetTriedBucket(nKey); | ||||
int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket); | int tried_bucket_pos = info.GetBucketPosition(nKey, false, tried_bucket); | ||||
// Will moving this address into tried evict another entry? | // Will moving this address into tried evict another entry? | ||||
if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) { | if (test_before_evict && (vvTried[tried_bucket][tried_bucket_pos] != -1)) { | ||||
// Output the entry we'd be colliding with, for debugging purposes | |||||
auto colliding_entry = | |||||
mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]); | |||||
LogPrint(BCLog::ADDRMAN, | LogPrint(BCLog::ADDRMAN, | ||||
"Collision inserting element into tried table, moving %s to " | "Collision inserting element into tried table (%s), moving %s " | ||||
"m_tried_collisions=%d\n", | "to m_tried_collisions=%d\n", | ||||
colliding_entry != mapInfo.end() | |||||
? colliding_entry->second.ToString() | |||||
: "", | |||||
addr.ToString(), m_tried_collisions.size()); | addr.ToString(), m_tried_collisions.size()); | ||||
if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) { | if (m_tried_collisions.size() < ADDRMAN_SET_TRIED_COLLISION_SIZE) { | ||||
m_tried_collisions.insert(nId); | m_tried_collisions.insert(nId); | ||||
} | } | ||||
} else { | } else { | ||||
LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString()); | LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString()); | ||||
// move nId to the tried tables | // move nId to the tried tables | ||||
▲ Show 20 Lines • Show All 373 Lines • ▼ Show 20 Lines | for (std::set<int>::iterator it = m_tried_collisions.begin(); | ||||
erase_collision = true; | erase_collision = true; | ||||
} else if (adjustedTime - info_old.nLastTry < | } else if (adjustedTime - info_old.nLastTry < | ||||
ADDRMAN_REPLACEMENT_SECONDS) { | ADDRMAN_REPLACEMENT_SECONDS) { | ||||
// attempted to connect and failed in last X hours | // attempted to connect and failed in last X hours | ||||
// Give address at least 60 seconds to successfully connect | // Give address at least 60 seconds to successfully connect | ||||
if (GetAdjustedTime() - info_old.nLastTry > 60) { | if (GetAdjustedTime() - info_old.nLastTry > 60) { | ||||
LogPrint(BCLog::ADDRMAN, | LogPrint(BCLog::ADDRMAN, | ||||
"Swapping %s for %s in tried table\n", | "Replacing %s with %s in tried table\n", | ||||
info_new.ToString(), info_old.ToString()); | info_old.ToString(), info_new.ToString()); | ||||
// Replaces an existing address already in the tried | // Replaces an existing address already in the tried | ||||
// table with the new address | // table with the new address | ||||
Good_(info_new, false, GetAdjustedTime()); | Good_(info_new, false, GetAdjustedTime()); | ||||
erase_collision = true; | erase_collision = true; | ||||
} | } | ||||
} else if (GetAdjustedTime() - info_new.nLastSuccess > | |||||
ADDRMAN_TEST_WINDOW) { | |||||
// If the collision hasn't resolved in some reasonable | |||||
// amount of time, just evict the old entry -- we must not | |||||
// be able to connect to it for some reason. | |||||
LogPrint(BCLog::ADDRMAN, | |||||
"Unable to test; replacing %s with %s in tried " | |||||
"table anyway\n", | |||||
info_old.ToString(), info_new.ToString()); | |||||
Good_(info_new, false, GetAdjustedTime()); | |||||
erase_collision = true; | |||||
} | } | ||||
} else { | } else { | ||||
// Collision is not actually a collision anymore | // Collision is not actually a collision anymore | ||||
Good_(info_new, false, adjustedTime); | Good_(info_new, false, adjustedTime); | ||||
erase_collision = true; | erase_collision = true; | ||||
} | } | ||||
} | } | ||||
Show All 36 Lines |