Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 96 Lines • ▼ Show 20 Lines | bool PeerManager::addNodeToPeer(PeerId peerid, NodeId nodeid, CPubKey pubkey) { | ||||
} | } | ||||
auto nit = nodes.find(nodeid); | auto nit = nodes.find(nodeid); | ||||
if (nit == nodes.end()) { | if (nit == nodes.end()) { | ||||
return nodes.emplace(nodeid, peerid, std::move(pubkey)).second; | return nodes.emplace(nodeid, peerid, std::move(pubkey)).second; | ||||
} | } | ||||
// We actually have this node already, we need to update it. | // We actually have this node already, we need to update it. | ||||
return nodes.modify(nit, [&](Node &n) { | return nodes.modify(nit, [&](AvalancheNode &n) { | ||||
n.peerid = peerid; | n.peerid = peerid; | ||||
n.pubkey = std::move(pubkey); | n.pubkey = std::move(pubkey); | ||||
}); | }); | ||||
} | } | ||||
bool PeerManager::removeNode(NodeId nodeid) { | bool PeerManager::removeNode(NodeId nodeid) { | ||||
return nodes.erase(nodeid) > 0; | return nodes.erase(nodeid) > 0; | ||||
} | } | ||||
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, | ||||
[&](AvalancheNode &n) { n.nextRequestTime = timeout; }); | |||||
} | } | ||||
NodeId PeerManager::getSuitableNodeToQuery() { | NodeId PeerManager::getSuitableNodeToQuery() { | ||||
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 162 Lines • Show Last 20 Lines |