Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | bool PeerManager::removeNodeFromPeer(const PeerSet::iterator &it, | ||||
} else { | } else { | ||||
fragmentation += slots[i].getScore(); | fragmentation += slots[i].getScore(); | ||||
slots[i] = slots[i].withPeerId(NO_PEER); | slots[i] = slots[i].withPeerId(NO_PEER); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool PeerManager::forNode(NodeId nodeid, | |||||
std::function<bool(const Node &n)> func) const { | |||||
auto it = nodes.find(nodeid); | |||||
return it != nodes.end() && func(*it); | |||||
} | |||||
bool PeerManager::updateNextRequestTime(NodeId nodeid, TimePoint timeout) { | bool PeerManager::updateNextRequestTime(NodeId nodeid, TimePoint timeout) { | ||||
auto it = nodes.find(nodeid); | auto it = nodes.find(nodeid); | ||||
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; }); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 333 Lines • ▼ Show 20 Lines | for (size_t i = begin; i < end; i++) { | ||||
return slots[i].getPeerId(); | return slots[i].getPeerId(); | ||||
} | } | ||||
} | } | ||||
// We failed to find a slot, retry. | // We failed to find a slot, retry. | ||||
return NO_PEER; | return NO_PEER; | ||||
} | } | ||||
std::vector<Peer> PeerManager::getPeers() const { | |||||
std::vector<Peer> vpeers; | |||||
for (auto &it : peers.get<0>()) { | |||||
vpeers.emplace_back(it); | |||||
} | |||||
return vpeers; | |||||
} | |||||
std::vector<NodeId> PeerManager::getNodeIdsForPeer(PeerId peerId) const { | |||||
std::vector<NodeId> nodeids; | |||||
auto &nview = nodes.get<next_request_time>(); | |||||
auto nodeRange = nview.equal_range(peerId); | |||||
for (auto it = nodeRange.first; it != nodeRange.second; ++it) { | |||||
nodeids.emplace_back(it->nodeid); | |||||
} | |||||
return nodeids; | |||||
} | |||||
bool PeerManager::isOrphan(const ProofId &id) const { | bool PeerManager::isOrphan(const ProofId &id) const { | ||||
return orphanProofs.getProof(id) != nullptr; | return orphanProofs.getProof(id) != nullptr; | ||||
} | } | ||||
std::shared_ptr<Proof> PeerManager::getOrphan(const ProofId &id) const { | std::shared_ptr<Proof> PeerManager::getOrphan(const ProofId &id) const { | ||||
return orphanProofs.getProof(id); | return orphanProofs.getProof(id); | ||||
} | } | ||||
Show All 25 Lines |