mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Cleanup the 'PeerSet' hierarchy:
This commit introduces no functional changes but cleans up the code and shrinks the surface area by removing dead and unused code, leveraging std:: alternatives to hand-rolled code and improving comments and documentation.
This commit is contained in:
committed by
Nik Bougalis
parent
d025f3fb28
commit
5b5226d518
@@ -41,28 +41,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
/** A functor to visit all active peers and retrieve their JSON data */
|
||||
struct get_peer_json
|
||||
{
|
||||
using return_type = Json::Value;
|
||||
|
||||
Json::Value json;
|
||||
|
||||
get_peer_json() = default;
|
||||
|
||||
void
|
||||
operator()(std::shared_ptr<Peer> const& peer)
|
||||
{
|
||||
json.append(peer->json());
|
||||
}
|
||||
|
||||
Json::Value
|
||||
operator()()
|
||||
{
|
||||
return json;
|
||||
}
|
||||
};
|
||||
|
||||
namespace CrawlOptions {
|
||||
enum {
|
||||
Disabled = 0,
|
||||
@@ -750,10 +728,9 @@ OverlayImpl::onManifests(
|
||||
|
||||
auto const toSkip = hashRouter.shouldRelay(hash);
|
||||
if (toSkip)
|
||||
foreach (send_if_not(
|
||||
foreach(send_if_not(
|
||||
std::make_shared<Message>(o, protocol::mtMANIFESTS),
|
||||
peer_in_set(*toSkip)))
|
||||
;
|
||||
peer_in_set(*toSkip)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -811,9 +788,8 @@ OverlayImpl::crawlShards(bool pubKey, std::uint32_t hops)
|
||||
// Relay request to active peers
|
||||
protocol::TMGetPeerShardInfo tmGPS;
|
||||
tmGPS.set_hops(hops);
|
||||
foreach (send_always(std::make_shared<Message>(
|
||||
tmGPS, protocol::mtGET_PEER_SHARD_INFO)))
|
||||
;
|
||||
foreach(send_always(std::make_shared<Message>(
|
||||
tmGPS, protocol::mtGET_PEER_SHARD_INFO)));
|
||||
|
||||
if (csCV_.wait_for(l, timeout) == std::cv_status::timeout)
|
||||
{
|
||||
@@ -874,41 +850,12 @@ OverlayImpl::lastLink(std::uint32_t id)
|
||||
csCV_.notify_all();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
OverlayImpl::selectPeers(
|
||||
PeerSet& set,
|
||||
std::size_t limit,
|
||||
std::function<bool(std::shared_ptr<Peer> const&)> score)
|
||||
{
|
||||
using item = std::pair<int, std::shared_ptr<PeerImp>>;
|
||||
|
||||
std::vector<item> v;
|
||||
v.reserve(size());
|
||||
|
||||
for_each([&](std::shared_ptr<PeerImp>&& e) {
|
||||
auto const s = e->getScore(score(e));
|
||||
v.emplace_back(s, std::move(e));
|
||||
});
|
||||
|
||||
std::sort(v.begin(), v.end(), [](item const& lhs, item const& rhs) {
|
||||
return lhs.first > rhs.first;
|
||||
});
|
||||
|
||||
std::size_t accepted = 0;
|
||||
for (auto const& e : v)
|
||||
{
|
||||
if (set.insert(e.second) && ++accepted >= limit)
|
||||
break;
|
||||
}
|
||||
return accepted;
|
||||
}
|
||||
|
||||
/** The number of active peers on the network
|
||||
Active peers are only those peers that have completed the handshake
|
||||
and are running the Ripple protocol.
|
||||
*/
|
||||
std::size_t
|
||||
OverlayImpl::size()
|
||||
OverlayImpl::size() const
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return ids_.size();
|
||||
@@ -1035,7 +982,12 @@ OverlayImpl::getUnlInfo()
|
||||
Json::Value
|
||||
OverlayImpl::json()
|
||||
{
|
||||
return foreach (get_peer_json());
|
||||
Json::Value json;
|
||||
for (auto const& peer : getActivePeers())
|
||||
{
|
||||
json.append(peer->json());
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
bool
|
||||
@@ -1129,7 +1081,7 @@ OverlayImpl::processRequest(http_request_type const& req, Handoff& handoff)
|
||||
}
|
||||
|
||||
Overlay::PeerSequence
|
||||
OverlayImpl::getActivePeers()
|
||||
OverlayImpl::getActivePeers() const
|
||||
{
|
||||
Overlay::PeerSequence ret;
|
||||
ret.reserve(size());
|
||||
@@ -1299,24 +1251,6 @@ OverlayImpl::sendEndpoints()
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
ScoreHasLedger::operator()(std::shared_ptr<Peer> const& bp) const
|
||||
{
|
||||
auto const& p = std::dynamic_pointer_cast<PeerImp>(bp);
|
||||
return p->hasLedger(hash_, seq_);
|
||||
}
|
||||
|
||||
bool
|
||||
ScoreHasTxSet::operator()(std::shared_ptr<Peer> const& bp) const
|
||||
{
|
||||
auto const& p = std::dynamic_pointer_cast<PeerImp>(bp);
|
||||
return p->hasTxSet(hash_);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Overlay::Setup
|
||||
setup_Overlay(BasicConfig const& config)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user