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