Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show All 20 Lines | |||||
bool PeerManager::addNode(NodeId nodeid, const std::shared_ptr<Proof> &proof, | bool PeerManager::addNode(NodeId nodeid, const std::shared_ptr<Proof> &proof, | ||||
const Delegation &delegation) { | const Delegation &delegation) { | ||||
auto it = fetchOrCreatePeer(proof); | auto it = fetchOrCreatePeer(proof); | ||||
if (it == peers.end()) { | if (it == peers.end()) { | ||||
return false; | return false; | ||||
} | } | ||||
const PeerId peerid = it->peerid; | |||||
DelegationState state; | DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
if (!delegation.verify(state, pubkey)) { | if (!delegation.verify(state, pubkey)) { | ||||
return false; | return false; | ||||
} | } | ||||
return addOrUpdateNode(it, nodeid, std::move(pubkey)); | |||||
} | |||||
bool PeerManager::addOrUpdateNode(const PeerSet::iterator &it, NodeId nodeid, | |||||
CPubKey pubkey) { | |||||
assert(it != peers.end()); | |||||
const PeerId peerid = it->peerid; | |||||
auto nit = nodes.find(nodeid); | auto nit = nodes.find(nodeid); | ||||
if (nit == nodes.end()) { | if (nit == nodes.end()) { | ||||
if (!nodes.emplace(nodeid, peerid, std::move(pubkey)).second) { | if (!nodes.emplace(nodeid, peerid, std::move(pubkey)).second) { | ||||
return false; | return false; | ||||
} | } | ||||
} else { | } else { | ||||
const PeerId oldpeerid = nit->peerid; | const PeerId oldpeerid = nit->peerid; | ||||
if (!nodes.modify(nit, [&](Node &n) { | if (!nodes.modify(nit, [&](Node &n) { | ||||
▲ Show 20 Lines • Show All 483 Lines • Show Last 20 Lines |