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#include <xrpl/basics/tagged_integer.h>
25
26#include <memory>
27#include <optional>
28#include <utility>
29
30namespace ripple {
31namespace test {
32namespace csf {
33
34struct PeerIDTag;
35//< Uniquely identifies a peer
37
45
49{
52
57 bool trusted_ = false;
58 bool full_ = false;
61
62public:
64 using NodeID = PeerID;
65
67 Ledger::ID id,
73 bool full,
76 : ledgerID_{id}
77 , seq_{seq}
79 , seenTime_{seen}
80 , key_{key}
82 , full_{full}
85 {
86 }
87
89 ledgerID() const
90 {
91 return ledgerID_;
92 }
93
95 seq() const
96 {
97 return seq_;
98 }
99
101 signTime() const
102 {
103 return signTime_;
104 }
105
107 seenTime() const
108 {
109 return seenTime_;
110 }
111
112 PeerKey const&
113 key() const
114 {
115 return key_;
116 }
117
118 PeerID const&
119 nodeID() const
120 {
121 return nodeID_;
122 }
123
124 bool
125 trusted() const
126 {
127 return trusted_;
128 }
129
130 bool
131 full() const
132 {
133 return full_;
134 }
135
137 cookie() const
138 {
139 return cookie_;
140 }
141
143 loadFee() const
144 {
145 return loadFee_;
146 }
147
148 Validation const&
149 unwrap() const
150 {
151 // For the rippled implementation in which RCLValidation wraps
152 // STValidation, the csf::Validation has no more specific type it
153 // wraps, so csf::Validation unwraps to itself
154 return *this;
155 }
156
157 auto
158 asTie() const
159 {
160 // trusted is a status set by the receiver, so it is not part of the tie
161 return std::tie(
162 ledgerID_,
163 seq_,
164 signTime_,
165 seenTime_,
166 key_,
167 nodeID_,
168 loadFee_,
169 full_);
170 }
171 bool
172 operator==(Validation const& o) const
173 {
174 return asTie() == o.asTie();
175 }
176
177 bool
178 operator<(Validation const& o) const
179 {
180 return asTie() < o.asTie();
181 }
182
183 void
185 {
186 trusted_ = true;
187 }
188
189 void
191 {
192 trusted_ = false;
193 }
194
195 void
197 {
198 seenTime_ = seen;
199 }
200};
201
202} // namespace csf
203} // namespace test
204} // namespace ripple
205
206#endif
Validation of a specific ledger by a specific Peer.
Definition: Validation.h:49
NetClock::time_point seenTime() const
Definition: Validation.h:107
Ledger::Seq seq() const
Definition: Validation.h:95
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:66
std::optional< std::uint32_t > loadFee_
Definition: Validation.h:59
Validation const & unwrap() const
Definition: Validation.h:149
PeerKey const & key() const
Definition: Validation.h:113
Ledger::ID ledgerID() const
Definition: Validation.h:89
void setSeen(NetClock::time_point seen)
Definition: Validation.h:196
PeerID const & nodeID() const
Definition: Validation.h:119
NetClock::time_point signTime_
Definition: Validation.h:53
bool operator<(Validation const &o) const
Definition: Validation.h:178
NetClock::time_point seenTime_
Definition: Validation.h:54
bool operator==(Validation const &o) const
Definition: Validation.h:172
NetClock::time_point signTime() const
Definition: Validation.h:101
std::optional< std::uint32_t > loadFee() const
Definition: Validation.h:143
std::uint64_t cookie() const
Definition: Validation.h:137
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition: Validation.h:44
tagged_integer< std::uint32_t, PeerIDTag > PeerID
Definition: Validation.h:36
void sign(Json::Value &jv, Account const &account)
Sign automatically.
Definition: utility.cpp:45
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)