Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show All 34 Lines | if (nit == nodes.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
} else { | } else { | ||||
const PeerId oldpeerid = nit->peerid; | const PeerId oldpeerid = nit->peerid; | ||||
if (!nodes.modify(nit, [&](Node &n) { n.peerid = peerid; })) { | if (!nodes.modify(nit, [&](Node &n) { n.peerid = peerid; })) { | ||||
return false; | return false; | ||||
} | } | ||||
// It is possible for the node to be dangling. If there was an inflight | |||||
// query when the peer gets removed, the node was not erased. | |||||
auto oldpeer_it = peers.find(oldpeerid); | |||||
if (oldpeer_it != peers.end()) { | |||||
// We actually have this node already, we need to update it. | // We actually have this node already, we need to update it. | ||||
bool success = removeNodeFromPeer(peers.find(oldpeerid)); | bool success = removeNodeFromPeer(oldpeer_it); | ||||
assert(success); | assert(success); | ||||
} | } | ||||
} | |||||
bool success = addNodeToPeer(it); | bool success = addNodeToPeer(it); | ||||
assert(success); | assert(success); | ||||
return true; | return true; | ||||
} | } | ||||
bool PeerManager::addNodeToPeer(const PeerSet::iterator &it) { | bool PeerManager::addNodeToPeer(const PeerSet::iterator &it) { | ||||
Show All 18 Lines | bool PeerManager::removeNode(NodeId nodeid) { | ||||
if (it == nodes.end()) { | if (it == nodes.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
const PeerId peerid = it->peerid; | const PeerId peerid = it->peerid; | ||||
nodes.erase(it); | nodes.erase(it); | ||||
// Keep the track of the reference count. | // Keep the track of the reference count. | ||||
bool success = removeNodeFromPeer(peers.find(peerid)); | bool success = removeNodeFromPeer(peers.find(peerid)); | ||||
deadalnix: Shouldn't this be patched too? If both needs to be patched, shouldn't removeNodeFromPeer be… | |||||
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()); | assert(it != peers.end()); | ||||
▲ Show 20 Lines • Show All 412 Lines • Show Last 20 Lines |
Shouldn't this be patched too? If both needs to be patched, shouldn't removeNodeFromPeer be patched instead?