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