Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
Show All 16 Lines | bool PeerManager::addNode(NodeId nodeid, const 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; | const PeerId peerid = it->peerid; | ||||
DelegationState state; | // This can only be wrong if proof-delegation pairing is broken in the | ||||
CPubKey pubkey; | // network layer. | ||||
if (!delegation.verify(state, proof, pubkey)) { | if (proof.getId() != delegation.getProofId()) { | ||||
return false; | return false; | ||||
} | } | ||||
auto delegationMaster = delegation.getMaster(); | |||||
CPubKey pubkey = delegationMaster ? *delegationMaster : proof.getMaster(); | |||||
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 421 Lines • Show Last 20 Lines |