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
20#ifndef RIPPLE_TEST_CSF_COLLECTOREF_H_INCLUDED
21#define RIPPLE_TEST_CSF_COLLECTOREF_H_INCLUDED
22
23#include <test/csf/SimTime.h>
24#include <test/csf/events.h>
25
26namespace ripple {
27namespace test {
28namespace csf {
29
70{
71 using tp = SimTime;
72
73 // Interface for type-erased collector instance
75 {
76 virtual ~ICollector() = default;
77
78 virtual void
79 on(PeerID node, tp when, Share<Tx> const&) = 0;
80
81 virtual void
82 on(PeerID node, tp when, Share<TxSet> const&) = 0;
83
84 virtual void
85 on(PeerID node, tp when, Share<Validation> const&) = 0;
86
87 virtual void
88 on(PeerID node, tp when, Share<Ledger> const&) = 0;
89
90 virtual void
91 on(PeerID node, tp when, Share<Proposal> const&) = 0;
92
93 virtual void
94 on(PeerID node, tp when, Receive<Tx> const&) = 0;
95
96 virtual void
97 on(PeerID node, tp when, Receive<TxSet> const&) = 0;
98
99 virtual void
100 on(PeerID node, tp when, Receive<Validation> const&) = 0;
101
102 virtual void
103 on(PeerID node, tp when, Receive<Ledger> const&) = 0;
104
105 virtual void
106 on(PeerID node, tp when, Receive<Proposal> const&) = 0;
107
108 virtual void
109 on(PeerID node, tp when, Relay<Tx> const&) = 0;
110
111 virtual void
112 on(PeerID node, tp when, Relay<TxSet> const&) = 0;
113
114 virtual void
115 on(PeerID node, tp when, Relay<Validation> const&) = 0;
116
117 virtual void
118 on(PeerID node, tp when, Relay<Ledger> const&) = 0;
119
120 virtual void
121 on(PeerID node, tp when, Relay<Proposal> const&) = 0;
122
123 virtual void
124 on(PeerID node, tp when, SubmitTx const&) = 0;
125
126 virtual void
127 on(PeerID node, tp when, StartRound const&) = 0;
128
129 virtual void
130 on(PeerID node, tp when, CloseLedger const&) = 0;
131
132 virtual void
133 on(PeerID node, tp when, AcceptLedger const&) = 0;
134
135 virtual void
136 on(PeerID node, tp when, WrongPrevLedger const&) = 0;
137
138 virtual void
139 on(PeerID node, tp when, FullyValidateLedger const&) = 0;
140 };
141
142 // Bridge between type-ful collector T and type erased instance
143 template <class T>
144 class Any final : public ICollector
145 {
146 T& t_;
147
148 public:
149 Any(T& t) : t_{t}
150 {
151 }
152
153 // Can't copy
154 Any(Any const&) = delete;
155 Any&
156 operator=(Any const&) = delete;
157
158 Any(Any&&) = default;
159 Any&
160 operator=(Any&&) = default;
161
162 virtual void
163 on(PeerID node, tp when, Share<Tx> const& e) override
164 {
165 t_.on(node, when, e);
166 }
167
168 virtual void
169 on(PeerID node, tp when, Share<TxSet> const& e) override
170 {
171 t_.on(node, when, e);
172 }
173
174 virtual void
175 on(PeerID node, tp when, Share<Validation> const& e) override
176 {
177 t_.on(node, when, e);
178 }
179
180 virtual void
181 on(PeerID node, tp when, Share<Ledger> const& e) override
182 {
183 t_.on(node, when, e);
184 }
185
186 virtual void
187 on(PeerID node, tp when, Share<Proposal> const& e) override
188 {
189 t_.on(node, when, e);
190 }
191
192 void
193 on(PeerID node, tp when, Receive<Tx> const& e) override
194 {
195 t_.on(node, when, e);
196 }
197
198 virtual void
199 on(PeerID node, tp when, Receive<TxSet> const& e) override
200 {
201 t_.on(node, when, e);
202 }
203
204 virtual void
205 on(PeerID node, tp when, Receive<Validation> const& e) override
206 {
207 t_.on(node, when, e);
208 }
209
210 virtual void
211 on(PeerID node, tp when, Receive<Ledger> const& e) override
212 {
213 t_.on(node, when, e);
214 }
215
216 virtual void
217 on(PeerID node, tp when, Receive<Proposal> const& e) override
218 {
219 t_.on(node, when, e);
220 }
221
222 void
223 on(PeerID node, tp when, Relay<Tx> const& e) override
224 {
225 t_.on(node, when, e);
226 }
227
228 virtual void
229 on(PeerID node, tp when, Relay<TxSet> const& e) override
230 {
231 t_.on(node, when, e);
232 }
233
234 virtual void
235 on(PeerID node, tp when, Relay<Validation> const& e) override
236 {
237 t_.on(node, when, e);
238 }
239
240 virtual void
241 on(PeerID node, tp when, Relay<Ledger> const& e) override
242 {
243 t_.on(node, when, e);
244 }
245
246 virtual void
247 on(PeerID node, tp when, Relay<Proposal> const& e) override
248 {
249 t_.on(node, when, e);
250 }
251
252 virtual void
253 on(PeerID node, tp when, SubmitTx const& e) override
254 {
255 t_.on(node, when, e);
256 }
257
258 virtual void
259 on(PeerID node, tp when, StartRound const& e) override
260 {
261 t_.on(node, when, e);
262 }
263
264 virtual void
265 on(PeerID node, tp when, CloseLedger const& e) override
266 {
267 t_.on(node, when, e);
268 }
269
270 virtual void
271 on(PeerID node, tp when, AcceptLedger const& e) override
272 {
273 t_.on(node, when, e);
274 }
275
276 virtual void
277 on(PeerID node, tp when, WrongPrevLedger const& e) override
278 {
279 t_.on(node, when, e);
280 }
281
282 virtual void
283 on(PeerID node, tp when, FullyValidateLedger const& e) override
284 {
285 t_.on(node, when, e);
286 }
287 };
288
290
291public:
292 template <class T>
293 CollectorRef(T& t) : impl_{new Any<T>(t)}
294 {
295 }
296
297 // Non-copyable
298 CollectorRef(CollectorRef const& c) = delete;
301
305
306 template <class E>
307 void
308 on(PeerID node, tp when, E const& e)
309 {
310 impl_->on(node, when, e);
311 }
312};
313
325{
327
328public:
329 template <class Collector>
330 void
331 add(Collector& collector)
332 {
333 collectors_.emplace_back(collector);
334 }
335
336 template <class E>
337 void
338 on(PeerID node, SimTime when, E const& e)
339 {
340 for (auto& c : collectors_)
341 {
342 c.on(node, when, e);
343 }
344 }
345};
346
347} // namespace csf
348} // namespace test
349} // namespace ripple
350
351#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:37
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Peer accepted consensus results.
Definition events.h:121
Peer closed the open ledger.
Definition events.h:111
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:140
A value received from another peer as part of flooding.
Definition events.h:82
A value relayed to another peer as part of flooding.
Definition events.h:70
A value to be flooded to all other peers starting from this peer.
Definition events.h:61
Peer starts a new consensus round.
Definition events.h:100
A transaction submitted to a peer.
Definition events.h:92
Peer detected a wrong prior ledger during consensus.
Definition events.h:131