mirror of
https://github.com/XRPLF/rippled.git
synced 2026-09-27 15:28:03 +00:00
adds callback to squelchAll instead of calling slots directly
This commit is contained in:
@@ -701,10 +701,16 @@ private:
|
||||
}
|
||||
|
||||
void
|
||||
squelchAll(PublicKey const& validator, std::uint32_t duration) override
|
||||
squelchAll(
|
||||
PublicKey const& validator,
|
||||
std::uint32_t duration,
|
||||
std::function<void(Peer::id_t)> callback) override
|
||||
{
|
||||
for (auto const& [id, peer] : peers_)
|
||||
{
|
||||
squelch_(validator, peer, duration);
|
||||
callback(id);
|
||||
}
|
||||
}
|
||||
void
|
||||
unsquelch(PublicKey const& validator, Peer::id_t id) const override
|
||||
@@ -1580,7 +1586,10 @@ vp_base_squelch_max_selected_peers=2
|
||||
}
|
||||
|
||||
void
|
||||
squelchAll(PublicKey const&, std::uint32_t) override
|
||||
squelchAll(
|
||||
PublicKey const&,
|
||||
std::uint32_t,
|
||||
std::function<void(Peer::id_t)>) override
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -41,8 +41,8 @@ class TestHandler : public reduce_relay::SquelchHandler
|
||||
public:
|
||||
using squelch_method =
|
||||
std::function<void(PublicKey const&, Peer::id_t, std::uint32_t)>;
|
||||
using squelchAll_method =
|
||||
std::function<void(PublicKey const&, std::uint32_t)>;
|
||||
using squelchAll_method = std::function<
|
||||
void(PublicKey const&, std::uint32_t, std::function<void(Peer::id_t)>)>;
|
||||
using unsquelch_method = std::function<void(PublicKey const&, Peer::id_t)>;
|
||||
|
||||
squelch_method squelch_f_;
|
||||
@@ -74,9 +74,12 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
squelchAll(PublicKey const& validator, std::uint32_t duration) override
|
||||
squelchAll(
|
||||
PublicKey const& validator,
|
||||
std::uint32_t duration,
|
||||
std::function<void(Peer::id_t)> callback) override
|
||||
{
|
||||
squelchAll_f_(validator, duration);
|
||||
squelchAll_f_(validator, duration, callback);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -148,10 +151,10 @@ public:
|
||||
BEAST_EXPECTS(false, "unexpected call to squelch handler");
|
||||
};
|
||||
|
||||
TestHandler::squelchAll_method noop_squelchAll = [&](PublicKey const&,
|
||||
std::uint32_t) {
|
||||
BEAST_EXPECTS(false, "unexpected call to squelchAll handler");
|
||||
};
|
||||
TestHandler::squelchAll_method noop_squelchAll =
|
||||
[&](PublicKey const&, std::uint32_t, std::function<void(Peer::id_t)>) {
|
||||
BEAST_EXPECTS(false, "unexpected call to squelchAll handler");
|
||||
};
|
||||
|
||||
TestHandler::unsquelch_method noop_unsquelch = [&](PublicKey const&,
|
||||
Peer::id_t) {
|
||||
@@ -369,10 +372,12 @@ vp_enhanced_squelch_enable=0
|
||||
auto const newValidator = randomKeyPair(KeyType::ed25519).first;
|
||||
|
||||
// once slots are full squelchAll must be called for new peer/validator
|
||||
handler.squelchAll_f_ = [&](PublicKey const& key, std::uint32_t) {
|
||||
handler.squelchAll_f_ = [&](PublicKey const& key,
|
||||
std::uint32_t,
|
||||
std::function<void(Peer::id_t)> callback) {
|
||||
BEAST_EXPECTS(
|
||||
key == newValidator, "unexpected validator squelched");
|
||||
slots.squelchValidator(key, peerID);
|
||||
callback(peerID);
|
||||
};
|
||||
|
||||
slots.updateUntrustedValidatorSlot(
|
||||
@@ -401,7 +406,8 @@ vp_enhanced_squelch_enable=0
|
||||
|
||||
// verify that squelchAll is called for each idled slot validator
|
||||
handler.squelchAll_f_ = [&](PublicKey const& actualKey,
|
||||
std::uint32_t duration) {
|
||||
std::uint32_t duration,
|
||||
std::function<void(Peer::id_t)> callback) {
|
||||
for (auto it = keys.begin(); it != keys.end(); ++it)
|
||||
{
|
||||
if (*it == actualKey)
|
||||
@@ -727,10 +733,12 @@ vp_enhanced_squelch_enable=0
|
||||
|
||||
// verify that squelchAll is called for idle validator
|
||||
handler.squelchAll_f_ = [&](PublicKey const& actualKey,
|
||||
std::uint32_t duration) {
|
||||
std::uint32_t duration,
|
||||
std::function<void(Peer::id_t)> callback) {
|
||||
BEAST_EXPECTS(
|
||||
actualKey == idleValidator,
|
||||
"unexpected key passed to squelchAll");
|
||||
callback(peerID);
|
||||
};
|
||||
|
||||
TestStopwatch stopwatch;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <xrpl/beast/utility/PropertyStream.h>
|
||||
#include <xrpl/protocol/PublicKey.h>
|
||||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
|
||||
namespace ripple {
|
||||
@@ -101,9 +102,13 @@ public:
|
||||
* to register that a (validator,peer) was squelched
|
||||
* @param validator Public key of the source validator
|
||||
* @param duration Squelch duration in seconds
|
||||
* @param callback a callback to register that a validator was squelched
|
||||
*/
|
||||
virtual void
|
||||
squelchAll(PublicKey const& validator, std::uint32_t duration) = 0;
|
||||
squelchAll(
|
||||
PublicKey const& validator,
|
||||
std::uint32_t duration,
|
||||
std::function<void(Peer::id_t)> callback) = 0;
|
||||
|
||||
/** Unsquelch handler
|
||||
* @param validator Public key of the source validator
|
||||
@@ -426,17 +431,6 @@ public:
|
||||
void
|
||||
deletePeer(Peer::id_t id, bool erase);
|
||||
|
||||
/** Called to register that a given validator was squelched for a given
|
||||
* peer. It is expected that this method is called by SquelchHandler.
|
||||
*
|
||||
* @param validatorKey Validator public key
|
||||
* @param peerID peer ID
|
||||
*/
|
||||
void
|
||||
registerSquelchedValidator(
|
||||
PublicKey const& validatorKey,
|
||||
Peer::id_t peerID);
|
||||
|
||||
void
|
||||
onWrite(beast::PropertyStream::Map& stream) const;
|
||||
|
||||
@@ -480,6 +474,17 @@ protected:
|
||||
bool
|
||||
expireAndIsPeerSquelched(PublicKey const& validatorKey, Peer::id_t peerID);
|
||||
|
||||
/** Called to register that a given validator was squelched for a given
|
||||
* peer. It is expected that this method is called by SquelchHandler.
|
||||
*
|
||||
* @param validatorKey Validator public key
|
||||
* @param peerID peer ID
|
||||
*/
|
||||
void
|
||||
registerSquelchedValidator(
|
||||
PublicKey const& validatorKey,
|
||||
Peer::id_t peerID);
|
||||
|
||||
std::atomic_bool reduceRelayReady_{false};
|
||||
|
||||
// Maintain an open number of slots for trusted validators to reduce
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
|
||||
#include "xrpld/overlay/detail/TrafficCount.h"
|
||||
|
||||
#include <functional>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
namespace CrawlOptions {
|
||||
@@ -1418,11 +1420,14 @@ OverlayImpl::squelch(
|
||||
}
|
||||
|
||||
void
|
||||
OverlayImpl::squelchAll(PublicKey const& validator, uint32_t squelchDuration)
|
||||
OverlayImpl::squelchAll(
|
||||
PublicKey const& validator,
|
||||
uint32_t squelchDuration,
|
||||
std::function<void(Peer::id_t)> callback)
|
||||
{
|
||||
for_each([&](std::shared_ptr<PeerImp>&& p) {
|
||||
p->send(makeSquelchMessage(validator, true, squelchDuration));
|
||||
slots_.registerSquelchedValidator(validator, p->id());
|
||||
callback(p->id());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
@@ -467,8 +468,10 @@ private:
|
||||
std::uint32_t squelchDuration) const override;
|
||||
|
||||
void
|
||||
squelchAll(PublicKey const& validator, std::uint32_t squelchDuration)
|
||||
override;
|
||||
squelchAll(
|
||||
PublicKey const& validator,
|
||||
std::uint32_t squelchDuration,
|
||||
std::function<void(Peer::id_t)>) override;
|
||||
|
||||
void
|
||||
unsquelch(PublicKey const& validator, Peer::id_t id) const override;
|
||||
|
||||
@@ -481,7 +481,10 @@ Slots::updateUntrustedValidatorSlot(
|
||||
// will be eventually cleaned and squelched
|
||||
if (untrustedSlots_.size() == MAX_UNTRUSTED_SLOTS)
|
||||
{
|
||||
handler_.squelchAll(validator, MAX_UNSQUELCH_EXPIRE_DEFAULT.count());
|
||||
handler_.squelchAll(
|
||||
validator,
|
||||
MAX_UNSQUELCH_EXPIRE_DEFAULT.count(),
|
||||
[&](Peer::id_t id) { registerSquelchedValidator(validator, id); });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -570,7 +573,11 @@ Slots::deleteIdlePeers()
|
||||
// sending messages for this validator squelch it
|
||||
if (!it->second.isTrusted_)
|
||||
handler_.squelchAll(
|
||||
it->first, MAX_UNSQUELCH_EXPIRE_DEFAULT.count());
|
||||
it->first,
|
||||
MAX_UNSQUELCH_EXPIRE_DEFAULT.count(),
|
||||
[&](Peer::id_t id) {
|
||||
registerSquelchedValidator(it->first, id);
|
||||
});
|
||||
|
||||
it = slots.erase(it);
|
||||
}
|
||||
@@ -586,7 +593,10 @@ Slots::deleteIdlePeers()
|
||||
// there might be some good validators in this set that "lapsed".
|
||||
// However, since these are untrusted validators we're not concerned
|
||||
for (auto const& validator : cleanConsideredValidators())
|
||||
handler_.squelchAll(validator, MAX_UNSQUELCH_EXPIRE_DEFAULT.count());
|
||||
handler_.squelchAll(
|
||||
validator,
|
||||
MAX_UNSQUELCH_EXPIRE_DEFAULT.count(),
|
||||
[&](Peer::id_t id) { registerSquelchedValidator(validator, id); });
|
||||
}
|
||||
|
||||
std::vector<PublicKey>
|
||||
|
||||
Reference in New Issue
Block a user