Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche.cpp
Show First 20 Lines • Show All 126 Lines • ▼ Show 20 Lines | static bool IsWorthPolling(const CBlockIndex *pindex) { | ||||
return true; | return true; | ||||
} | } | ||||
AvalancheProcessor::AvalancheProcessor(CConnman *connmanIn) | AvalancheProcessor::AvalancheProcessor(CConnman *connmanIn) | ||||
: connman(connmanIn), | : connman(connmanIn), | ||||
queryTimeoutDuration( | queryTimeoutDuration( | ||||
AVALANCHE_DEFAULT_QUERY_TIMEOUT_DURATION_MILLISECONDS), | AVALANCHE_DEFAULT_QUERY_TIMEOUT_DURATION_MILLISECONDS), | ||||
round(0), stopRequest(false), running(false) { | round(0) { | ||||
// Pick a random key for the session. | // Pick a random key for the session. | ||||
sessionKey.MakeNewKey(true); | sessionKey.MakeNewKey(true); | ||||
} | } | ||||
AvalancheProcessor::~AvalancheProcessor() { | AvalancheProcessor::~AvalancheProcessor() { | ||||
stopEventLoop(); | stopEventLoop(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Lines | CPubKey AvalancheProcessor::getPubKey(NodeId nodeid) const { | ||||
if (it == r->end()) { | if (it == r->end()) { | ||||
return CPubKey(); | return CPubKey(); | ||||
} | } | ||||
return it->pubkey; | return it->pubkey; | ||||
} | } | ||||
bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | ||||
LOCK(cs_running); | return eventLoop.startEventLoop( | ||||
if (running) { | scheduler, [this]() { this->runEventLoop(); }, | ||||
// Do not start the event loop twice. | |||||
return false; | |||||
} | |||||
running = true; | |||||
// Start the event loop. | |||||
scheduler.scheduleEvery( | |||||
[this]() -> bool { | |||||
runEventLoop(); | |||||
if (!stopRequest) { | |||||
return true; | |||||
} | |||||
LOCK(cs_running); | |||||
running = false; | |||||
cond_running.notify_all(); | |||||
// A stop request was made. | |||||
return false; | |||||
}, | |||||
AVALANCHE_TIME_STEP_MILLISECONDS); | AVALANCHE_TIME_STEP_MILLISECONDS); | ||||
return true; | |||||
} | } | ||||
bool AvalancheProcessor::stopEventLoop() { | bool AvalancheProcessor::stopEventLoop() { | ||||
WAIT_LOCK(cs_running, lock); | return eventLoop.stopEventLoop(); | ||||
if (!running) { | |||||
return false; | |||||
} | |||||
// Request avalanche to stop. | |||||
stopRequest = true; | |||||
// Wait for avalanche to stop. | |||||
cond_running.wait(lock, [this]() EXCLUSIVE_LOCKS_REQUIRED(cs_running) { | |||||
return !running; | |||||
}); | |||||
stopRequest = false; | |||||
return true; | |||||
} | } | ||||
std::vector<CInv> AvalancheProcessor::getInvsForNextPoll(bool forPoll) const { | std::vector<CInv> AvalancheProcessor::getInvsForNextPoll(bool forPoll) const { | ||||
std::vector<CInv> invs; | std::vector<CInv> invs; | ||||
auto r = vote_records.getReadView(); | auto r = vote_records.getReadView(); | ||||
for (const std::pair<const CBlockIndex *const, VoteRecord> &p : | for (const std::pair<const CBlockIndex *const, VoteRecord> &p : | ||||
reverse_iterate(r)) { | reverse_iterate(r)) { | ||||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |