mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
improves code readability
This commit is contained in:
@@ -46,7 +46,7 @@ Slot::deleteIdlePeer(PublicKey const& validator)
|
|||||||
auto& peer = it->second;
|
auto& peer = it->second;
|
||||||
auto id = it->first;
|
auto id = it->first;
|
||||||
++it;
|
++it;
|
||||||
if (now - peer.lastMessage > IDLED)
|
if (now - peer.lastMessage > reduce_relay::PEER_IDLED)
|
||||||
{
|
{
|
||||||
JLOG(journal_.trace())
|
JLOG(journal_.trace())
|
||||||
<< "deleteIdlePeer: " << Slice(validator) << " " << id
|
<< "deleteIdlePeer: " << Slice(validator) << " " << id
|
||||||
@@ -112,12 +112,12 @@ Slot::update(
|
|||||||
if (state_ != SlotState::Counting || peer.state == PeerState::Squelched)
|
if (state_ != SlotState::Counting || peer.state == PeerState::Squelched)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (++peer.count > MIN_MESSAGE_THRESHOLD)
|
if (++peer.count > reduce_relay::MIN_MESSAGE_THRESHOLD)
|
||||||
considered_.insert(id);
|
considered_.insert(id);
|
||||||
if (peer.count == (MAX_MESSAGE_THRESHOLD + 1))
|
if (peer.count == (reduce_relay::MAX_MESSAGE_THRESHOLD + 1))
|
||||||
++reachedThreshold_;
|
++reachedThreshold_;
|
||||||
|
|
||||||
if (now - lastSelected_ > 2 * MAX_UNSQUELCH_EXPIRE_DEFAULT)
|
if (now - lastSelected_ > 2 * reduce_relay::MAX_UNSQUELCH_EXPIRE_DEFAULT)
|
||||||
{
|
{
|
||||||
JLOG(journal_.trace())
|
JLOG(journal_.trace())
|
||||||
<< "update: resetting due to inactivity " << Slice(validator) << " "
|
<< "update: resetting due to inactivity " << Slice(validator) << " "
|
||||||
@@ -150,7 +150,7 @@ Slot::update(
|
|||||||
<< Slice(validator) << " " << id;
|
<< Slice(validator) << " " << id;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (now - itpeers->second.lastMessage < IDLED)
|
if (now - itpeers->second.lastMessage < reduce_relay::PEER_IDLED)
|
||||||
selected.insert(id);
|
selected.insert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,14 +211,16 @@ Slot::getSquelchDuration(std::size_t npeers) const
|
|||||||
{
|
{
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
auto m = std::max(
|
auto m = std::max(
|
||||||
MAX_UNSQUELCH_EXPIRE_DEFAULT, seconds{SQUELCH_PER_PEER * npeers});
|
reduce_relay::MAX_UNSQUELCH_EXPIRE_DEFAULT,
|
||||||
if (m > MAX_UNSQUELCH_EXPIRE_PEERS)
|
seconds{reduce_relay::SQUELCH_PER_PEER * npeers});
|
||||||
|
if (m > reduce_relay::MAX_UNSQUELCH_EXPIRE_PEERS)
|
||||||
{
|
{
|
||||||
m = MAX_UNSQUELCH_EXPIRE_PEERS;
|
m = reduce_relay::MAX_UNSQUELCH_EXPIRE_PEERS;
|
||||||
JLOG(journal_.warn())
|
JLOG(journal_.warn())
|
||||||
<< "getSquelchDuration: unexpected squelch duration " << npeers;
|
<< "getSquelchDuration: unexpected squelch duration " << npeers;
|
||||||
}
|
}
|
||||||
return seconds{ripple::rand_int(MIN_UNSQUELCH_EXPIRE / 1s, m / 1s)};
|
return seconds{
|
||||||
|
ripple::rand_int(reduce_relay::MIN_UNSQUELCH_EXPIRE / 1s, m / 1s)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -250,7 +252,7 @@ Slot::deletePeer(PublicKey const& validator, Peer::id_t id, bool erase)
|
|||||||
}
|
}
|
||||||
else if (considered_.find(id) != considered_.end())
|
else if (considered_.find(id) != considered_.end())
|
||||||
{
|
{
|
||||||
if (it->second.count > MAX_MESSAGE_THRESHOLD)
|
if (it->second.count > reduce_relay::MAX_MESSAGE_THRESHOLD)
|
||||||
--reachedThreshold_;
|
--reachedThreshold_;
|
||||||
considered_.erase(id);
|
considered_.erase(id);
|
||||||
}
|
}
|
||||||
@@ -363,7 +365,7 @@ Slots::expireAndIsPeerSquelched(
|
|||||||
bool
|
bool
|
||||||
Slots::addPeerMessage(uint256 const& key, Peer::id_t id)
|
Slots::addPeerMessage(uint256 const& key, Peer::id_t id)
|
||||||
{
|
{
|
||||||
beast::expire(peersWithMessage_, reduce_relay::IDLED);
|
beast::expire(peersWithMessage_, reduce_relay::PEER_IDLED);
|
||||||
|
|
||||||
if (key.isNonZero())
|
if (key.isNonZero())
|
||||||
{
|
{
|
||||||
@@ -466,7 +468,9 @@ Slots::updateUntrustedValidatorSlot(
|
|||||||
{
|
{
|
||||||
registerSquelchedValidator(validator, id);
|
registerSquelchedValidator(validator, id);
|
||||||
handler_.squelch(
|
handler_.squelch(
|
||||||
validator, id, MAX_UNSQUELCH_EXPIRE_DEFAULT.count());
|
validator,
|
||||||
|
id,
|
||||||
|
reduce_relay::MAX_UNSQUELCH_EXPIRE_DEFAULT.count());
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -479,7 +483,7 @@ Slots::updateUntrustedValidatorSlot(
|
|||||||
// In all of these cases we send a squelch message to all peers.
|
// In all of these cases we send a squelch message to all peers.
|
||||||
// The validator may still be considered by the selector. However, it
|
// The validator may still be considered by the selector. However, it
|
||||||
// will be eventually cleaned and squelched
|
// will be eventually cleaned and squelched
|
||||||
if (untrustedSlots_.size() == MAX_UNTRUSTED_SLOTS)
|
if (untrustedSlots_.size() == reduce_relay::MAX_UNTRUSTED_SLOTS)
|
||||||
{
|
{
|
||||||
handler_.squelchAll(
|
handler_.squelchAll(
|
||||||
validator,
|
validator,
|
||||||
@@ -526,11 +530,9 @@ Slots::updateConsideredValidator(PublicKey const& validator, Peer::id_t peer)
|
|||||||
++it->second.count;
|
++it->second.count;
|
||||||
|
|
||||||
// if the validator has not met selection criteria yet
|
// if the validator has not met selection criteria yet
|
||||||
if (it->second.count < MAX_MESSAGE_THRESHOLD ||
|
if (it->second.count < reduce_relay::MAX_MESSAGE_THRESHOLD ||
|
||||||
it->second.peers.size() < reduce_relay::MAX_SELECTED_PEERS)
|
it->second.peers.size() < reduce_relay::MAX_SELECTED_PEERS)
|
||||||
{
|
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
|
||||||
|
|
||||||
auto const key = it->first;
|
auto const key = it->first;
|
||||||
consideredValidators_.erase(it);
|
consideredValidators_.erase(it);
|
||||||
@@ -604,7 +606,7 @@ Slots::deleteIdlePeers()
|
|||||||
for (auto const& validator : cleanConsideredValidators())
|
for (auto const& validator : cleanConsideredValidators())
|
||||||
handler_.squelchAll(
|
handler_.squelchAll(
|
||||||
validator,
|
validator,
|
||||||
MAX_UNSQUELCH_EXPIRE_DEFAULT.count(),
|
reduce_relay::MAX_UNSQUELCH_EXPIRE_DEFAULT.count(),
|
||||||
[&](Peer::id_t id) { registerSquelchedValidator(validator, id); });
|
[&](Peer::id_t id) { registerSquelchedValidator(validator, id); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user