rippled
Loading...
Searching...
No Matches
Validation.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_VALIDATION_H_INCLUDED
21#define RIPPLE_TEST_CSF_VALIDATION_H_INCLUDED
22
23#include <test/csf/ledgers.h>
24
25#include <xrpl/basics/tagged_integer.h>
26
27#include <memory>
28#include <optional>
29#include <utility>
30
31namespace ripple {
32namespace test {
33namespace csf {
34
35struct PeerIDTag;
36//< Uniquely identifies a peer
38
46
50{
53
58 bool trusted_ = false;
59 bool full_ = false;
62
63public:
65 using NodeID = PeerID;
66
88
90 ledgerID() const
91 {
92 return ledgerID_;
93 }
94
96 seq() const
97 {
98 return seq_;
99 }
100
102 signTime() const
103 {
104 return signTime_;
105 }
106
108 seenTime() const
109 {
110 return seenTime_;
111 }
112
113 PeerKey const&
114 key() const
115 {
116 return key_;
117 }
118
119 PeerID const&
120 nodeID() const
121 {
122 return nodeID_;
123 }
124
125 bool
126 trusted() const
127 {
128 return trusted_;
129 }
130
131 bool
132 full() const
133 {
134 return full_;
135 }
136
138 cookie() const
139 {
140 return cookie_;
141 }
142
144 loadFee() const
145 {
146 return loadFee_;
147 }
148
149 Validation const&
150 unwrap() const
151 {
152 // For the rippled implementation in which RCLValidation wraps
153 // STValidation, the csf::Validation has no more specific type it
154 // wraps, so csf::Validation unwraps to itself
155 return *this;
156 }
157
158 auto
159 asTie() const
160 {
161 // trusted is a status set by the receiver, so it is not part of the tie
162 return std::tie(
163 ledgerID_,
164 seq_,
165 signTime_,
166 seenTime_,
167 key_,
168 nodeID_,
169 loadFee_,
170 full_);
171 }
172 bool
173 operator==(Validation const& o) const
174 {
175 return asTie() == o.asTie();
176 }
177
178 bool
179 operator<(Validation const& o) const
180 {
181 return asTie() < o.asTie();
182 }
183
184 void
186 {
187 trusted_ = true;
188 }
189
190 void
192 {
193 trusted_ = false;
194 }
195
196 void
198 {
199 seenTime_ = seen;
200 }
201};
202
203} // namespace csf
204} // namespace test
205} // namespace ripple
206
207#endif
Validation of a specific ledger by a specific Peer.
Definition Validation.h:50
NetClock::time_point seenTime() const
Definition Validation.h:108
Ledger::Seq seq() const
Definition Validation.h:96
Validation(Ledger::ID id, Ledger::Seq seq, NetClock::time_point sign, NetClock::time_point seen, PeerKey key, PeerID nodeID, bool full, std::optional< std::uint32_t > loadFee=std::nullopt, std::uint64_t cookie=0)
Definition Validation.h:67
std::optional< std::uint32_t > loadFee_
Definition Validation.h:60
Validation const & unwrap() const
Definition Validation.h:150
PeerKey const & key() const
Definition Validation.h:114
Ledger::ID ledgerID() const
Definition Validation.h:90
void setSeen(NetClock::time_point seen)
Definition Validation.h:197
PeerID const & nodeID() const
Definition Validation.h:120
NetClock::time_point signTime_
Definition Validation.h:54
bool operator<(Validation const &o) const
Definition Validation.h:179
NetClock::time_point seenTime_
Definition Validation.h:55
bool operator==(Validation const &o) const
Definition Validation.h:173
NetClock::time_point signTime() const
Definition Validation.h:102
std::optional< std::uint32_t > loadFee() const
Definition Validation.h:144
std::uint64_t cookie() const
Definition Validation.h:138
T is_same_v
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition Validation.h:45
tagged_integer< std::uint32_t, PeerIDTag > PeerID
Definition Validation.h:37
void sign(Json::Value &jv, Account const &account)
Sign automatically.
Definition utility.cpp:47
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
Set the sequence number on a JTx.
Definition seq.h:34
T tie(T... args)