Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | bool PeerManager::updateNextRequestTime(NodeId nodeid, TimePoint timeout) { | ||||
if (it == nodes.end()) { | if (it == nodes.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
return nodes.modify(it, [&](Node &n) { n.nextRequestTime = timeout; }); | return nodes.modify(it, [&](Node &n) { n.nextRequestTime = timeout; }); | ||||
} | } | ||||
bool PeerManager::registerProof(const ProofRef &proof) { | bool PeerManager::registerProof(const ProofRef &proof) { | ||||
return !exists(proof->getId()) && getPeerId(proof) != NO_PEER; | return !exists(proof->getId()) && fetchOrCreatePeer(proof) != peers.end(); | ||||
} | } | ||||
NodeId PeerManager::selectNode() { | NodeId PeerManager::selectNode() { | ||||
for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | for (int retry = 0; retry < SELECT_NODE_MAX_RETRY; retry++) { | ||||
const PeerId p = selectPeer(); | const PeerId p = selectPeer(); | ||||
// If we cannot find a peer, it may be due to the fact that it is | // If we cannot find a peer, it may be due to the fact that it is | ||||
// unlikely due to high fragmentation, so compact and retry. | // unlikely due to high fragmentation, so compact and retry. | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | void PeerManager::updatedBlockTip() { | ||||
orphanProofs.rescan(*this); | orphanProofs.rescan(*this); | ||||
for (auto &p : newOrphans) { | for (auto &p : newOrphans) { | ||||
orphanProofs.addProof(p); | orphanProofs.addProof(p); | ||||
} | } | ||||
} | } | ||||
PeerId PeerManager::getPeerId(const ProofRef &proof) { | |||||
auto it = fetchOrCreatePeer(proof); | |||||
return it == peers.end() ? NO_PEER : it->peerid; | |||||
} | |||||
ProofRef PeerManager::getProof(const ProofId &proofid) const { | ProofRef PeerManager::getProof(const ProofId &proofid) const { | ||||
ProofRef proof = nullptr; | ProofRef proof = nullptr; | ||||
forPeer(proofid, [&](const Peer &p) { | forPeer(proofid, [&](const Peer &p) { | ||||
proof = p.proof; | proof = p.proof; | ||||
return true; | return true; | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 378 Lines • Show Last 20 Lines |