mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improve peer iteration in overlay
This commit is contained in:
@@ -235,10 +235,19 @@ public:
|
||||
for_each (UnaryFunc&& f)
|
||||
{
|
||||
std::lock_guard <decltype(mutex_)> lock (mutex_);
|
||||
for (auto const& e : ids_)
|
||||
|
||||
// Iterate over a copy of the peer list because peer
|
||||
// destruction can invalidate iterators.
|
||||
std::vector<std::weak_ptr<PeerImp>> wp;
|
||||
wp.reserve(ids_.size());
|
||||
|
||||
for (auto& x : ids_)
|
||||
wp.push_back(x.second);
|
||||
|
||||
for (auto& w : wp)
|
||||
{
|
||||
if (auto sp = e.second.lock())
|
||||
f(std::move(sp));
|
||||
if (auto p = w.lock())
|
||||
f(std::move(p));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1958,14 +1958,14 @@ getPeerWithTree (OverlayImpl& ov,
|
||||
std::shared_ptr<PeerImp> ret;
|
||||
int retScore = 0;
|
||||
|
||||
ov.for_each([&](std::shared_ptr<PeerImp> const& p)
|
||||
ov.for_each([&](std::shared_ptr<PeerImp>&& p)
|
||||
{
|
||||
if (p->hasTxSet(rootHash) && p.get() != skip)
|
||||
{
|
||||
auto score = p->getScore (true);
|
||||
if (! ret || (score > retScore))
|
||||
{
|
||||
ret = p;
|
||||
ret = std::move(p);
|
||||
retScore = score;
|
||||
}
|
||||
}
|
||||
@@ -1986,7 +1986,7 @@ getPeerWithLedger (OverlayImpl& ov,
|
||||
std::shared_ptr<PeerImp> ret;
|
||||
int retScore = 0;
|
||||
|
||||
ov.for_each([&](std::shared_ptr<PeerImp> const& p)
|
||||
ov.for_each([&](std::shared_ptr<PeerImp>&& p)
|
||||
{
|
||||
if (p->hasLedger(ledgerHash, ledger) &&
|
||||
p.get() != skip)
|
||||
@@ -1994,7 +1994,7 @@ getPeerWithLedger (OverlayImpl& ov,
|
||||
auto score = p->getScore (true);
|
||||
if (! ret || (score > retScore))
|
||||
{
|
||||
ret = p;
|
||||
ret = std::move(p);
|
||||
retScore = score;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user