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 <random.h> | #include <random.h> | ||||
#include <cassert> | #include <cassert> | ||||
namespace avalanche { | namespace avalanche { | ||||
PeerId PeerManager::addPeer(PeerId p, uint32_t score) { | |||||
auto inserted = peers.emplace(p, uint32_t(slots.size()), Proof(score)); | |||||
assert(inserted.second); | |||||
const uint64_t start = slotCount; | |||||
slots.emplace_back(start, score, p); | |||||
slotCount = start + score; | |||||
return p; | |||||
} | |||||
PeerId PeerManager::getPeer(const Proof &proof) { | PeerId PeerManager::getPeer(const Proof &proof) { | ||||
auto &pview = peers.get<proof_index>(); | auto &pview = peers.get<proof_index>(); | ||||
auto it = pview.find(proof.getId()); | auto it = pview.find(proof.getId()); | ||||
if (it != pview.end()) { | if (it != pview.end()) { | ||||
return it->peerid; | return it->peerid; | ||||
} | } | ||||
// We have no peer for this proof, time to create it. | // We have no peer for this proof, time to create it. | ||||
▲ Show 20 Lines • Show All 286 Lines • Show Last 20 Lines |