Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show First 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | NodeId AvalancheProcessor::getSuitableNodeToQuery() { | ||||
if (it->nextRequestTime <= std::chrono::steady_clock::now()) { | if (it->nextRequestTime <= std::chrono::steady_clock::now()) { | ||||
return it->nodeid; | return it->nodeid; | ||||
} | } | ||||
return NO_NODE; | return NO_NODE; | ||||
} | } | ||||
void AvalancheProcessor::runEventLoop() { | void AvalancheProcessor::clearTimedoutRequests() { | ||||
auto now = std::chrono::steady_clock::now(); | auto now = std::chrono::steady_clock::now(); | ||||
{ | |||||
// Clear expired requests. | // Clear expired requests. | ||||
auto w = queries.getWriteView(); | auto w = queries.getWriteView(); | ||||
auto it = w->get<query_timeout>().begin(); | auto it = w->get<query_timeout>().begin(); | ||||
while (it != w->get<query_timeout>().end() && it->timeout < now) { | while (it != w->get<query_timeout>().end() && it->timeout < now) { | ||||
w->get<query_timeout>().erase(it++); | w->get<query_timeout>().erase(it++); | ||||
} | } | ||||
} | } | ||||
void AvalancheProcessor::runEventLoop() { | |||||
// First things first, check if we have requests that timed out and clear | |||||
// them. | |||||
clearTimedoutRequests(); | |||||
std::vector<CInv> invs = getInvsForNextPoll(); | std::vector<CInv> invs = getInvsForNextPoll(); | ||||
if (invs.empty()) { | if (invs.empty()) { | ||||
// If there are no invs to poll, we are done. | // If there are no invs to poll, we are done. | ||||
return; | return; | ||||
} | } | ||||
while (true) { | while (true) { | ||||
NodeId nodeid = getSuitableNodeToQuery(); | NodeId nodeid = getSuitableNodeToQuery(); | ||||
▲ Show 20 Lines • Show All 47 Lines • Show Last 20 Lines |