Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | bool PeerManager::removeNode(NodeId nodeid) { | ||||
bool success = removeNodeFromPeer(peers.find(peerid)); | bool success = removeNodeFromPeer(peers.find(peerid)); | ||||
assert(success); | assert(success); | ||||
return true; | return true; | ||||
} | } | ||||
bool PeerManager::removeNodeFromPeer(const PeerSet::iterator &it, | bool PeerManager::removeNodeFromPeer(const PeerSet::iterator &it, | ||||
uint32_t count) { | uint32_t count) { | ||||
assert(it != peers.end()); | // It is possible for nodes to be dangling. If there was an inflight query | ||||
// when the peer gets removed, the node was not erased. In this case there | |||||
// is nothing to do. | |||||
if (it == peers.end()) { | |||||
return true; | |||||
} | |||||
assert(count <= it->node_count); | assert(count <= it->node_count); | ||||
if (count == 0) { | if (count == 0) { | ||||
// This is a NOOP. | // This is a NOOP. | ||||
return false; | return false; | ||||
} | } | ||||
const uint32_t new_count = it->node_count - count; | const uint32_t new_count = it->node_count - count; | ||||
if (!peers.modify(it, [&](Peer &p) { p.node_count = new_count; })) { | if (!peers.modify(it, [&](Peer &p) { p.node_count = new_count; })) { | ||||
▲ Show 20 Lines • Show All 404 Lines • Show Last 20 Lines |