Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/peermanager.cpp
// Copyright (c) 2020 The Bitcoin developers | // Copyright (c) 2020 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <avalanche/peermanager.h> | #include <avalanche/peermanager.h> | ||||
#include <avalanche/delegation.h> | #include <avalanche/delegation.h> | ||||
#include <avalanche/validation.h> | #include <avalanche/validation.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <validation.h> // For ChainstateActive() | #include <validation.h> // For ChainstateActive() | ||||
#include <cassert> | #include <cassert> | ||||
namespace avalanche { | namespace avalanche { | ||||
bool PeerManager::addNode(NodeId nodeid, const Proof &proof, | bool PeerManager::addNode(NodeId nodeid, const Proof &proof, | ||||
const Delegation &delegation) { | const Delegation &delegation, | ||||
std::optional<AvaHelloSigData> sigData) { | |||||
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; | DelegationState state; | ||||
CPubKey pubkey; | CPubKey pubkey; | ||||
if (!delegation.verify(state, proof, pubkey)) { | if (!delegation.verify(state, proof, pubkey)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Check AVAHELLO signature if applicable. | |||||
if (sigData && !sigData->verify(pubkey)) { | |||||
deadalnix: The fact this doesn't depend on anything else in this function but the parameter you added is a… | |||||
return false; | |||||
} | |||||
PiRKAuthorUnsubmitted Done Inline ActionsOK.
I don't think adding a new valid proof hurts anything even if that node turns out not to be the owner, but I agree that it is not the point of addNode PiRK: OK.
> Why do you want to run what precedes this without a valid signature anyways?
I don't… | |||||
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 |
The fact this doesn't depend on anything else in this function but the parameter you added is a sure sign that this doesn't belong here.
Why do you want to run what precedes this without a valid signature anyways?