rippled
Loading...
Searching...
No Matches
CollectorRef.h
1#ifndef XRPL_TEST_CSF_COLLECTOREF_H_INCLUDED
2#define XRPL_TEST_CSF_COLLECTOREF_H_INCLUDED
3
4#include <test/csf/SimTime.h>
5#include <test/csf/events.h>
6
7namespace ripple {
8namespace test {
9namespace csf {
10
51{
52 using tp = SimTime;
53
54 // Interface for type-erased collector instance
56 {
57 virtual ~ICollector() = default;
58
59 virtual void
60 on(PeerID node, tp when, Share<Tx> const&) = 0;
61
62 virtual void
63 on(PeerID node, tp when, Share<TxSet> const&) = 0;
64
65 virtual void
66 on(PeerID node, tp when, Share<Validation> const&) = 0;
67
68 virtual void
69 on(PeerID node, tp when, Share<Ledger> const&) = 0;
70
71 virtual void
72 on(PeerID node, tp when, Share<Proposal> const&) = 0;
73
74 virtual void
75 on(PeerID node, tp when, Receive<Tx> const&) = 0;
76
77 virtual void
78 on(PeerID node, tp when, Receive<TxSet> const&) = 0;
79
80 virtual void
81 on(PeerID node, tp when, Receive<Validation> const&) = 0;
82
83 virtual void
84 on(PeerID node, tp when, Receive<Ledger> const&) = 0;
85
86 virtual void
87 on(PeerID node, tp when, Receive<Proposal> const&) = 0;
88
89 virtual void
90 on(PeerID node, tp when, Relay<Tx> const&) = 0;
91
92 virtual void
93 on(PeerID node, tp when, Relay<TxSet> const&) = 0;
94
95 virtual void
96 on(PeerID node, tp when, Relay<Validation> const&) = 0;
97
98 virtual void
99 on(PeerID node, tp when, Relay<Ledger> const&) = 0;
100
101 virtual void
102 on(PeerID node, tp when, Relay<Proposal> const&) = 0;
103
104 virtual void
105 on(PeerID node, tp when, SubmitTx const&) = 0;
106
107 virtual void
108 on(PeerID node, tp when, StartRound const&) = 0;
109
110 virtual void
111 on(PeerID node, tp when, CloseLedger const&) = 0;
112
113 virtual void
114 on(PeerID node, tp when, AcceptLedger const&) = 0;
115
116 virtual void
117 on(PeerID node, tp when, WrongPrevLedger const&) = 0;
118
119 virtual void
120 on(PeerID node, tp when, FullyValidateLedger const&) = 0;
121 };
122
123 // Bridge between type-ful collector T and type erased instance
124 template <class T>
125 class Any final : public ICollector
126 {
127 T& t_;
128
129 public:
130 Any(T& t) : t_{t}
131 {
132 }
133
134 // Can't copy
135 Any(Any const&) = delete;
136 Any&
137 operator=(Any const&) = delete;
138
139 Any(Any&&) = default;
140 Any&
141 operator=(Any&&) = default;
142
143 virtual void
144 on(PeerID node, tp when, Share<Tx> const& e) override
145 {
146 t_.on(node, when, e);
147 }
148
149 virtual void
150 on(PeerID node, tp when, Share<TxSet> const& e) override
151 {
152 t_.on(node, when, e);
153 }
154
155 virtual void
156 on(PeerID node, tp when, Share<Validation> const& e) override
157 {
158 t_.on(node, when, e);
159 }
160
161 virtual void
162 on(PeerID node, tp when, Share<Ledger> const& e) override
163 {
164 t_.on(node, when, e);
165 }
166
167 virtual void
168 on(PeerID node, tp when, Share<Proposal> const& e) override
169 {
170 t_.on(node, when, e);
171 }
172
173 void
174 on(PeerID node, tp when, Receive<Tx> const& e) override
175 {
176 t_.on(node, when, e);
177 }
178
179 virtual void
180 on(PeerID node, tp when, Receive<TxSet> const& e) override
181 {
182 t_.on(node, when, e);
183 }
184
185 virtual void
186 on(PeerID node, tp when, Receive<Validation> const& e) override
187 {
188 t_.on(node, when, e);
189 }
190
191 virtual void
192 on(PeerID node, tp when, Receive<Ledger> const& e) override
193 {
194 t_.on(node, when, e);
195 }
196
197 virtual void
198 on(PeerID node, tp when, Receive<Proposal> const& e) override
199 {
200 t_.on(node, when, e);
201 }
202
203 void
204 on(PeerID node, tp when, Relay<Tx> const& e) override
205 {
206 t_.on(node, when, e);
207 }
208
209 virtual void
210 on(PeerID node, tp when, Relay<TxSet> const& e) override
211 {
212 t_.on(node, when, e);
213 }
214
215 virtual void
216 on(PeerID node, tp when, Relay<Validation> const& e) override
217 {
218 t_.on(node, when, e);
219 }
220
221 virtual void
222 on(PeerID node, tp when, Relay<Ledger> const& e) override
223 {
224 t_.on(node, when, e);
225 }
226
227 virtual void
228 on(PeerID node, tp when, Relay<Proposal> const& e) override
229 {
230 t_.on(node, when, e);
231 }
232
233 virtual void
234 on(PeerID node, tp when, SubmitTx const& e) override
235 {
236 t_.on(node, when, e);
237 }
238
239 virtual void
240 on(PeerID node, tp when, StartRound const& e) override
241 {
242 t_.on(node, when, e);
243 }
244
245 virtual void
246 on(PeerID node, tp when, CloseLedger const& e) override
247 {
248 t_.on(node, when, e);
249 }
250
251 virtual void
252 on(PeerID node, tp when, AcceptLedger const& e) override
253 {
254 t_.on(node, when, e);
255 }
256
257 virtual void
258 on(PeerID node, tp when, WrongPrevLedger const& e) override
259 {
260 t_.on(node, when, e);
261 }
262
263 virtual void
264 on(PeerID node, tp when, FullyValidateLedger const& e) override
265 {
266 t_.on(node, when, e);
267 }
268 };
269
271
272public:
273 template <class T>
274 CollectorRef(T& t) : impl_{new Any<T>(t)}
275 {
276 }
277
278 // Non-copyable
279 CollectorRef(CollectorRef const& c) = delete;
282
286
287 template <class E>
288 void
289 on(PeerID node, tp when, E const& e)
290 {
291 impl_->on(node, when, e);
292 }
293};
294
306{
308
309public:
310 template <class Collector>
311 void
312 add(Collector& collector)
313 {
314 collectors_.emplace_back(collector);
315 }
316
317 template <class E>
318 void
319 on(PeerID node, SimTime when, E const& e)
320 {
321 for (auto& c : collectors_)
322 {
323 c.on(node, when, e);
324 }
325 }
326};
327
328} // namespace csf
329} // namespace test
330} // namespace ripple
331
332#endif
Any & operator=(Any const &)=delete
virtual void on(PeerID node, tp when, Share< TxSet > const &e) override
virtual void on(PeerID node, tp when, Relay< Validation > const &e) override
virtual void on(PeerID node, tp when, Relay< TxSet > const &e) override
virtual void on(PeerID node, tp when, Receive< Ledger > const &e) override
virtual void on(PeerID node, tp when, FullyValidateLedger const &e) override
virtual void on(PeerID node, tp when, Share< Proposal > const &e) override
virtual void on(PeerID node, tp when, StartRound const &e) override
virtual void on(PeerID node, tp when, Relay< Proposal > const &e) override
virtual void on(PeerID node, tp when, SubmitTx const &e) override
virtual void on(PeerID node, tp when, Relay< Ledger > const &e) override
virtual void on(PeerID node, tp when, Receive< Validation > const &e) override
virtual void on(PeerID node, tp when, WrongPrevLedger const &e) override
virtual void on(PeerID node, tp when, AcceptLedger const &e) override
virtual void on(PeerID node, tp when, Receive< Proposal > const &e) override
virtual void on(PeerID node, tp when, Share< Validation > const &e) override
virtual void on(PeerID node, tp when, Receive< TxSet > const &e) override
void on(PeerID node, tp when, Receive< Tx > const &e) override
virtual void on(PeerID node, tp when, Share< Tx > const &e) override
virtual void on(PeerID node, tp when, Share< Ledger > const &e) override
void on(PeerID node, tp when, Relay< Tx > const &e) override
virtual void on(PeerID node, tp when, CloseLedger const &e) override
Holds a type-erased reference to an arbitray collector.
std::unique_ptr< ICollector > impl_
CollectorRef & operator=(CollectorRef &&)=default
CollectorRef(CollectorRef const &c)=delete
CollectorRef & operator=(CollectorRef &c)=delete
void on(PeerID node, tp when, E const &e)
CollectorRef(CollectorRef &&)=default
A container of CollectorRefs.
std::vector< CollectorRef > collectors_
void add(Collector &collector)
void on(PeerID node, SimTime when, E const &e)
typename SimClock::time_point SimTime
Definition SimTime.h:18
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
Peer accepted consensus results.
Definition events.h:102
Peer closed the open ledger.
Definition events.h:92
virtual void on(PeerID node, tp when, CloseLedger const &)=0
virtual void on(PeerID node, tp when, Relay< Tx > const &)=0
virtual void on(PeerID node, tp when, Receive< Validation > const &)=0
virtual void on(PeerID node, tp when, Share< Validation > const &)=0
virtual void on(PeerID node, tp when, AcceptLedger const &)=0
virtual void on(PeerID node, tp when, Receive< Proposal > const &)=0
virtual void on(PeerID node, tp when, Relay< Validation > const &)=0
virtual void on(PeerID node, tp when, Relay< Proposal > const &)=0
virtual void on(PeerID node, tp when, Share< Proposal > const &)=0
virtual void on(PeerID node, tp when, Relay< Ledger > const &)=0
virtual void on(PeerID node, tp when, Share< TxSet > const &)=0
virtual void on(PeerID node, tp when, StartRound const &)=0
virtual void on(PeerID node, tp when, FullyValidateLedger const &)=0
virtual void on(PeerID node, tp when, Receive< Ledger > const &)=0
virtual void on(PeerID node, tp when, Relay< TxSet > const &)=0
virtual void on(PeerID node, tp when, Share< Tx > const &)=0
virtual void on(PeerID node, tp when, Receive< Tx > const &)=0
virtual void on(PeerID node, tp when, WrongPrevLedger const &)=0
virtual void on(PeerID node, tp when, Share< Ledger > const &)=0
virtual void on(PeerID node, tp when, SubmitTx const &)=0
virtual void on(PeerID node, tp when, Receive< TxSet > const &)=0
Peer fully validated a new ledger.
Definition events.h:121
A value received from another peer as part of flooding.
Definition events.h:63
A value relayed to another peer as part of flooding.
Definition events.h:51
A value to be flooded to all other peers starting from this peer.
Definition events.h:42
Peer starts a new consensus round.
Definition events.h:81
A transaction submitted to a peer.
Definition events.h:73
Peer detected a wrong prior ledger during consensus.
Definition events.h:112