Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/processor.cpp
Show First 20 Lines • Show All 227 Lines • ▼ Show 20 Lines | |||||
bool AvalancheProcessor::registerVotes( | bool AvalancheProcessor::registerVotes( | ||||
NodeId nodeid, const AvalancheResponse &response, | NodeId nodeid, const AvalancheResponse &response, | ||||
std::vector<AvalancheBlockUpdate> &updates) { | std::vector<AvalancheBlockUpdate> &updates) { | ||||
{ | { | ||||
// Save the time at which we can query again. | // Save the time at which we can query again. | ||||
auto w = peerSet.getWriteView(); | auto w = peerSet.getWriteView(); | ||||
auto it = w->find(nodeid); | auto it = w->find(nodeid); | ||||
if (it != w->end()) { | if (it != w->end()) { | ||||
w->modify(it, [&response](Node &n) { | w->modify(it, [&response](AvalancheNode &n) { | ||||
// FIXME: This will override the time even when we received an | // FIXME: This will override the time even when we received an | ||||
// old stale message. This should check that the message is | // old stale message. This should check that the message is | ||||
// indeed the most up to date one before updating the time. | // indeed the most up to date one before updating the time. | ||||
n.nextRequestTime = | n.nextRequestTime = | ||||
std::chrono::steady_clock::now() + | std::chrono::steady_clock::now() + | ||||
std::chrono::milliseconds(response.getCooldown()); | std::chrono::milliseconds(response.getCooldown()); | ||||
}); | }); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | |||||
bool AvalancheProcessor::addPeer(NodeId nodeid, int64_t score, CPubKey pubkey) { | bool AvalancheProcessor::addPeer(NodeId nodeid, int64_t score, CPubKey pubkey) { | ||||
return peerSet.getWriteView() | return peerSet.getWriteView() | ||||
->insert({nodeid, score, std::chrono::steady_clock::now(), | ->insert({nodeid, score, std::chrono::steady_clock::now(), | ||||
std::move(pubkey)}) | std::move(pubkey)}) | ||||
.second; | .second; | ||||
} | } | ||||
bool AvalancheProcessor::forNode( | bool AvalancheProcessor::forNode( | ||||
NodeId nodeid, std::function<bool(const Node &n)> func) const { | NodeId nodeid, std::function<bool(const AvalancheNode &n)> func) const { | ||||
auto r = peerSet.getReadView(); | auto r = peerSet.getReadView(); | ||||
auto it = r->find(nodeid); | auto it = r->find(nodeid); | ||||
return it != r->end() && func(*it); | return it != r->end() && func(*it); | ||||
} | } | ||||
bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | bool AvalancheProcessor::startEventLoop(CScheduler &scheduler) { | ||||
return eventLoop.startEventLoop( | return eventLoop.startEventLoop( | ||||
scheduler, [this]() { this->runEventLoop(); }, AVALANCHE_TIME_STEP); | scheduler, [this]() { this->runEventLoop(); }, AVALANCHE_TIME_STEP); | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | do { | ||||
std::chrono::steady_clock::now() + queryTimeoutDuration; | std::chrono::steady_clock::now() + queryTimeoutDuration; | ||||
// Register the query. | // Register the query. | ||||
queries.getWriteView()->insert( | queries.getWriteView()->insert( | ||||
{pnode->GetId(), current_round, timeout, invs}); | {pnode->GetId(), current_round, timeout, invs}); | ||||
// Set the timeout. | // Set the timeout. | ||||
auto w = peerSet.getWriteView(); | auto w = peerSet.getWriteView(); | ||||
auto it = w->find(pnode->GetId()); | auto it = w->find(pnode->GetId()); | ||||
if (it != w->end()) { | if (it != w->end()) { | ||||
w->modify(it, [&timeout](Node &n) { | w->modify(it, [&timeout](AvalancheNode &n) { | ||||
n.nextRequestTime = timeout; | n.nextRequestTime = timeout; | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
// Send the query to the node. | // Send the query to the node. | ||||
connman->PushMessage( | connman->PushMessage( | ||||
pnode, | pnode, | ||||
Show All 18 Lines |