rippled
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 <ripple/basics/tagged_integer.h>
23 #include <test/csf/ledgers.h>
24 
25 #include <memory>
26 #include <optional>
27 #include <utility>
28 
29 namespace ripple {
30 namespace test {
31 namespace csf {
32 
33 struct PeerIDTag;
34 //< Uniquely identifies a peer
36 
44 
48 {
51 
56  bool trusted_ = false;
57  bool full_ = false;
60 
61 public:
62  using NodeKey = PeerKey;
63  using NodeID = PeerID;
64 
66  Ledger::ID id,
70  PeerKey key,
71  PeerID nodeID,
72  bool full,
75  : ledgerID_{id}
76  , seq_{seq}
77  , signTime_{sign}
78  , seenTime_{seen}
79  , key_{key}
80  , nodeID_{nodeID}
81  , full_{full}
82  , loadFee_{loadFee}
83  , cookie_{cookie}
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
ripple::test::csf::Validation::asTie
auto asTie() const
Definition: Validation.h:157
utility
ripple::test::csf::Validation::seenTime
NetClock::time_point seenTime() const
Definition: Validation.h:106
ripple::test::csf::PeerID
tagged_integer< std::uint32_t, PeerIDTag > PeerID
Definition: Validation.h:35
std::pair< PeerID, std::uint32_t >
ripple::test::csf::Validation::nodeID
PeerID const & nodeID() const
Definition: Validation.h:118
ripple::test::csf::Validation::setTrusted
void setTrusted()
Definition: Validation.h:183
ripple::test::csf::Validation::seq
Ledger::Seq seq() const
Definition: Validation.h:94
ripple::test::csf::Validation::unwrap
Validation const & unwrap() const
Definition: Validation.h:148
ripple::test::csf::Validation::seenTime_
NetClock::time_point seenTime_
Definition: Validation.h:53
ripple::test::csf::Validation::operator==
bool operator==(Validation const &o) const
Definition: Validation.h:171
ripple::test::csf::Validation::trusted_
bool trusted_
Definition: Validation.h:56
ripple::test::csf::Validation::cookie
std::uint64_t cookie() const
Definition: Validation.h:136
std::tie
T tie(T... args)
ripple::test::csf::Validation::loadFee_
std::optional< std::uint32_t > loadFee_
Definition: Validation.h:58
ripple::test::csf::Validation::ledgerID_
Ledger::ID ledgerID_
Definition: Validation.h:49
ripple::test::csf::Validation::seq_
Ledger::Seq seq_
Definition: Validation.h:50
ripple::test::csf::PeerKey
std::pair< PeerID, std::uint32_t > PeerKey
The current key of a peer.
Definition: Validation.h:43
std::chrono::time_point
std::uint64_t
ripple::test::csf::Validation::key
PeerKey const & key() const
Definition: Validation.h:112
memory
ripple::test::csf::Validation::operator<
bool operator<(Validation const &o) const
Definition: Validation.h:177
ripple::test::jtx::seq
Set the sequence number on a JTx.
Definition: seq.h:33
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::csf::Validation::signTime
NetClock::time_point signTime() const
Definition: Validation.h:100
ripple::sign
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &m)
Generate a signature for a message.
Definition: SecretKey.cpp:238
ripple::test::csf::Validation
Validation of a specific ledger by a specific Peer.
Definition: Validation.h:47
ripple::test::csf::Validation::setSeen
void setSeen(NetClock::time_point seen)
Definition: Validation.h:195
ripple::test::csf::Ledger::ID
tagged_integer< std::uint32_t, IdTag > ID
Definition: ledgers.h:67
ripple::test::csf::Validation::full_
bool full_
Definition: Validation.h:57
ripple::test::csf::Validation::full
bool full() const
Definition: Validation.h:130
ripple::test::csf::Validation::ledgerID
Ledger::ID ledgerID() const
Definition: Validation.h:88
ripple::test::csf::Validation::Validation
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
ripple::test::csf::Validation::key_
PeerKey key_
Definition: Validation.h:54
optional
ripple::test::csf::Validation::nodeID_
PeerID nodeID_
Definition: Validation.h:55
ripple::test::csf::Validation::cookie_
std::uint64_t cookie_
Definition: Validation.h:59
ripple::test::csf::Validation::trusted
bool trusted() const
Definition: Validation.h:124
ripple::tagged_integer< std::uint32_t, PeerIDTag >
ripple::test::csf::Validation::setUntrusted
void setUntrusted()
Definition: Validation.h:189
ripple::test::csf::Validation::loadFee
std::optional< std::uint32_t > loadFee() const
Definition: Validation.h:142
ripple::test::csf::Validation::signTime_
NetClock::time_point signTime_
Definition: Validation.h:52