xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
overlay
Squelch.h
1
#pragma once
2
3
#include <xrpld/overlay/ReduceRelayCommon.h>
4
5
#include <xrpl/basics/Log.h>
6
#include <xrpl/basics/UnorderedContainers.h>
7
#include <xrpl/beast/utility/Journal.h>
8
#include <xrpl/protocol/PublicKey.h>
9
10
#include <
chrono
>
11
12
namespace
xrpl::reduce_relay
{
13
17
template
<
typename
ClockType>
18
class
Squelch
19
{
20
using
time_point
= ClockType::time_point;
21
22
public
:
23
explicit
Squelch
(
beast::Journal
journal) :
journal_
(journal)
24
{
25
}
26
virtual
~Squelch
() =
default
;
27
34
bool
35
addSquelch
(
PublicKey
const
& validator,
std::chrono::seconds
const
& squelchDuration);
36
41
void
42
removeSquelch
(
PublicKey
const
& validator);
43
49
bool
50
expireSquelch
(
PublicKey
const
& validator);
51
52
private
:
57
HashMap<PublicKey, time_point>
squelched_
;
58
beast::Journal
const
journal_
;
59
};
60
61
template
<
typename
ClockType>
62
bool
63
Squelch<ClockType>::addSquelch
(
64
PublicKey
const
& validator,
65
std::chrono::seconds
const
& squelchDuration)
66
{
67
if
(squelchDuration >=
kMinUnsquelchExpire
&& squelchDuration <=
kMaxUnsquelchExpirePeers
)
68
{
69
squelched_
[validator] = ClockType::now() + squelchDuration;
70
return
true
;
71
}
72
73
JLOG(
journal_
.error()) <<
"squelch: invalid squelch duration "
<< squelchDuration.
count
();
74
75
// unsquelch if invalid duration
76
removeSquelch
(validator);
77
78
return
false
;
79
}
80
81
template
<
typename
ClockType>
82
void
83
Squelch<ClockType>::removeSquelch
(
PublicKey
const
& validator)
84
{
85
squelched_
.erase(validator);
86
}
87
88
template
<
typename
ClockType>
89
bool
90
Squelch<ClockType>::expireSquelch
(
PublicKey
const
& validator)
91
{
92
auto
now = ClockType::now();
93
94
auto
const
& it =
squelched_
.find(validator);
95
if
(it ==
squelched_
.end())
96
return
true
;
97
if
(it->second > now)
98
return
false
;
99
100
// squelch expired
101
squelched_
.erase(it);
102
103
return
true
;
104
}
105
106
}
// namespace xrpl::reduce_relay
chrono
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
xrpl::PublicKey
A public key.
Definition
PublicKey.h:53
xrpl::reduce_relay::Squelch::Squelch
Squelch(beast::Journal journal)
Definition
Squelch.h:23
xrpl::reduce_relay::Squelch::time_point
ClockType::time_point time_point
Definition
Squelch.h:20
xrpl::reduce_relay::Squelch::removeSquelch
void removeSquelch(PublicKey const &validator)
Remove the squelch.
Definition
Squelch.h:83
xrpl::reduce_relay::Squelch::expireSquelch
bool expireSquelch(PublicKey const &validator)
Remove expired squelch.
Definition
Squelch.h:90
xrpl::reduce_relay::Squelch::journal_
beast::Journal const journal_
Definition
Squelch.h:58
xrpl::reduce_relay::Squelch::addSquelch
bool addSquelch(PublicKey const &validator, std::chrono::seconds const &squelchDuration)
Squelch validation/proposal relaying for the validator.
Definition
Squelch.h:63
xrpl::reduce_relay::Squelch::~Squelch
virtual ~Squelch()=default
xrpl::reduce_relay::Squelch::squelched_
HashMap< PublicKey, time_point > squelched_
Maintains the list of squelched relaying to downstream peers.
Definition
Squelch.h:57
std::chrono::seconds::count
T count(T... args)
std::chrono::seconds
xrpl::reduce_relay
Definition
ReduceRelayCommon.h:11
xrpl::reduce_relay::kMinUnsquelchExpire
static constexpr auto kMinUnsquelchExpire
Definition
ReduceRelayCommon.h:18
xrpl::reduce_relay::kMaxUnsquelchExpirePeers
static constexpr auto kMaxUnsquelchExpirePeers
Definition
ReduceRelayCommon.h:21
xrpl::HashMap
std::unordered_map< Key, Value, Hash, Pred, Allocator > HashMap
Definition
UnorderedContainers.h:36
Generated by
1.17.0