rippled
Loading...
Searching...
No Matches
CollectorRef.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2017 Ripple Labs Inc
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19#ifndef RIPPLE_TEST_CSF_COLLECTOREF_H_INCLUDED
20#define RIPPLE_TEST_CSF_COLLECTOREF_H_INCLUDED
21
22#include <test/csf/SimTime.h>
23#include <test/csf/events.h>
24
25namespace ripple {
26namespace test {
27namespace csf {
28
69{
70 using tp = SimTime;
71
72 // Interface for type-erased collector instance
74 {
75 virtual ~ICollector() = default;
76
77 virtual void
78 on(PeerID node, tp when, Share<Tx> const&) = 0;
79
80 virtual void
81 on(PeerID node, tp when, Share<TxSet> const&) = 0;
82
83 virtual void
84 on(PeerID node, tp when, Share<Validation> const&) = 0;
85
86 virtual void
87 on(PeerID node, tp when, Share<Ledger> const&) = 0;
88
89 virtual void
90 on(PeerID node, tp when, Share<Proposal> const&) = 0;
91
92 virtual void
93 on(PeerID node, tp when, Receive<Tx> const&) = 0;
94
95 virtual void
96 on(PeerID node, tp when, Receive<TxSet> const&) = 0;
97
98 virtual void
99 on(PeerID node, tp when, Receive<Validation> const&) = 0;
100
101 virtual void
102 on(PeerID node, tp when, Receive<Ledger> const&) = 0;
103
104 virtual void
105 on(PeerID node, tp when, Receive<Proposal> const&) = 0;
106
107 virtual void
108 on(PeerID node, tp when, Relay<Tx> const&) = 0;
109
110 virtual void
111 on(PeerID node, tp when, Relay<TxSet> const&) = 0;
112
113 virtual void
114 on(PeerID node, tp when, Relay<Validation> const&) = 0;
115
116 virtual void
117 on(PeerID node, tp when, Relay<Ledger> const&) = 0;
118
119 virtual void
120 on(PeerID node, tp when, Relay<Proposal> const&) = 0;
121
122 virtual void
123 on(PeerID node, tp when, SubmitTx const&) = 0;
124
125 virtual void
126 on(PeerID node, tp when, StartRound const&) = 0;
127
128 virtual void
129 on(PeerID node, tp when, CloseLedger const&) = 0;
130
131 virtual void
132 on(PeerID node, tp when, AcceptLedger const&) = 0;
133
134 virtual void
135 on(PeerID node, tp when, WrongPrevLedger const&) = 0;
136
137 virtual void
138 on(PeerID node, tp when, FullyValidateLedger const&) = 0;
139 };
140
141 // Bridge between type-ful collector T and type erased instance
142 template <class T>
143 class Any final : public ICollector
144 {
145 T& t_;
146
147 public:
148 Any(T& t) : t_{t}
149 {
150 }
151
152 // Can't copy
153 Any(Any const&) = delete;
154 Any&
155 operator=(Any const&) = delete;
156
157 Any(Any&&) = default;
158 Any&
159 operator=(Any&&) = default;
160
161 virtual void
162 on(PeerID node, tp when, Share<Tx> const& e) override
163 {
164 t_.on(node, when, e);
165 }
166
167 virtual void
168 on(PeerID node, tp when, Share<TxSet> const& e) override
169 {
170 t_.on(node, when, e);
171 }
172
173 virtual void
174 on(PeerID node, tp when, Share<Validation> const& e) override
175 {
176 t_.on(node, when, e);
177 }
178
179 virtual void
180 on(PeerID node, tp when, Share<Ledger> const& e) override
181 {
182 t_.on(node, when, e);
183 }
184
185 virtual void
186 on(PeerID node, tp when, Share<Proposal> const& e) override
187 {
188 t_.on(node, when, e);
189 }
190
191 void
192 on(PeerID node, tp when, Receive<Tx> const& e) override
193 {
194 t_.on(node, when, e);
195 }
196
197 virtual void
198 on(PeerID node, tp when, Receive<TxSet> const& e) override
199 {
200 t_.on(node, when, e);
201 }
202
203 virtual void
204 on(PeerID node, tp when, Receive<Validation> const& e) override
205 {
206 t_.on(node, when, e);
207 }
208
209 virtual void
210 on(PeerID node, tp when, Receive<Ledger> const& e) override
211 {
212 t_.on(node, when, e);
213 }
214
215 virtual void
216 on(PeerID node, tp when, Receive<Proposal> const& e) override
217 {
218 t_.on(node, when, e);
219 }
220
221 void
222 on(PeerID node, tp when, Relay<Tx> const& e) override
223 {
224 t_.on(node, when, e);
225 }
226
227 virtual void
228 on(PeerID node, tp when, Relay<TxSet> const& e) override
229 {
230 t_.on(node, when, e);
231 }
232
233 virtual void
234 on(PeerID node, tp when, Relay<Validation> const& e) override
235 {
236 t_.on(node, when, e);
237 }
238
239 virtual void
240 on(PeerID node, tp when, Relay<Ledger> const& e) override
241 {
242 t_.on(node, when, e);
243 }
244
245 virtual void
246 on(PeerID node, tp when, Relay<Proposal> const& e) override
247 {
248 t_.on(node, when, e);
249 }
250
251 virtual void
252 on(PeerID node, tp when, SubmitTx const& e) override
253 {
254 t_.on(node, when, e);
255 }
256
257 virtual void
258 on(PeerID node, tp when, StartRound const& e) override
259 {
260 t_.on(node, when, e);
261 }
262
263 virtual void
264 on(PeerID node, tp when, CloseLedger const& e) override
265 {
266 t_.on(node, when, e);
267 }
268
269 virtual void
270 on(PeerID node, tp when, AcceptLedger const& e) override
271 {
272 t_.on(node, when, e);
273 }
274
275 virtual void
276 on(PeerID node, tp when, WrongPrevLedger const& e) override
277 {
278 t_.on(node, when, e);
279 }
280
281 virtual void
282 on(PeerID node, tp when, FullyValidateLedger const& e) override
283 {
284 t_.on(node, when, e);
285 }
286 };
287
289
290public:
291 template <class T>
292 CollectorRef(T& t) : impl_{new Any<T>(t)}
293 {
294 }
295
296 // Non-copyable
297 CollectorRef(CollectorRef const& c) = delete;
300
304
305 template <class E>
306 void
307 on(PeerID node, tp when, E const& e)
308 {
309 impl_->on(node, when, e);
310 }
311};
312
324{
326
327public:
328 template <class Collector>
329 void
330 add(Collector& collector)
331 {
332 collectors_.emplace_back(collector);
333 }
334
335 template <class E>
336 void
337 on(PeerID node, SimTime when, E const& e)
338 {
339 for (auto& c : collectors_)
340 {
341 c.on(node, when, e);
342 }
343 }
344};
345
346} // namespace csf
347} // namespace test
348} // namespace ripple
349
350#endif
Any & operator=(Any const &)=delete
virtual void on(PeerID node, tp when, Share< TxSet > const &e) override
Definition: CollectorRef.h:168
virtual void on(PeerID node, tp when, Relay< Validation > const &e) override
Definition: CollectorRef.h:234
virtual void on(PeerID node, tp when, Relay< TxSet > const &e) override
Definition: CollectorRef.h:228
virtual void on(PeerID node, tp when, Receive< Ledger > const &e) override
Definition: CollectorRef.h:210
virtual void on(PeerID node, tp when, FullyValidateLedger const &e) override
Definition: CollectorRef.h:282
virtual void on(PeerID node, tp when, Share< Proposal > const &e) override
Definition: CollectorRef.h:186
virtual void on(PeerID node, tp when, StartRound const &e) override
Definition: CollectorRef.h:258
virtual void on(PeerID node, tp when, Relay< Proposal > const &e) override
Definition: CollectorRef.h:246
virtual void on(PeerID node, tp when, SubmitTx const &e) override
Definition: CollectorRef.h:252
virtual void on(PeerID node, tp when, Relay< Ledger > const &e) override
Definition: CollectorRef.h:240
virtual void on(PeerID node, tp when, Receive< Validation > const &e) override
Definition: CollectorRef.h:204
virtual void on(PeerID node, tp when, WrongPrevLedger const &e) override
Definition: CollectorRef.h:276
virtual void on(PeerID node, tp when, AcceptLedger const &e) override
Definition: CollectorRef.h:270
virtual void on(PeerID node, tp when, Receive< Proposal > const &e) override
Definition: CollectorRef.h:216
virtual void on(PeerID node, tp when, Share< Validation > const &e) override
Definition: CollectorRef.h:174
virtual void on(PeerID node, tp when, Receive< TxSet > const &e) override
Definition: CollectorRef.h:198
void on(PeerID node, tp when, Receive< Tx > const &e) override
Definition: CollectorRef.h:192
virtual void on(PeerID node, tp when, Share< Tx > const &e) override
Definition: CollectorRef.h:162
virtual void on(PeerID node, tp when, Share< Ledger > const &e) override
Definition: CollectorRef.h:180
void on(PeerID node, tp when, Relay< Tx > const &e) override
Definition: CollectorRef.h:222
virtual void on(PeerID node, tp when, CloseLedger const &e) override
Definition: CollectorRef.h:264
Holds a type-erased reference to an arbitray collector.
Definition: CollectorRef.h:69
std::unique_ptr< ICollector > impl_
Definition: CollectorRef.h:288
CollectorRef & operator=(CollectorRef &&)=default
CollectorRef(CollectorRef const &c)=delete
CollectorRef & operator=(CollectorRef &c)=delete
void on(PeerID node, tp when, E const &e)
Definition: CollectorRef.h:307
CollectorRef(CollectorRef &&)=default
A container of CollectorRefs.
Definition: CollectorRef.h:324
std::vector< CollectorRef > collectors_
Definition: CollectorRef.h:325
void add(Collector &collector)
Definition: CollectorRef.h:330
void on(PeerID node, SimTime when, E const &e)
Definition: CollectorRef.h:337
typename SimClock::time_point SimTime
Definition: SimTime.h:36
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Peer accepted consensus results.
Definition: events.h:119
Peer closed the open ledger.
Definition: events.h:109
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:138
A value received from another peer as part of flooding.
Definition: events.h:80
A value relayed to another peer as part of flooding.
Definition: events.h:68
A value to be flooded to all other peers starting from this peer.
Definition: events.h:59
Peer starts a new consensus round.
Definition: events.h:98
A transaction submitted to a peer.
Definition: events.h:90
Peer detected a wrong prior ledger during consensus.
Definition: events.h:129